vikasmarwaha@webrtc.org | 98fce15 | 2013-02-27 23:22:10 +0000 | [diff] [blame^] | 1 | var RTCPeerConnection = null; |
| 2 | var getUserMedia = null; |
| 3 | var attachMediaStream = null; |
| 4 | var reattachMediaStream = null; |
| 5 | var webrtcDetectedBrowser = null; |
| 6 | |
| 7 | if (navigator.mozGetUserMedia) { |
| 8 | console.log("This appears to be Firefox"); |
| 9 | |
| 10 | webrtcDetectedBrowser = "firefox"; |
| 11 | |
| 12 | // The RTCPeerConnection object. |
| 13 | RTCPeerConnection = mozRTCPeerConnection; |
| 14 | |
| 15 | // The RTCSessionDescription object. |
| 16 | RTCSessionDescription = mozRTCSessionDescription; |
| 17 | |
| 18 | // The RTCIceCandidate object. |
| 19 | RTCIceCandidate = mozRTCIceCandidate; |
| 20 | |
| 21 | // Get UserMedia (only difference is the prefix). |
| 22 | // Code from Adam Barth. |
| 23 | getUserMedia = navigator.mozGetUserMedia.bind(navigator); |
| 24 | |
| 25 | // Attach a media stream to an element. |
| 26 | attachMediaStream = function(element, stream) { |
| 27 | console.log("Attaching media stream"); |
| 28 | element.mozSrcObject = stream; |
| 29 | element.play(); |
| 30 | }; |
| 31 | |
| 32 | reattachMediaStream = function(to, from) { |
| 33 | console.log("Reattaching media stream"); |
| 34 | to.mozSrcObject = from.mozSrcObject; |
| 35 | to.play(); |
| 36 | }; |
| 37 | |
| 38 | // Fake get{Video,Audio}Tracks |
| 39 | MediaStream.prototype.getVideoTracks = function() { |
| 40 | return []; |
| 41 | }; |
| 42 | |
| 43 | MediaStream.prototype.getAudioTracks = function() { |
| 44 | return []; |
| 45 | }; |
| 46 | } else if (navigator.webkitGetUserMedia) { |
| 47 | console.log("This appears to be Chrome"); |
| 48 | |
| 49 | webrtcDetectedBrowser = "chrome"; |
| 50 | |
| 51 | // The RTCPeerConnection object. |
| 52 | RTCPeerConnection = webkitRTCPeerConnection; |
| 53 | |
| 54 | // Get UserMedia (only difference is the prefix). |
| 55 | // Code from Adam Barth. |
| 56 | getUserMedia = navigator.webkitGetUserMedia.bind(navigator); |
| 57 | |
| 58 | // Attach a media stream to an element. |
| 59 | attachMediaStream = function(element, stream) { |
| 60 | element.src = webkitURL.createObjectURL(stream); |
| 61 | }; |
| 62 | |
| 63 | reattachMediaStream = function(to, from) { |
| 64 | to.src = from.src; |
| 65 | }; |
| 66 | |
| 67 | // The representation of tracks in a stream is changed in M26. |
| 68 | // Unify them for earlier Chrome versions in the coexisting period. |
| 69 | if (!webkitMediaStream.prototype.getVideoTracks) { |
| 70 | webkitMediaStream.prototype.getVideoTracks = function() { |
| 71 | return this.videoTracks; |
| 72 | }; |
| 73 | webkitMediaStream.prototype.getAudioTracks = function() { |
| 74 | return this.audioTracks; |
| 75 | }; |
| 76 | } |
| 77 | |
| 78 | // New syntax of getXXXStreams method in M26. |
| 79 | if (!webkitRTCPeerConnection.prototype.getLocalStreams) { |
| 80 | webkitRTCPeerConnection.prototype.getLocalStreams = function() { |
| 81 | return this.localStreams; |
| 82 | }; |
| 83 | webkitRTCPeerConnection.prototype.getRemoteStreams = function() { |
| 84 | return this.remoteStreams; |
| 85 | }; |
| 86 | } |
| 87 | } else { |
| 88 | console.log("Browser does not appear to be WebRTC-capable"); |
| 89 | } |