Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(536)

Side by Side Diff: chrome/test/data/webrtc/adapter.js

Issue 23172002: Landing https://codereview.chromium.org/18769010/. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 var RTCPeerConnection = null;
2 var getUserMedia = null;
3 var attachMediaStream = null;
4 var reattachMediaStream = null;
5 var webrtcDetectedBrowser = null;
6 var webrtcDetectedVersion = null;
7
8 function trace(text) {
9 // This function is used for logging.
10 if (text[text.length - 1] == '\n') {
11 text = text.substring(0, text.length - 1);
12 }
13 console.log((performance.now() / 1000).toFixed(3) + ": " + text);
14 }
15
16 if (navigator.mozGetUserMedia) {
17 console.log("This appears to be Firefox");
18
19 webrtcDetectedBrowser = "firefox";
20
21 webrtcDetectedVersion =
22 parseInt(navigator.userAgent.match(/Firefox\/([0-9]+)\./)[1]);
23
24 // The RTCPeerConnection object.
25 RTCPeerConnection = mozRTCPeerConnection;
26
27 // The RTCSessionDescription object.
28 RTCSessionDescription = mozRTCSessionDescription;
29
30 // The RTCIceCandidate object.
31 RTCIceCandidate = mozRTCIceCandidate;
32
33 // Get UserMedia (only difference is the prefix).
34 // Code from Adam Barth.
35 getUserMedia = navigator.mozGetUserMedia.bind(navigator);
36
37 // Creates iceServer from the url for FF.
38 createIceServer = function(url, username, password) {
39 var iceServer = null;
40 var url_parts = url.split(':');
41 if (url_parts[0].indexOf('stun') === 0) {
42 // Create iceServer with stun url.
43 iceServer = { 'url': url };
44 } else if (url_parts[0].indexOf('turn') === 0 &&
45 (url.indexOf('transport=udp') !== -1 ||
46 url.indexOf('?transport') === -1)) {
47 // Create iceServer with turn url.
48 // Ignore the transport parameter from TURN url.
49 var turn_url_parts = url.split("?");
50 iceServer = { 'url': turn_url_parts[0],
51 'credential': password,
52 'username': username };
53 }
54 return iceServer;
55 };
56
57 // Attach a media stream to an element.
58 attachMediaStream = function(element, stream) {
59 console.log("Attaching media stream");
60 element.mozSrcObject = stream;
61 element.play();
62 };
63
64 reattachMediaStream = function(to, from) {
65 console.log("Reattaching media stream");
66 to.mozSrcObject = from.mozSrcObject;
67 to.play();
68 };
69
70 // Fake get{Video,Audio}Tracks
71 MediaStream.prototype.getVideoTracks = function() {
72 return [];
73 };
74
75 MediaStream.prototype.getAudioTracks = function() {
76 return [];
77 };
78 } else if (navigator.webkitGetUserMedia) {
79 console.log("This appears to be Chrome");
80
81 webrtcDetectedBrowser = "chrome";
82 webrtcDetectedVersion =
83 parseInt(navigator.userAgent.match(/Chrom(e|ium)\/([0-9]+)\./)[2]);
84
85 // Creates iceServer from the url for Chrome.
86 createIceServer = function(url, username, password) {
87 var iceServer = null;
88 var url_parts = url.split(':');
89 if (url_parts[0].indexOf('stun') === 0) {
90 // Create iceServer with stun url.
91 iceServer = { 'url': url };
92 } else if (url_parts[0].indexOf('turn') === 0) {
93 if (webrtcDetectedVersion < 28) {
94 // For pre-M28 chrome versions use old TURN format.
95 var url_turn_parts = url.split("turn:");
96 iceServer = { 'url': 'turn:' + username + '@' + url_turn_parts[1],
97 'credential': password };
98 } else {
99 // For Chrome M28 & above use new TURN format.
100 iceServer = { 'url': url,
101 'credential': password,
102 'username': username };
103 }
104 }
105 return iceServer;
106 };
107
108 // The RTCPeerConnection object.
109 RTCPeerConnection = webkitRTCPeerConnection;
110
111 // Get UserMedia (only difference is the prefix).
112 // Code from Adam Barth.
113 getUserMedia = navigator.webkitGetUserMedia.bind(navigator);
114
115 // Attach a media stream to an element.
116 attachMediaStream = function(element, stream) {
117 if (typeof element.srcObject !== 'undefined') {
118 element.srcObject = stream;
119 } else if (typeof element.mozSrcObject !== 'undefined') {
120 element.mozSrcObject = stream;
121 } else if (typeof element.src !== 'undefined') {
122 element.src = URL.createObjectURL(stream);
123 } else {
124 console.log('Error attaching stream to element.');
125 }
126 };
127
128 reattachMediaStream = function(to, from) {
129 to.src = from.src;
130 };
131
132 // The representation of tracks in a stream is changed in M26.
133 // Unify them for earlier Chrome versions in the coexisting period.
134 if (!webkitMediaStream.prototype.getVideoTracks) {
135 webkitMediaStream.prototype.getVideoTracks = function() {
136 return this.videoTracks;
137 };
138 webkitMediaStream.prototype.getAudioTracks = function() {
139 return this.audioTracks;
140 };
141 }
142
143 // New syntax of getXXXStreams method in M26.
144 if (!webkitRTCPeerConnection.prototype.getLocalStreams) {
145 webkitRTCPeerConnection.prototype.getLocalStreams = function() {
146 return this.localStreams;
147 };
148 webkitRTCPeerConnection.prototype.getRemoteStreams = function() {
149 return this.remoteStreams;
150 };
151 }
152 } else {
153 console.log("Browser does not appear to be WebRTC-capable");
154 }
OLDNEW
« no previous file with comments | « chrome/browser/media/webrtc_browsertest_base.cc ('k') | chrome/test/data/webrtc/getusermedia.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698