blob: 77d92b1ad336ee3d499e052b26a7b0f13f5af10b [file] [log] [blame]
vikasmarwaha@webrtc.org98fce152013-02-27 23:22:10 +00001var RTCPeerConnection = null;
2var getUserMedia = null;
3var attachMediaStream = null;
4var reattachMediaStream = null;
5var webrtcDetectedBrowser = null;
6
vikasmarwaha@webrtc.orga856db22013-03-05 03:35:26 +00007function 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.org98fce152013-02-27 23:22:10 +000015if (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.org07db4a62013-03-06 03:35:03 +000061
vikasmarwaha@webrtc.org98fce152013-02-27 23:22:10 +000062 // 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.org77ac8482013-04-25 23:22:03 +000068 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.org98fce152013-02-27 23:22:10 +000077 };
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}