Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

RTC.bundle.js 37KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165
  1. !function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.RTC=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
  2. /* global connection, Strophe, updateLargeVideo, focusedVideoSrc*/
  3. // cache datachannels to avoid garbage collection
  4. // https://code.google.com/p/chromium/issues/detail?id=405545
  5. var _dataChannels = [];
  6. var DataChannels =
  7. {
  8. /**
  9. * Callback triggered by PeerConnection when new data channel is opened
  10. * on the bridge.
  11. * @param event the event info object.
  12. */
  13. onDataChannel: function (event)
  14. {
  15. var dataChannel = event.channel;
  16. dataChannel.onopen = function () {
  17. console.info("Data channel opened by the Videobridge!", dataChannel);
  18. // Code sample for sending string and/or binary data
  19. // Sends String message to the bridge
  20. //dataChannel.send("Hello bridge!");
  21. // Sends 12 bytes binary message to the bridge
  22. //dataChannel.send(new ArrayBuffer(12));
  23. // when the data channel becomes available, tell the bridge about video
  24. // selections so that it can do adaptive simulcast,
  25. // we want the notification to trigger even if userJid is undefined,
  26. // or null.
  27. var userJid = UI.getLargeVideoState().userJid;
  28. // we want the notification to trigger even if userJid is undefined,
  29. // or null.
  30. onSelectedEndpointChanged(userJid);
  31. };
  32. dataChannel.onerror = function (error) {
  33. console.error("Data Channel Error:", error, dataChannel);
  34. };
  35. dataChannel.onmessage = function (event) {
  36. var data = event.data;
  37. // JSON
  38. var obj;
  39. try {
  40. obj = JSON.parse(data);
  41. }
  42. catch (e) {
  43. console.error(
  44. "Failed to parse data channel message as JSON: ",
  45. data,
  46. dataChannel);
  47. }
  48. if (('undefined' !== typeof(obj)) && (null !== obj)) {
  49. var colibriClass = obj.colibriClass;
  50. if ("DominantSpeakerEndpointChangeEvent" === colibriClass) {
  51. // Endpoint ID from the Videobridge.
  52. var dominantSpeakerEndpoint = obj.dominantSpeakerEndpoint;
  53. console.info(
  54. "Data channel new dominant speaker event: ",
  55. dominantSpeakerEndpoint);
  56. $(document).trigger(
  57. 'dominantspeakerchanged',
  58. [dominantSpeakerEndpoint]);
  59. }
  60. else if ("InLastNChangeEvent" === colibriClass)
  61. {
  62. var oldValue = obj.oldValue;
  63. var newValue = obj.newValue;
  64. // Make sure that oldValue and newValue are of type boolean.
  65. var type;
  66. if ((type = typeof oldValue) !== 'boolean') {
  67. if (type === 'string') {
  68. oldValue = (oldValue == "true");
  69. } else {
  70. oldValue = new Boolean(oldValue).valueOf();
  71. }
  72. }
  73. if ((type = typeof newValue) !== 'boolean') {
  74. if (type === 'string') {
  75. newValue = (newValue == "true");
  76. } else {
  77. newValue = new Boolean(newValue).valueOf();
  78. }
  79. }
  80. $(document).trigger('inlastnchanged', [oldValue, newValue]);
  81. }
  82. else if ("LastNEndpointsChangeEvent" === colibriClass)
  83. {
  84. // The new/latest list of last-n endpoint IDs.
  85. var lastNEndpoints = obj.lastNEndpoints;
  86. // The list of endpoint IDs which are entering the list of
  87. // last-n at this time i.e. were not in the old list of last-n
  88. // endpoint IDs.
  89. var endpointsEnteringLastN = obj.endpointsEnteringLastN;
  90. var stream = obj.stream;
  91. console.log(
  92. "Data channel new last-n event: ",
  93. lastNEndpoints, endpointsEnteringLastN, obj);
  94. $(document).trigger(
  95. 'lastnchanged',
  96. [lastNEndpoints, endpointsEnteringLastN, stream]);
  97. }
  98. else if ("SimulcastLayersChangedEvent" === colibriClass)
  99. {
  100. $(document).trigger(
  101. 'simulcastlayerschanged',
  102. [obj.endpointSimulcastLayers]);
  103. }
  104. else if ("SimulcastLayersChangingEvent" === colibriClass)
  105. {
  106. $(document).trigger(
  107. 'simulcastlayerschanging',
  108. [obj.endpointSimulcastLayers]);
  109. }
  110. else if ("StartSimulcastLayerEvent" === colibriClass)
  111. {
  112. $(document).trigger('startsimulcastlayer', obj.simulcastLayer);
  113. }
  114. else if ("StopSimulcastLayerEvent" === colibriClass)
  115. {
  116. $(document).trigger('stopsimulcastlayer', obj.simulcastLayer);
  117. }
  118. else
  119. {
  120. console.debug("Data channel JSON-formatted message: ", obj);
  121. }
  122. }
  123. };
  124. dataChannel.onclose = function ()
  125. {
  126. console.info("The Data Channel closed", dataChannel);
  127. var idx = _dataChannels.indexOf(dataChannel);
  128. if (idx > -1)
  129. _dataChannels = _dataChannels.splice(idx, 1);
  130. };
  131. _dataChannels.push(dataChannel);
  132. },
  133. /**
  134. * Binds "ondatachannel" event listener to given PeerConnection instance.
  135. * @param peerConnection WebRTC peer connection instance.
  136. */
  137. bindDataChannelListener: function (peerConnection) {
  138. if(!config.openSctp)
  139. retrun;
  140. peerConnection.ondatachannel = this.onDataChannel;
  141. // Sample code for opening new data channel from Jitsi Meet to the bridge.
  142. // Although it's not a requirement to open separate channels from both bridge
  143. // and peer as single channel can be used for sending and receiving data.
  144. // So either channel opened by the bridge or the one opened here is enough
  145. // for communication with the bridge.
  146. /*var dataChannelOptions =
  147. {
  148. reliable: true
  149. };
  150. var dataChannel
  151. = peerConnection.createDataChannel("myChannel", dataChannelOptions);
  152. // Can be used only when is in open state
  153. dataChannel.onopen = function ()
  154. {
  155. dataChannel.send("My channel !!!");
  156. };
  157. dataChannel.onmessage = function (event)
  158. {
  159. var msgData = event.data;
  160. console.info("Got My Data Channel Message:", msgData, dataChannel);
  161. };*/
  162. }
  163. }
  164. function onSelectedEndpointChanged(userJid)
  165. {
  166. console.log('selected endpoint changed: ', userJid);
  167. if (_dataChannels && _dataChannels.length != 0)
  168. {
  169. _dataChannels.some(function (dataChannel) {
  170. if (dataChannel.readyState == 'open')
  171. {
  172. dataChannel.send(JSON.stringify({
  173. 'colibriClass': 'SelectedEndpointChangedEvent',
  174. 'selectedEndpoint': (!userJid || userJid == null)
  175. ? null : userJid
  176. }));
  177. return true;
  178. }
  179. });
  180. }
  181. }
  182. $(document).bind("selectedendpointchanged", function(event, userJid) {
  183. onSelectedEndpointChanged(userJid);
  184. });
  185. function onPinnedEndpointChanged(userJid)
  186. {
  187. console.log('pinned endpoint changed: ', userJid);
  188. if (_dataChannels && _dataChannels.length != 0)
  189. {
  190. _dataChannels.some(function (dataChannel) {
  191. if (dataChannel.readyState == 'open')
  192. {
  193. dataChannel.send(JSON.stringify({
  194. 'colibriClass': 'PinnedEndpointChangedEvent',
  195. 'pinnedEndpoint': (!userJid || userJid == null)
  196. ? null : Strophe.getResourceFromJid(userJid)
  197. }));
  198. return true;
  199. }
  200. });
  201. }
  202. }
  203. $(document).bind("pinnedendpointchanged", function(event, userJid) {
  204. onPinnedEndpointChanged(userJid);
  205. });
  206. module.exports = DataChannels;
  207. },{}],2:[function(require,module,exports){
  208. //var StreamEventTypes = require("../../service/RTC/StreamEventTypes.js");
  209. function LocalStream(stream, type, eventEmitter)
  210. {
  211. this.stream = stream;
  212. this.eventEmitter = eventEmitter;
  213. this.type = type;
  214. var self = this;
  215. if(type == "audio")
  216. {
  217. this.getTracks = function () {
  218. return self.stream.getAudioTracks();
  219. };
  220. }
  221. else
  222. {
  223. this.getTracks = function () {
  224. return self.stream.getVideoTracks();
  225. };
  226. }
  227. this.stream.onended = function()
  228. {
  229. self.streamEnded();
  230. };
  231. }
  232. LocalStream.prototype.streamEnded = function () {
  233. this.eventEmitter.emit(StreamEventTypes.EVENT_TYPE_LOCAL_ENDED, this);
  234. }
  235. LocalStream.prototype.getOriginalStream = function()
  236. {
  237. return this.stream;
  238. }
  239. LocalStream.prototype.isAudioStream = function () {
  240. return (this.stream.getAudioTracks() && this.stream.getAudioTracks().length > 0);
  241. };
  242. LocalStream.prototype.mute = function()
  243. {
  244. var ismuted = false;
  245. var tracks = this.getTracks();
  246. for (var idx = 0; idx < tracks.length; idx++) {
  247. ismuted = !tracks[idx].enabled;
  248. tracks[idx].enabled = ismuted;
  249. }
  250. return ismuted;
  251. };
  252. LocalStream.prototype.setMute = function(mute)
  253. {
  254. var tracks = this.getTracks();
  255. for (var idx = 0; idx < tracks.length; idx++) {
  256. tracks[idx].enabled = mute;
  257. }
  258. };
  259. LocalStream.prototype.isMuted = function () {
  260. var tracks = [];
  261. if(this.type == "audio")
  262. {
  263. tracks = this.stream.getAudioTracks();
  264. }
  265. else
  266. {
  267. tracks = this.stream.getVideoTracks();
  268. }
  269. for (var idx = 0; idx < tracks.length; idx++) {
  270. if(tracks[idx].enabled)
  271. return false;
  272. }
  273. return true;
  274. }
  275. LocalStream.prototype.getId = function () {
  276. return this.stream.getTracks()[0].id;
  277. }
  278. module.exports = LocalStream;
  279. },{}],3:[function(require,module,exports){
  280. ////These lines should be uncommented when require works in app.js
  281. //var RTCBrowserType = require("../../service/RTC/RTCBrowserType.js");
  282. //var StreamEventTypes = require("../../service/RTC/StreamEventTypes.js");
  283. //var MediaStreamType = require("../../service/RTC/MediaStreamTypes");
  284. /**
  285. * Creates a MediaStream object for the given data, session id and ssrc.
  286. * It is a wrapper class for the MediaStream.
  287. *
  288. * @param data the data object from which we obtain the stream,
  289. * the peerjid, etc.
  290. * @param sid the session id
  291. * @param ssrc the ssrc corresponding to this MediaStream
  292. *
  293. * @constructor
  294. */
  295. function MediaStream(data, sid, ssrc, eventEmmiter, browser) {
  296. // XXX(gp) to minimize headaches in the future, we should build our
  297. // abstractions around tracks and not streams. ORTC is track based API.
  298. // Mozilla expects m-lines to represent media tracks.
  299. //
  300. // Practically, what I'm saying is that we should have a MediaTrack class
  301. // and not a MediaStream class.
  302. //
  303. // Also, we should be able to associate multiple SSRCs with a MediaTrack as
  304. // a track might have an associated RTX and FEC sources.
  305. this.sid = sid;
  306. this.stream = data.stream;
  307. this.peerjid = data.peerjid;
  308. this.ssrc = ssrc;
  309. this.type = (this.stream.getVideoTracks().length > 0)?
  310. MediaStreamType.VIDEO_TYPE : MediaStreamType.AUDIO_TYPE;
  311. this.muted = false;
  312. eventEmmiter.emit(StreamEventTypes.EVENT_TYPE_REMOTE_CREATED, this);
  313. if(browser == RTCBrowserType.RTC_BROWSER_FIREFOX)
  314. {
  315. if (!this.getVideoTracks)
  316. this.getVideoTracks = function () { return []; };
  317. if (!this.getAudioTracks)
  318. this.getAudioTracks = function () { return []; };
  319. }
  320. }
  321. MediaStream.prototype.getOriginalStream = function()
  322. {
  323. return this.stream;
  324. }
  325. MediaStream.prototype.setMute = function (value)
  326. {
  327. this.stream.muted = value;
  328. this.muted = value;
  329. }
  330. module.exports = MediaStream;
  331. },{}],4:[function(require,module,exports){
  332. var EventEmitter = require("events");
  333. var RTCUtils = require("./RTCUtils.js");
  334. var LocalStream = require("./LocalStream.js");
  335. var DataChannels = require("./DataChannels");
  336. var MediaStream = require("./MediaStream.js");
  337. //These lines should be uncommented when require works in app.js
  338. //var StreamEventTypes = require("../../service/RTC/StreamEventTypes.js");
  339. //var XMPPEvents = require("../service/xmpp/XMPPEvents");
  340. var eventEmitter = new EventEmitter();
  341. var RTC = {
  342. rtcUtils: null,
  343. localStreams: [],
  344. remoteStreams: {},
  345. localAudio: null,
  346. localVideo: null,
  347. addStreamListener: function (listener, eventType) {
  348. eventEmitter.on(eventType, listener);
  349. },
  350. removeStreamListener: function (listener, eventType) {
  351. if(!(eventType instanceof StreamEventTypes))
  352. throw "Illegal argument";
  353. eventEmitter.removeListener(eventType, listener);
  354. },
  355. createLocalStream: function (stream, type) {
  356. var localStream = new LocalStream(stream, type, eventEmitter);
  357. //in firefox we have only one stream object
  358. if(this.localStreams.length == 0 ||
  359. this.localStreams[0].getOriginalStream() != stream)
  360. this.localStreams.push(localStream);
  361. if(type == "audio")
  362. {
  363. this.localAudio = localStream;
  364. }
  365. else
  366. {
  367. this.localVideo = localStream;
  368. }
  369. eventEmitter.emit(StreamEventTypes.EVENT_TYPE_LOCAL_CREATED,
  370. localStream);
  371. return localStream;
  372. },
  373. removeLocalStream: function (stream) {
  374. for(var i = 0; i < this.localStreams.length; i++)
  375. {
  376. if(this.localStreams[i].getOriginalStream() === stream) {
  377. delete this.localStreams[i];
  378. return;
  379. }
  380. }
  381. },
  382. createRemoteStream: function (data, sid, thessrc) {
  383. var remoteStream = new MediaStream(data, sid, thessrc, eventEmitter,
  384. this.getBrowserType());
  385. var jid = data.peerjid || connection.emuc.myroomjid;
  386. if(!this.remoteStreams[jid]) {
  387. this.remoteStreams[jid] = {};
  388. }
  389. this.remoteStreams[jid][remoteStream.type]= remoteStream;
  390. return remoteStream;
  391. },
  392. getBrowserType: function () {
  393. return this.rtcUtils.browser;
  394. },
  395. getPCConstraints: function () {
  396. return this.rtcUtils.pc_constraints;
  397. },
  398. getUserMediaWithConstraints:function(um, success_callback,
  399. failure_callback, resolution,
  400. bandwidth, fps, desktopStream)
  401. {
  402. return this.rtcUtils.getUserMediaWithConstraints(um, success_callback,
  403. failure_callback, resolution, bandwidth, fps, desktopStream);
  404. },
  405. attachMediaStream: function (element, stream) {
  406. this.rtcUtils.attachMediaStream(element, stream);
  407. },
  408. getStreamID: function (stream) {
  409. return this.rtcUtils.getStreamID(stream);
  410. },
  411. getVideoSrc: function (element) {
  412. return this.rtcUtils.getVideoSrc(element);
  413. },
  414. setVideoSrc: function (element, src) {
  415. this.rtcUtils.setVideoSrc(element, src);
  416. },
  417. dispose: function() {
  418. if (this.rtcUtils) {
  419. this.rtcUtils = null;
  420. }
  421. },
  422. stop: function () {
  423. this.dispose();
  424. },
  425. start: function () {
  426. this.rtcUtils = new RTCUtils(this);
  427. this.rtcUtils.obtainAudioAndVideoPermissions();
  428. },
  429. onConferenceCreated: function(event) {
  430. DataChannels.bindDataChannelListener(event.peerconnection);
  431. },
  432. muteRemoteVideoStream: function (jid, value) {
  433. var stream;
  434. if(this.remoteStreams[jid] &&
  435. this.remoteStreams[jid][MediaStreamType.VIDEO_TYPE])
  436. {
  437. stream = this.remoteStreams[jid][MediaStreamType.VIDEO_TYPE];
  438. }
  439. if(!stream)
  440. return false;
  441. if (value != stream.muted) {
  442. stream.setMute(value);
  443. return true;
  444. }
  445. return false;
  446. },
  447. switchVideoStreams: function (new_stream) {
  448. this.localVideo.stream = new_stream;
  449. this.localStreams = [];
  450. //in firefox we have only one stream object
  451. if(this.localAudio.getOriginalStream() != new_stream)
  452. this.localStreams.push(this.localAudio);
  453. this.localStreams.push(this.localVideo);
  454. }
  455. };
  456. module.exports = RTC;
  457. },{"./DataChannels":1,"./LocalStream.js":2,"./MediaStream.js":3,"./RTCUtils.js":5,"events":6}],5:[function(require,module,exports){
  458. //This should be uncommented when app.js supports require
  459. //var RTCBrowserType = require("../../service/RTC/RTCBrowserType.js");
  460. function setResolutionConstraints(constraints, resolution, isAndroid)
  461. {
  462. if (resolution && !constraints.video || isAndroid) {
  463. constraints.video = { mandatory: {}, optional: [] };// same behaviour as true
  464. }
  465. // see https://code.google.com/p/chromium/issues/detail?id=143631#c9 for list of supported resolutions
  466. switch (resolution) {
  467. // 16:9 first
  468. case '1080':
  469. case 'fullhd':
  470. constraints.video.mandatory.minWidth = 1920;
  471. constraints.video.mandatory.minHeight = 1080;
  472. break;
  473. case '720':
  474. case 'hd':
  475. constraints.video.mandatory.minWidth = 1280;
  476. constraints.video.mandatory.minHeight = 720;
  477. break;
  478. case '360':
  479. constraints.video.mandatory.minWidth = 640;
  480. constraints.video.mandatory.minHeight = 360;
  481. break;
  482. case '180':
  483. constraints.video.mandatory.minWidth = 320;
  484. constraints.video.mandatory.minHeight = 180;
  485. break;
  486. // 4:3
  487. case '960':
  488. constraints.video.mandatory.minWidth = 960;
  489. constraints.video.mandatory.minHeight = 720;
  490. break;
  491. case '640':
  492. case 'vga':
  493. constraints.video.mandatory.minWidth = 640;
  494. constraints.video.mandatory.minHeight = 480;
  495. break;
  496. case '320':
  497. constraints.video.mandatory.minWidth = 320;
  498. constraints.video.mandatory.minHeight = 240;
  499. break;
  500. default:
  501. if (isAndroid) {
  502. constraints.video.mandatory.minWidth = 320;
  503. constraints.video.mandatory.minHeight = 240;
  504. constraints.video.mandatory.maxFrameRate = 15;
  505. }
  506. break;
  507. }
  508. if (constraints.video.mandatory.minWidth)
  509. constraints.video.mandatory.maxWidth = constraints.video.mandatory.minWidth;
  510. if (constraints.video.mandatory.minHeight)
  511. constraints.video.mandatory.maxHeight = constraints.video.mandatory.minHeight;
  512. }
  513. function getConstraints(um, resolution, bandwidth, fps, desktopStream, isAndroid)
  514. {
  515. var constraints = {audio: false, video: false};
  516. if (um.indexOf('video') >= 0) {
  517. constraints.video = { mandatory: {}, optional: [] };// same behaviour as true
  518. }
  519. if (um.indexOf('audio') >= 0) {
  520. constraints.audio = { mandatory: {}, optional: []};// same behaviour as true
  521. }
  522. if (um.indexOf('screen') >= 0) {
  523. constraints.video = {
  524. mandatory: {
  525. chromeMediaSource: "screen",
  526. googLeakyBucket: true,
  527. maxWidth: window.screen.width,
  528. maxHeight: window.screen.height,
  529. maxFrameRate: 3
  530. },
  531. optional: []
  532. };
  533. }
  534. if (um.indexOf('desktop') >= 0) {
  535. constraints.video = {
  536. mandatory: {
  537. chromeMediaSource: "desktop",
  538. chromeMediaSourceId: desktopStream,
  539. googLeakyBucket: true,
  540. maxWidth: window.screen.width,
  541. maxHeight: window.screen.height,
  542. maxFrameRate: 3
  543. },
  544. optional: []
  545. };
  546. }
  547. if (constraints.audio) {
  548. // if it is good enough for hangouts...
  549. constraints.audio.optional.push(
  550. {googEchoCancellation: true},
  551. {googAutoGainControl: true},
  552. {googNoiseSupression: true},
  553. {googHighpassFilter: true},
  554. {googNoisesuppression2: true},
  555. {googEchoCancellation2: true},
  556. {googAutoGainControl2: true}
  557. );
  558. }
  559. if (constraints.video) {
  560. constraints.video.optional.push(
  561. {googNoiseReduction: false} // chrome 37 workaround for issue 3807, reenable in M38
  562. );
  563. if (um.indexOf('video') >= 0) {
  564. constraints.video.optional.push(
  565. {googLeakyBucket: true}
  566. );
  567. }
  568. }
  569. setResolutionConstraints(constraints, resolution, isAndroid);
  570. if (bandwidth) { // doesn't work currently, see webrtc issue 1846
  571. if (!constraints.video) constraints.video = {mandatory: {}, optional: []};//same behaviour as true
  572. constraints.video.optional.push({bandwidth: bandwidth});
  573. }
  574. if (fps) { // for some cameras it might be necessary to request 30fps
  575. // so they choose 30fps mjpg over 10fps yuy2
  576. if (!constraints.video) constraints.video = {mandatory: {}, optional: []};// same behaviour as true;
  577. constraints.video.mandatory.minFrameRate = fps;
  578. }
  579. return constraints;
  580. }
  581. function RTCUtils(RTCService)
  582. {
  583. this.service = RTCService;
  584. if (navigator.mozGetUserMedia) {
  585. console.log('This appears to be Firefox');
  586. var version = parseInt(navigator.userAgent.match(/Firefox\/([0-9]+)\./)[1], 10);
  587. if (version >= 22) {
  588. this.peerconnection = mozRTCPeerConnection;
  589. this.browser = RTCBrowserType.RTC_BROWSER_FIREFOX;
  590. this.getUserMedia = navigator.mozGetUserMedia.bind(navigator);
  591. this.pc_constraints = {};
  592. this.attachMediaStream = function (element, stream) {
  593. element[0].mozSrcObject = stream;
  594. element[0].play();
  595. };
  596. this.getStreamID = function (stream) {
  597. var tracks = stream.getVideoTracks();
  598. if(!tracks || tracks.length == 0)
  599. {
  600. tracks = stream.getAudioTracks();
  601. }
  602. return tracks[0].id.replace(/[\{,\}]/g,"");
  603. };
  604. this.getVideoSrc = function (element) {
  605. return element.mozSrcObject;
  606. };
  607. this.setVideoSrc = function (element, src) {
  608. element.mozSrcObject = src;
  609. };
  610. RTCSessionDescription = mozRTCSessionDescription;
  611. RTCIceCandidate = mozRTCIceCandidate;
  612. }
  613. } else if (navigator.webkitGetUserMedia) {
  614. console.log('This appears to be Chrome');
  615. this.peerconnection = webkitRTCPeerConnection;
  616. this.browser = RTCBrowserType.RTC_BROWSER_CHROME;
  617. this.getUserMedia = navigator.webkitGetUserMedia.bind(navigator);
  618. this.attachMediaStream = function (element, stream) {
  619. element.attr('src', webkitURL.createObjectURL(stream));
  620. };
  621. this.getStreamID = function (stream) {
  622. // streams from FF endpoints have the characters '{' and '}'
  623. // that make jQuery choke.
  624. return stream.id.replace(/[\{,\}]/g,"");
  625. };
  626. this.getVideoSrc = function (element) {
  627. return element.getAttribute("src");
  628. };
  629. this.setVideoSrc = function (element, src) {
  630. element.setAttribute("src", src);
  631. };
  632. // DTLS should now be enabled by default but..
  633. this.pc_constraints = {'optional': [{'DtlsSrtpKeyAgreement': 'true'}]};
  634. if (navigator.userAgent.indexOf('Android') != -1) {
  635. this.pc_constraints = {}; // disable DTLS on Android
  636. }
  637. if (!webkitMediaStream.prototype.getVideoTracks) {
  638. webkitMediaStream.prototype.getVideoTracks = function () {
  639. return this.videoTracks;
  640. };
  641. }
  642. if (!webkitMediaStream.prototype.getAudioTracks) {
  643. webkitMediaStream.prototype.getAudioTracks = function () {
  644. return this.audioTracks;
  645. };
  646. }
  647. }
  648. else
  649. {
  650. try { console.log('Browser does not appear to be WebRTC-capable'); } catch (e) { }
  651. window.location.href = 'webrtcrequired.html';
  652. return;
  653. }
  654. if (this.browser !== RTCBrowserType.RTC_BROWSER_CHROME &&
  655. config.enableFirefoxSupport !== true) {
  656. window.location.href = 'chromeonly.html';
  657. return;
  658. }
  659. }
  660. RTCUtils.prototype.getUserMediaWithConstraints = function(
  661. um, success_callback, failure_callback, resolution,bandwidth, fps,
  662. desktopStream)
  663. {
  664. // Check if we are running on Android device
  665. var isAndroid = navigator.userAgent.indexOf('Android') != -1;
  666. var constraints = getConstraints(
  667. um, resolution, bandwidth, fps, desktopStream, isAndroid);
  668. var isFF = navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
  669. try {
  670. if (config.enableSimulcast
  671. && constraints.video
  672. && constraints.video.chromeMediaSource !== 'screen'
  673. && constraints.video.chromeMediaSource !== 'desktop'
  674. && !isAndroid
  675. // We currently do not support FF, as it doesn't have multistream support.
  676. && !isFF) {
  677. simulcast.getUserMedia(constraints, function (stream) {
  678. console.log('onUserMediaSuccess');
  679. success_callback(stream);
  680. },
  681. function (error) {
  682. console.warn('Failed to get access to local media. Error ', error);
  683. if (failure_callback) {
  684. failure_callback(error);
  685. }
  686. });
  687. } else {
  688. this.getUserMedia(constraints,
  689. function (stream) {
  690. console.log('onUserMediaSuccess');
  691. success_callback(stream);
  692. },
  693. function (error) {
  694. console.warn('Failed to get access to local media. Error ',
  695. error, constraints);
  696. if (failure_callback) {
  697. failure_callback(error);
  698. }
  699. });
  700. }
  701. } catch (e) {
  702. console.error('GUM failed: ', e);
  703. if(failure_callback) {
  704. failure_callback(e);
  705. }
  706. }
  707. };
  708. /**
  709. * We ask for audio and video combined stream in order to get permissions and
  710. * not to ask twice.
  711. */
  712. RTCUtils.prototype.obtainAudioAndVideoPermissions = function() {
  713. var self = this;
  714. // Get AV
  715. var cb = function (stream) {
  716. console.log('got', stream, stream.getAudioTracks().length, stream.getVideoTracks().length);
  717. self.handleLocalStream(stream);
  718. };
  719. var self = this;
  720. this.getUserMediaWithConstraints(
  721. ['audio', 'video'],
  722. cb,
  723. function (error) {
  724. console.error('failed to obtain audio/video stream - trying audio only', error);
  725. self.getUserMediaWithConstraints(
  726. ['audio'],
  727. cb,
  728. function (error) {
  729. console.error('failed to obtain audio/video stream - stop', error);
  730. UI.messageHandler.showError("Error",
  731. "Failed to obtain permissions to use the local microphone" +
  732. "and/or camera.");
  733. }
  734. );
  735. },
  736. config.resolution || '360');
  737. }
  738. RTCUtils.prototype.handleLocalStream = function(stream)
  739. {
  740. if(window.webkitMediaStream)
  741. {
  742. var audioStream = new webkitMediaStream();
  743. var videoStream = new webkitMediaStream();
  744. var audioTracks = stream.getAudioTracks();
  745. var videoTracks = stream.getVideoTracks();
  746. for (var i = 0; i < audioTracks.length; i++) {
  747. audioStream.addTrack(audioTracks[i]);
  748. }
  749. this.service.createLocalStream(audioStream, "audio");
  750. for (i = 0; i < videoTracks.length; i++) {
  751. videoStream.addTrack(videoTracks[i]);
  752. }
  753. this.service.createLocalStream(videoStream, "video");
  754. }
  755. else
  756. {//firefox
  757. this.service.createLocalStream(stream, "stream");
  758. }
  759. };
  760. module.exports = RTCUtils;
  761. },{}],6:[function(require,module,exports){
  762. // Copyright Joyent, Inc. and other Node contributors.
  763. //
  764. // Permission is hereby granted, free of charge, to any person obtaining a
  765. // copy of this software and associated documentation files (the
  766. // "Software"), to deal in the Software without restriction, including
  767. // without limitation the rights to use, copy, modify, merge, publish,
  768. // distribute, sublicense, and/or sell copies of the Software, and to permit
  769. // persons to whom the Software is furnished to do so, subject to the
  770. // following conditions:
  771. //
  772. // The above copyright notice and this permission notice shall be included
  773. // in all copies or substantial portions of the Software.
  774. //
  775. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  776. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  777. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  778. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  779. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  780. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  781. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  782. function EventEmitter() {
  783. this._events = this._events || {};
  784. this._maxListeners = this._maxListeners || undefined;
  785. }
  786. module.exports = EventEmitter;
  787. // Backwards-compat with node 0.10.x
  788. EventEmitter.EventEmitter = EventEmitter;
  789. EventEmitter.prototype._events = undefined;
  790. EventEmitter.prototype._maxListeners = undefined;
  791. // By default EventEmitters will print a warning if more than 10 listeners are
  792. // added to it. This is a useful default which helps finding memory leaks.
  793. EventEmitter.defaultMaxListeners = 10;
  794. // Obviously not all Emitters should be limited to 10. This function allows
  795. // that to be increased. Set to zero for unlimited.
  796. EventEmitter.prototype.setMaxListeners = function(n) {
  797. if (!isNumber(n) || n < 0 || isNaN(n))
  798. throw TypeError('n must be a positive number');
  799. this._maxListeners = n;
  800. return this;
  801. };
  802. EventEmitter.prototype.emit = function(type) {
  803. var er, handler, len, args, i, listeners;
  804. if (!this._events)
  805. this._events = {};
  806. // If there is no 'error' event listener then throw.
  807. if (type === 'error') {
  808. if (!this._events.error ||
  809. (isObject(this._events.error) && !this._events.error.length)) {
  810. er = arguments[1];
  811. if (er instanceof Error) {
  812. throw er; // Unhandled 'error' event
  813. } else {
  814. throw TypeError('Uncaught, unspecified "error" event.');
  815. }
  816. return false;
  817. }
  818. }
  819. handler = this._events[type];
  820. if (isUndefined(handler))
  821. return false;
  822. if (isFunction(handler)) {
  823. switch (arguments.length) {
  824. // fast cases
  825. case 1:
  826. handler.call(this);
  827. break;
  828. case 2:
  829. handler.call(this, arguments[1]);
  830. break;
  831. case 3:
  832. handler.call(this, arguments[1], arguments[2]);
  833. break;
  834. // slower
  835. default:
  836. len = arguments.length;
  837. args = new Array(len - 1);
  838. for (i = 1; i < len; i++)
  839. args[i - 1] = arguments[i];
  840. handler.apply(this, args);
  841. }
  842. } else if (isObject(handler)) {
  843. len = arguments.length;
  844. args = new Array(len - 1);
  845. for (i = 1; i < len; i++)
  846. args[i - 1] = arguments[i];
  847. listeners = handler.slice();
  848. len = listeners.length;
  849. for (i = 0; i < len; i++)
  850. listeners[i].apply(this, args);
  851. }
  852. return true;
  853. };
  854. EventEmitter.prototype.addListener = function(type, listener) {
  855. var m;
  856. if (!isFunction(listener))
  857. throw TypeError('listener must be a function');
  858. if (!this._events)
  859. this._events = {};
  860. // To avoid recursion in the case that type === "newListener"! Before
  861. // adding it to the listeners, first emit "newListener".
  862. if (this._events.newListener)
  863. this.emit('newListener', type,
  864. isFunction(listener.listener) ?
  865. listener.listener : listener);
  866. if (!this._events[type])
  867. // Optimize the case of one listener. Don't need the extra array object.
  868. this._events[type] = listener;
  869. else if (isObject(this._events[type]))
  870. // If we've already got an array, just append.
  871. this._events[type].push(listener);
  872. else
  873. // Adding the second element, need to change to array.
  874. this._events[type] = [this._events[type], listener];
  875. // Check for listener leak
  876. if (isObject(this._events[type]) && !this._events[type].warned) {
  877. var m;
  878. if (!isUndefined(this._maxListeners)) {
  879. m = this._maxListeners;
  880. } else {
  881. m = EventEmitter.defaultMaxListeners;
  882. }
  883. if (m && m > 0 && this._events[type].length > m) {
  884. this._events[type].warned = true;
  885. console.error('(node) warning: possible EventEmitter memory ' +
  886. 'leak detected. %d listeners added. ' +
  887. 'Use emitter.setMaxListeners() to increase limit.',
  888. this._events[type].length);
  889. if (typeof console.trace === 'function') {
  890. // not supported in IE 10
  891. console.trace();
  892. }
  893. }
  894. }
  895. return this;
  896. };
  897. EventEmitter.prototype.on = EventEmitter.prototype.addListener;
  898. EventEmitter.prototype.once = function(type, listener) {
  899. if (!isFunction(listener))
  900. throw TypeError('listener must be a function');
  901. var fired = false;
  902. function g() {
  903. this.removeListener(type, g);
  904. if (!fired) {
  905. fired = true;
  906. listener.apply(this, arguments);
  907. }
  908. }
  909. g.listener = listener;
  910. this.on(type, g);
  911. return this;
  912. };
  913. // emits a 'removeListener' event iff the listener was removed
  914. EventEmitter.prototype.removeListener = function(type, listener) {
  915. var list, position, length, i;
  916. if (!isFunction(listener))
  917. throw TypeError('listener must be a function');
  918. if (!this._events || !this._events[type])
  919. return this;
  920. list = this._events[type];
  921. length = list.length;
  922. position = -1;
  923. if (list === listener ||
  924. (isFunction(list.listener) && list.listener === listener)) {
  925. delete this._events[type];
  926. if (this._events.removeListener)
  927. this.emit('removeListener', type, listener);
  928. } else if (isObject(list)) {
  929. for (i = length; i-- > 0;) {
  930. if (list[i] === listener ||
  931. (list[i].listener && list[i].listener === listener)) {
  932. position = i;
  933. break;
  934. }
  935. }
  936. if (position < 0)
  937. return this;
  938. if (list.length === 1) {
  939. list.length = 0;
  940. delete this._events[type];
  941. } else {
  942. list.splice(position, 1);
  943. }
  944. if (this._events.removeListener)
  945. this.emit('removeListener', type, listener);
  946. }
  947. return this;
  948. };
  949. EventEmitter.prototype.removeAllListeners = function(type) {
  950. var key, listeners;
  951. if (!this._events)
  952. return this;
  953. // not listening for removeListener, no need to emit
  954. if (!this._events.removeListener) {
  955. if (arguments.length === 0)
  956. this._events = {};
  957. else if (this._events[type])
  958. delete this._events[type];
  959. return this;
  960. }
  961. // emit removeListener for all listeners on all events
  962. if (arguments.length === 0) {
  963. for (key in this._events) {
  964. if (key === 'removeListener') continue;
  965. this.removeAllListeners(key);
  966. }
  967. this.removeAllListeners('removeListener');
  968. this._events = {};
  969. return this;
  970. }
  971. listeners = this._events[type];
  972. if (isFunction(listeners)) {
  973. this.removeListener(type, listeners);
  974. } else {
  975. // LIFO order
  976. while (listeners.length)
  977. this.removeListener(type, listeners[listeners.length - 1]);
  978. }
  979. delete this._events[type];
  980. return this;
  981. };
  982. EventEmitter.prototype.listeners = function(type) {
  983. var ret;
  984. if (!this._events || !this._events[type])
  985. ret = [];
  986. else if (isFunction(this._events[type]))
  987. ret = [this._events[type]];
  988. else
  989. ret = this._events[type].slice();
  990. return ret;
  991. };
  992. EventEmitter.listenerCount = function(emitter, type) {
  993. var ret;
  994. if (!emitter._events || !emitter._events[type])
  995. ret = 0;
  996. else if (isFunction(emitter._events[type]))
  997. ret = 1;
  998. else
  999. ret = emitter._events[type].length;
  1000. return ret;
  1001. };
  1002. function isFunction(arg) {
  1003. return typeof arg === 'function';
  1004. }
  1005. function isNumber(arg) {
  1006. return typeof arg === 'number';
  1007. }
  1008. function isObject(arg) {
  1009. return typeof arg === 'object' && arg !== null;
  1010. }
  1011. function isUndefined(arg) {
  1012. return arg === void 0;
  1013. }
  1014. },{}]},{},[4])(4)
  1015. });