/usr/share/javascript/rtcninja/Adapter.js is in libjs-rtcninja 0.6.2-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 | 'use strict';
// Expose the Adapter function/object.
module.exports = Adapter;
// Dependencies
var browser = require('bowser').browser,
debug = require('debug')('rtcninja:Adapter'),
debugerror = require('debug')('rtcninja:ERROR:Adapter'),
// Internal vars
getUserMedia = null,
RTCPeerConnection = null,
RTCSessionDescription = null,
RTCIceCandidate = null,
MediaStreamTrack = null,
getMediaDevices = null,
attachMediaStream = null,
canRenegotiate = false,
oldSpecRTCOfferOptions = false,
browserVersion = Number(browser.version) || 0,
isDesktop = !!(!browser.mobile || !browser.tablet),
hasWebRTC = false,
virtGlobal, virtNavigator;
debugerror.log = console.warn.bind(console);
// Dirty trick to get this library working in a Node-webkit env with browserified libs
virtGlobal = global.window || global;
// Don't fail in Node
virtNavigator = virtGlobal.navigator || {};
// Constructor.
function Adapter(options) {
// Chrome desktop, Chrome Android, Opera desktop, Opera Android, Android native browser
// or generic Webkit browser.
if (
(isDesktop && browser.chrome && browserVersion >= 32) ||
(browser.android && browser.chrome && browserVersion >= 39) ||
(isDesktop && browser.opera && browserVersion >= 27) ||
(browser.android && browser.opera && browserVersion >= 24) ||
(browser.android && browser.webkit && !browser.chrome && browserVersion >= 37) ||
(virtNavigator.webkitGetUserMedia && virtGlobal.webkitRTCPeerConnection)
) {
hasWebRTC = true;
getUserMedia = virtNavigator.webkitGetUserMedia.bind(virtNavigator);
RTCPeerConnection = virtGlobal.webkitRTCPeerConnection;
RTCSessionDescription = virtGlobal.RTCSessionDescription;
RTCIceCandidate = virtGlobal.RTCIceCandidate;
MediaStreamTrack = virtGlobal.MediaStreamTrack;
if (MediaStreamTrack && MediaStreamTrack.getSources) {
getMediaDevices = MediaStreamTrack.getSources.bind(MediaStreamTrack);
} else if (virtNavigator.getMediaDevices) {
getMediaDevices = virtNavigator.getMediaDevices.bind(virtNavigator);
}
attachMediaStream = function (element, stream) {
element.src = URL.createObjectURL(stream);
return element;
};
canRenegotiate = true;
oldSpecRTCOfferOptions = false;
// Firefox desktop, Firefox Android.
} else if (
(isDesktop && browser.firefox && browserVersion >= 22) ||
(browser.android && browser.firefox && browserVersion >= 33) ||
(virtNavigator.mozGetUserMedia && virtGlobal.mozRTCPeerConnection)
) {
hasWebRTC = true;
getUserMedia = virtNavigator.mozGetUserMedia.bind(virtNavigator);
RTCPeerConnection = virtGlobal.mozRTCPeerConnection;
RTCSessionDescription = virtGlobal.mozRTCSessionDescription;
RTCIceCandidate = virtGlobal.mozRTCIceCandidate;
MediaStreamTrack = virtGlobal.MediaStreamTrack;
attachMediaStream = function (element, stream) {
element.src = URL.createObjectURL(stream);
return element;
};
canRenegotiate = false;
oldSpecRTCOfferOptions = false;
// WebRTC plugin required. For example IE or Safari with the Temasys plugin.
} else if (
options.plugin &&
typeof options.plugin.isRequired === 'function' &&
options.plugin.isRequired() &&
typeof options.plugin.isInstalled === 'function' &&
options.plugin.isInstalled()
) {
var pluginiface = options.plugin.interface;
hasWebRTC = true;
getUserMedia = pluginiface.getUserMedia;
RTCPeerConnection = pluginiface.RTCPeerConnection;
RTCSessionDescription = pluginiface.RTCSessionDescription;
RTCIceCandidate = pluginiface.RTCIceCandidate;
MediaStreamTrack = pluginiface.MediaStreamTrack;
if (MediaStreamTrack && MediaStreamTrack.getSources) {
getMediaDevices = MediaStreamTrack.getSources.bind(MediaStreamTrack);
} else if (virtNavigator.getMediaDevices) {
getMediaDevices = virtNavigator.getMediaDevices.bind(virtNavigator);
}
attachMediaStream = pluginiface.attachMediaStream;
canRenegotiate = pluginiface.canRenegotiate;
oldSpecRTCOfferOptions = true; // TODO: Update when fixed in the plugin.
// Best effort (may be adater.js is loaded).
} else if (virtNavigator.getUserMedia && virtGlobal.RTCPeerConnection) {
hasWebRTC = true;
getUserMedia = virtNavigator.getUserMedia.bind(virtNavigator);
RTCPeerConnection = virtGlobal.RTCPeerConnection;
RTCSessionDescription = virtGlobal.RTCSessionDescription;
RTCIceCandidate = virtGlobal.RTCIceCandidate;
MediaStreamTrack = virtGlobal.MediaStreamTrack;
if (MediaStreamTrack && MediaStreamTrack.getSources) {
getMediaDevices = MediaStreamTrack.getSources.bind(MediaStreamTrack);
} else if (virtNavigator.getMediaDevices) {
getMediaDevices = virtNavigator.getMediaDevices.bind(virtNavigator);
}
attachMediaStream = virtGlobal.attachMediaStream || function (element, stream) {
element.src = URL.createObjectURL(stream);
return element;
};
canRenegotiate = false;
oldSpecRTCOfferOptions = false;
}
function throwNonSupported(item) {
return function () {
throw new Error('rtcninja: WebRTC not supported, missing ' + item +
' [browser: ' + browser.name + ' ' + browser.version + ']');
};
}
// Public API.
// Expose a WebRTC checker.
Adapter.hasWebRTC = function () {
return hasWebRTC;
};
// Expose getUserMedia.
if (getUserMedia) {
Adapter.getUserMedia = function (constraints, successCallback, errorCallback) {
debug('getUserMedia() | constraints: %o', constraints);
try {
getUserMedia(constraints,
function (stream) {
debug('getUserMedia() | success');
if (successCallback) {
successCallback(stream);
}
},
function (error) {
debug('getUserMedia() | error:', error);
if (errorCallback) {
errorCallback(error);
}
}
);
}
catch (error) {
debugerror('getUserMedia() | error:', error);
if (errorCallback) {
errorCallback(error);
}
}
};
} else {
Adapter.getUserMedia = function (constraints, successCallback, errorCallback) {
debugerror('getUserMedia() | WebRTC not supported');
if (errorCallback) {
errorCallback(new Error('rtcninja: WebRTC not supported, missing ' +
'getUserMedia [browser: ' + browser.name + ' ' + browser.version + ']'));
} else {
throwNonSupported('getUserMedia');
}
};
}
// Expose RTCPeerConnection.
Adapter.RTCPeerConnection = RTCPeerConnection || throwNonSupported('RTCPeerConnection');
// Expose RTCSessionDescription.
Adapter.RTCSessionDescription = RTCSessionDescription || throwNonSupported('RTCSessionDescription');
// Expose RTCIceCandidate.
Adapter.RTCIceCandidate = RTCIceCandidate || throwNonSupported('RTCIceCandidate');
// Expose MediaStreamTrack.
Adapter.MediaStreamTrack = MediaStreamTrack || throwNonSupported('MediaStreamTrack');
// Expose getMediaDevices.
Adapter.getMediaDevices = getMediaDevices;
// Expose MediaStreamTrack.
Adapter.attachMediaStream = attachMediaStream || throwNonSupported('attachMediaStream');
// Expose canRenegotiate attribute.
Adapter.canRenegotiate = canRenegotiate;
// Expose closeMediaStream.
Adapter.closeMediaStream = function (stream) {
if (!stream) {
return;
}
// Latest spec states that MediaStream has no stop() method and instead must
// call stop() on every MediaStreamTrack.
if (MediaStreamTrack && MediaStreamTrack.prototype && MediaStreamTrack.prototype.stop) {
debug('closeMediaStream() | calling stop() on all the MediaStreamTrack');
var tracks, i, len;
if (stream.getTracks) {
tracks = stream.getTracks();
for (i = 0, len = tracks.length; i < len; i += 1) {
tracks[i].stop();
}
} else {
tracks = stream.getAudioTracks();
for (i = 0, len = tracks.length; i < len; i += 1) {
tracks[i].stop();
}
tracks = stream.getVideoTracks();
for (i = 0, len = tracks.length; i < len; i += 1) {
tracks[i].stop();
}
}
// Deprecated by the spec, but still in use.
} else if (typeof stream.stop === 'function') {
debug('closeMediaStream() | calling stop() on the MediaStream');
stream.stop();
}
};
// Expose fixPeerConnectionConfig.
Adapter.fixPeerConnectionConfig = function (pcConfig) {
var i, len, iceServer, hasUrls, hasUrl;
if (!Array.isArray(pcConfig.iceServers)) {
pcConfig.iceServers = [];
}
for (i = 0, len = pcConfig.iceServers.length; i < len; i += 1) {
iceServer = pcConfig.iceServers[i];
hasUrls = iceServer.hasOwnProperty('urls');
hasUrl = iceServer.hasOwnProperty('url');
if (typeof iceServer === 'object') {
// Has .urls but not .url, so add .url with a single string value.
if (hasUrls && !hasUrl) {
iceServer.url = (Array.isArray(iceServer.urls) ? iceServer.urls[0] : iceServer.urls);
// Has .url but not .urls, so add .urls with same value.
} else if (!hasUrls && hasUrl) {
iceServer.urls = (Array.isArray(iceServer.url) ? iceServer.url.slice() : iceServer.url);
}
// Ensure .url is a single string.
if (hasUrl && Array.isArray(iceServer.url)) {
iceServer.url = iceServer.url[0];
}
}
}
};
// Expose fixRTCOfferOptions.
Adapter.fixRTCOfferOptions = function (options) {
options = options || {};
// New spec.
if (!oldSpecRTCOfferOptions) {
if (options.mandatory && options.mandatory.OfferToReceiveAudio) {
options.offerToReceiveAudio = 1;
}
if (options.mandatory && options.mandatory.OfferToReceiveVideo) {
options.offerToReceiveVideo = 1;
}
delete options.mandatory;
// Old spec.
} else {
if (options.offerToReceiveAudio) {
options.mandatory = options.mandatory || {};
options.mandatory.OfferToReceiveAudio = true;
}
if (options.offerToReceiveVideo) {
options.mandatory = options.mandatory || {};
options.mandatory.OfferToReceiveVideo = true;
}
}
};
return Adapter;
}
|