Home | History | Annotate | Download | only in manual
      1 var RTCPeerConnection = null;
      2 var getUserMedia = null;
      3 var attachMediaStream = null;
      4 
      5 if (navigator.mozGetUserMedia) {
      6   console.log("This appears to be Firefox");
      7 
      8   // The RTCPeerConnection object.
      9   RTCPeerConnection = mozRTCPeerConnection;
     10 
     11   // Get UserMedia (only difference is the prefix).
     12   // Code from Adam Barth.
     13   getUserMedia = navigator.mozGetUserMedia.bind(navigator);
     14 
     15   // Attach a media stream to an element.
     16   attachMediaStream = function(element, stream) {
     17     console.log("Attaching media stream");
     18     element.mozSrcObject = stream;
     19     element.play();
     20   };
     21 } else if (navigator.webkitGetUserMedia) {
     22   console.log("This appears to be Chrome");
     23 
     24   // The RTCPeerConnection object.
     25   RTCPeerConnection = webkitRTCPeerConnection;
     26   
     27   // Get UserMedia (only difference is the prefix).
     28   // Code from Adam Barth.
     29   getUserMedia = navigator.webkitGetUserMedia.bind(navigator);
     30 
     31   // Attach a media stream to an element.
     32   attachMediaStream = function(element, stream) {
     33     element.src = webkitURL.createObjectURL(stream);
     34   };
     35 
     36   // The representation of tracks in a stream is changed in M26.
     37   // Unify them for earlier Chrome versions in the coexisting period.
     38   if (!webkitMediaStream.prototype.getVideoTracks) {
     39       webkitMediaStream.prototype.getVideoTracks = function() {
     40       return this.videoTracks;
     41     } 
     42   } 
     43   
     44   if (!webkitMediaStream.prototype.getAudioTracks) {
     45       webkitMediaStream.prototype.getAudioTracks = function() {
     46       return this.audioTracks;
     47     }
     48   } 
     49 } else {
     50   console.log("Browser does not appear to be WebRTC-capable");
     51 }
     52