4

I have been going over the WebRTC docs and I see two WebRTC methods where I am not sure I understand what the difference is: reattachMediaStream and attachMediaSource.

attachMediaSource This I get, you use it to attach a MediaStream to something like a video element.

HTML:

<video id="videoPlayer">

JS:

attachMediaSource(videoPlayer, mediaSource);

But when is reattachMediaStream used?

Looking at the adapter.js code the WebRTC group provides, doesn't help much.

For Gecko it has:

  reattachMediaStream = function(to, from) {
    console.log("Reattaching media stream");
    to.mozSrcObject = from.mozSrcObject;
    to.play();
  };

For webkit it has:

  reattachMediaStream = function(to, from) {
    to.src = from.src;
  }

Looking at all the various examples out there also hasn't helped. I don't see anything using reattachMediaStream.

Is it attaching the video from one video element to another?

Bjorn
  • 69,215
  • 39
  • 136
  • 164

1 Answers1

3

You're right: the reattachMediaStream method allows you to attach the same media stream to multiple video elements.
For a usage example, have a look at this page, at line 350:

function onRemoteStreamAdded(event) {
    console.log("Remote stream added."); 
    reattachMediaStream(miniVideo, localVideo);
    attachMediaStream(remoteVideo, event.stream);
    remoteStream = event.stream;
    waitForRemoteVideo();  
}

In this example the method is used to show a preview of the local video in a small window in the right bottom corner of the page.

  • Wow, thanks! I couldn't find anything Googling. Looks like that was at the bottom of the search results page. :) – Bjorn Sep 29 '13 at 12:29
  • Also I'm thinking this is just a helper method provided by WebRTC via their adapter.js file to get around browser inconsistencies in attaching streams to videos and not part of the WebRTC spec itself. – Bjorn Sep 29 '13 at 12:31