4

I'm using MediaStream API in a web app which allow multiple user to make à conf call based on webrtc. When I use MediaStream.addTracks() the id of my track (MediaStreamTrack) change.

Here is a concrete example :

getUserMedia.call(navigator, {audio:true,video:false}, function(stream) {
    console.log(stream.getAudioTracks());                //(1)
    rtc.streams[0].addTrack(stream.getAudioTracks()[0]); //rtc object managed by webrtc.io
    console.log(rtc.streams[0].getAudioTracks());        //(2)
}, function() {
    console.log("Could not connect stream.");
    onFail();
});

(1) : At this point my audio track is

enabled: true
id: "0eKd3T3arsIgrnLsIplvfA69feDzxvwEnu8ga0"
kind: "audio"
label: "0eKd3T3arsIgrnLsIplvfA69feDzxvwEnu8ga0"
onended: null
onmute: null
onunmute: null
readyState: "live"

(2) : At this point my audio track is

enabled: true
id: "bd3ba276-8804-4c6e-8dd7-f1bd316150e8"
kind: "audio"
label: "0eKd3T3arsIgrnLsIplvfA69feDzxvwEnu8ga0"
onended: null
onmute: null
onunmute: null
readyState: "live"

As you can see the id has changed. Is this the normal behaviour ?

Tako
  • 661
  • 12
  • 34

2 Answers2

0

No, it isn't. The API description on webrtc.com shows that the mediastream parameter for the addStream function is only a constant reference. So the id shouldn't change.

Enthusiasmus
  • 303
  • 2
  • 9
  • 1
    Yes I know it shouldn't change, but it does, this is why I'm asking. And this is not _addStream_ but _addTracks_ – Tako Oct 03 '13 at 10:31
0

A new track added to stream when you are calling addTrack function. For example, if you had two tracks on a stream (a video track and a audio track), after calling addTrack function you have 3 tracks and any track replaced by new one. So you are getting the latest track properties that are different from previous.

NutCracker
  • 11,485
  • 4
  • 44
  • 68