WebRTC - How to identify the source IDs (device IDs) for a MediaStream(Tracks)

爱⌒轻易说出口 提交于 2020-12-25 16:14:23

问题


Once I have established a WebRTC connection, I can getLocalStreams and getRemoteStreams.

The streams have their own ID. Each stream is made of audio/video tracks MediaStreamTrack.

I'd like to be able to identify the device/source (ID) used for each track in order to avoid adding a stream that was already added to the connection.

In other word, I was thinking to make a check in connection.onaddstream that the stream track is not already present in my list of local or remote streams.

Any suggestions?


回答1:


For each MediaStreamTrack you can call .getCapabilities().deviceId to get the deviceId.

But I'm not sure if you can use the same device id within the same browser twice.




回答2:


.getSettings().deviceId on audio/video track (instance of MediaStreamTrack) will return deviceId that is same as deviceId returned from enumerateDevices()




回答3:


You can use MediaStreamTrack.id property of MediaStreamTrack. It Returns a DOM string containing a unique identifier (GUID) for the track; it is generated by the browser.



来源:https://stackoverflow.com/questions/39744329/webrtc-how-to-identify-the-source-ids-device-ids-for-a-mediastreamtracks

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!