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 | |
vikasmarwaha@webrtc.org | a856db2 | 2013-03-05 03:35:26 +0000 | [diff] [blame] | 7 | function trace(text) { |
| 8 | // This function is used for logging. |
| 9 | if (text[text.length - 1] == '\n') { |
| 10 | text = text.substring(0, text.length - 1); |
| 11 | } |
| 12 | console.log((performance.now() / 1000).toFixed(3) + ": " + text); |
| 13 | } |
| 14 | |
vikasmarwaha@webrtc.org | 98fce15 | 2013-02-27 23:22:10 +0000 | [diff] [blame] | 15 | if (navigator.mozGetUserMedia) { |
| 16 | console.log("This appears to be Firefox"); |
| 17 | |
| 18 | webrtcDetectedBrowser = "firefox"; |
| 19 | |
| 20 | // The RTCPeerConnection object. |
| 21 | RTCPeerConnection = mozRTCPeerConnection; |
| 22 | |
| 23 | // The RTCSessionDescription object. |
| 24 | RTCSessionDescription = mozRTCSessionDescription; |
| 25 | |
| 26 | // The RTCIceCandidate object. |
| 27 | RTCIceCandidate = mozRTCIceCandidate; |
| 28 | |
| 29 | // Get UserMedia (only difference is the prefix). |
| 30 | // Code from Adam Barth. |
| 31 | getUserMedia = navigator.mozGetUserMedia.bind(navigator); |
| 32 | |
| 33 | // Attach a media stream to an element. |
| 34 | attachMediaStream = function(element, stream) { |
| 35 | console.log("Attaching media stream"); |
| 36 | element.mozSrcObject = stream; |
| 37 | element.play(); |
| 38 | }; |
| 39 | |
| 40 | reattachMediaStream = function(to, from) { |
| 41 | console.log("Reattaching media stream"); |
| 42 | to.mozSrcObject = from.mozSrcObject; |
| 43 | to.play(); |
| 44 | }; |
| 45 | |
| 46 | // Fake get{Video,Audio}Tracks |
| 47 | MediaStream.prototype.getVideoTracks = function() { |
| 48 | return []; |
| 49 | }; |
| 50 | |
| 51 | MediaStream.prototype.getAudioTracks = function() { |
| 52 | return []; |
| 53 | }; |
| 54 | } else if (navigator.webkitGetUserMedia) { |
| 55 | console.log("This appears to be Chrome"); |
| 56 | |
| 57 | webrtcDetectedBrowser = "chrome"; |
| 58 | |
| 59 | // The RTCPeerConnection object. |
| 60 | RTCPeerConnection = webkitRTCPeerConnection; |
braveyao@webrtc.org | 07db4a6 | 2013-03-06 03:35:03 +0000 | [diff] [blame] | 61 | |
vikasmarwaha@webrtc.org | 98fce15 | 2013-02-27 23:22:10 +0000 | [diff] [blame] | 62 | // Get UserMedia (only difference is the prefix). |
| 63 | // Code from Adam Barth. |
| 64 | getUserMedia = navigator.webkitGetUserMedia.bind(navigator); |
| 65 | |
| 66 | // Attach a media stream to an element. |
| 67 | attachMediaStream = function(element, stream) { |
vikasmarwaha@webrtc.org | 77ac848 | 2013-04-25 23:22:03 +0000 | [diff] [blame] | 68 | if (typeof element.srcObject !== 'undefined') { |
| 69 | element.srcObject = stream; |
| 70 | } else if (typeof element.mozSrcObject !== 'undefined') { |
| 71 | element.mozSrcObject = stream; |
| 72 | } else if (typeof element.src !== 'undefined') { |
| 73 | element.src = URL.createObjectURL(stream); |
| 74 | } else { |
| 75 | console.log('Error attaching stream to element.'); |
| 76 | } |
vikasmarwaha@webrtc.org | 98fce15 | 2013-02-27 23:22:10 +0000 | [diff] [blame] | 77 | }; |
| 78 | |
| 79 | reattachMediaStream = function(to, from) { |
| 80 | to.src = from.src; |
| 81 | }; |
| 82 | |
| 83 | // The representation of tracks in a stream is changed in M26. |
| 84 | // Unify them for earlier Chrome versions in the coexisting period. |
| 85 | if (!webkitMediaStream.prototype.getVideoTracks) { |
| 86 | webkitMediaStream.prototype.getVideoTracks = function() { |
| 87 | return this.videoTracks; |
| 88 | }; |
| 89 | webkitMediaStream.prototype.getAudioTracks = function() { |
| 90 | return this.audioTracks; |
| 91 | }; |
| 92 | } |
| 93 | |
| 94 | // New syntax of getXXXStreams method in M26. |
| 95 | if (!webkitRTCPeerConnection.prototype.getLocalStreams) { |
| 96 | webkitRTCPeerConnection.prototype.getLocalStreams = function() { |
| 97 | return this.localStreams; |
| 98 | }; |
| 99 | webkitRTCPeerConnection.prototype.getRemoteStreams = function() { |
| 100 | return this.remoteStreams; |
| 101 | }; |
| 102 | } |
| 103 | } else { |
| 104 | console.log("Browser does not appear to be WebRTC-capable"); |
| 105 | } |