问题
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