blob: 4294f34d88d0d82c96a0ee4e5b6e834c5723433c [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;
61
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) {
68 element.src = webkitURL.createObjectURL(stream);
69 };
70
71 reattachMediaStream = function(to, from) {
72 to.src = from.src;
73 };
74
75 // The representation of tracks in a stream is changed in M26.
76 // Unify them for earlier Chrome versions in the coexisting period.
77 if (!webkitMediaStream.prototype.getVideoTracks) {
78 webkitMediaStream.prototype.getVideoTracks = function() {
79 return this.videoTracks;
80 };
81 webkitMediaStream.prototype.getAudioTracks = function() {
82 return this.audioTracks;
83 };
84 }
85
86 // New syntax of getXXXStreams method in M26.
87 if (!webkitRTCPeerConnection.prototype.getLocalStreams) {
88 webkitRTCPeerConnection.prototype.getLocalStreams = function() {
89 return this.localStreams;
90 };
91 webkitRTCPeerConnection.prototype.getRemoteStreams = function() {
92 return this.remoteStreams;
93 };
94 }
95} else {
96 console.log("Browser does not appear to be WebRTC-capable");
97}