You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138
  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 = VideoLayout.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. this.stream.onended = function()
  216. {
  217. self.streamEnded();
  218. };
  219. }
  220. LocalStream.prototype.streamEnded = function () {
  221. this.eventEmitter.emit(StreamEventTypes.EVENT_TYPE_LOCAL_ENDED, this);
  222. }
  223. LocalStream.prototype.getOriginalStream = function()
  224. {
  225. return this.stream;
  226. }
  227. LocalStream.prototype.isAudioStream = function () {
  228. return (this.stream.getAudioTracks() && this.stream.getAudioTracks().length > 0);
  229. }
  230. LocalStream.prototype.mute = function()
  231. {
  232. var ismuted = false;
  233. var tracks = [];
  234. if(this.type = "audio")
  235. {
  236. tracks = this.stream.getAudioTracks();
  237. }
  238. else
  239. {
  240. tracks = this.stream.getVideoTracks();
  241. }
  242. for (var idx = 0; idx < tracks.length; idx++) {
  243. ismuted = !tracks[idx].enabled;
  244. tracks[idx].enabled = !tracks[idx].enabled;
  245. }
  246. return ismuted;
  247. }
  248. LocalStream.prototype.isMuted = function () {
  249. var tracks = [];
  250. if(this.type = "audio")
  251. {
  252. tracks = this.stream.getAudioTracks();
  253. }
  254. else
  255. {
  256. tracks = this.stream.getVideoTracks();
  257. }
  258. for (var idx = 0; idx < tracks.length; idx++) {
  259. if(tracks[idx].enabled)
  260. return false;
  261. }
  262. return true;
  263. }
  264. module.exports = LocalStream;
  265. },{}],3:[function(require,module,exports){
  266. ////These lines should be uncommented when require works in app.js
  267. //var RTCBrowserType = require("../../service/RTC/RTCBrowserType.js");
  268. //var StreamEventTypes = require("../../service/RTC/StreamEventTypes.js");
  269. //var MediaStreamType = require("../../service/RTC/MediaStreamTypes");
  270. /**
  271. * Creates a MediaStream object for the given data, session id and ssrc.
  272. * It is a wrapper class for the MediaStream.
  273. *
  274. * @param data the data object from which we obtain the stream,
  275. * the peerjid, etc.
  276. * @param sid the session id
  277. * @param ssrc the ssrc corresponding to this MediaStream
  278. *
  279. * @constructor
  280. */
  281. function MediaStream(data, sid, ssrc, eventEmmiter, browser) {
  282. // XXX(gp) to minimize headaches in the future, we should build our
  283. // abstractions around tracks and not streams. ORTC is track based API.
  284. // Mozilla expects m-lines to represent media tracks.
  285. //
  286. // Practically, what I'm saying is that we should have a MediaTrack class
  287. // and not a MediaStream class.
  288. //
  289. // Also, we should be able to associate multiple SSRCs with a MediaTrack as
  290. // a track might have an associated RTX and FEC sources.
  291. this.sid = sid;
  292. this.stream = data.stream;
  293. this.peerjid = data.peerjid;
  294. this.ssrc = ssrc;
  295. this.type = (this.stream.getVideoTracks().length > 0)?
  296. MediaStreamType.VIDEO_TYPE : MediaStreamType.AUDIO_TYPE;
  297. this.muted = false;
  298. eventEmmiter.emit(StreamEventTypes.EVENT_TYPE_REMOTE_CREATED, this);
  299. if(browser == RTCBrowserType.RTC_BROWSER_FIREFOX)
  300. {
  301. if (!this.getVideoTracks)
  302. this.getVideoTracks = function () { return []; };
  303. if (!this.getAudioTracks)
  304. this.getAudioTracks = function () { return []; };
  305. }
  306. }
  307. MediaStream.prototype.getOriginalStream = function()
  308. {
  309. return this.stream;
  310. }
  311. MediaStream.prototype.setMute = function (value)
  312. {
  313. this.stream.muted = value;
  314. this.muted = value;
  315. }
  316. module.exports = MediaStream;
  317. },{}],4:[function(require,module,exports){
  318. var EventEmitter = require("events");
  319. var RTCUtils = require("./RTCUtils.js");
  320. var LocalStream = require("./LocalStream.js");
  321. var DataChannels = require("./DataChannels");
  322. var MediaStream = require("./MediaStream.js");
  323. //These lines should be uncommented when require works in app.js
  324. //var StreamEventTypes = require("../../service/RTC/StreamEventTypes.js");
  325. //var XMPPEvents = require("../service/xmpp/XMPPEvents");
  326. var eventEmitter = new EventEmitter();
  327. var RTC = {
  328. rtcUtils: null,
  329. localStreams: [],
  330. remoteStreams: {},
  331. localAudio: null,
  332. localVideo: null,
  333. addStreamListener: function (listener, eventType) {
  334. eventEmitter.on(eventType, listener);
  335. },
  336. removeStreamListener: function (listener, eventType) {
  337. if(!(eventType instanceof StreamEventTypes))
  338. throw "Illegal argument";
  339. eventEmitter.removeListener(eventType, listener);
  340. },
  341. createLocalStream: function (stream, type) {
  342. var localStream = new LocalStream(stream, type, eventEmitter);
  343. this.localStreams.push(localStream);
  344. if(type == "audio")
  345. {
  346. this.localAudio = localStream;
  347. }
  348. else
  349. {
  350. this.localVideo = localStream;
  351. }
  352. eventEmitter.emit(StreamEventTypes.EVENT_TYPE_LOCAL_CREATED,
  353. localStream);
  354. return localStream;
  355. },
  356. removeLocalStream: function (stream) {
  357. for(var i = 0; i < this.localStreams.length; i++)
  358. {
  359. if(this.localStreams[i].getOriginalStream() === stream) {
  360. delete this.localStreams[i];
  361. return;
  362. }
  363. }
  364. },
  365. createRemoteStream: function (data, sid, thessrc) {
  366. var remoteStream = new MediaStream(data, sid, thessrc, eventEmitter,
  367. this.getBrowserType());
  368. var jid = data.peerjid || connection.emuc.myroomjid;
  369. if(!this.remoteStreams[jid]) {
  370. this.remoteStreams[jid] = {};
  371. }
  372. this.remoteStreams[jid][remoteStream.type]= remoteStream;
  373. return remoteStream;
  374. },
  375. getBrowserType: function () {
  376. return this.rtcUtils.browser;
  377. },
  378. getPCConstraints: function () {
  379. return this.rtcUtils.pc_constraints;
  380. },
  381. getUserMediaWithConstraints:function(um, success_callback,
  382. failure_callback, resolution,
  383. bandwidth, fps, desktopStream)
  384. {
  385. return this.rtcUtils.getUserMediaWithConstraints(um, success_callback,
  386. failure_callback, resolution, bandwidth, fps, desktopStream);
  387. },
  388. attachMediaStream: function (element, stream) {
  389. this.rtcUtils.attachMediaStream(element, stream);
  390. },
  391. getStreamID: function (stream) {
  392. return this.rtcUtils.getStreamID(stream);
  393. },
  394. getVideoSrc: function (element) {
  395. return this.rtcUtils.getVideoSrc(element);
  396. },
  397. setVideoSrc: function (element, src) {
  398. this.rtcUtils.setVideoSrc(element, src);
  399. },
  400. dispose: function() {
  401. if (this.rtcUtils) {
  402. this.rtcUtils = null;
  403. }
  404. },
  405. stop: function () {
  406. this.dispose();
  407. },
  408. start: function () {
  409. this.rtcUtils = new RTCUtils(this);
  410. this.rtcUtils.obtainAudioAndVideoPermissions();
  411. },
  412. onConferenceCreated: function(event) {
  413. DataChannels.bindDataChannelListener(event.peerconnection);
  414. },
  415. muteRemoteVideoStream: function (jid, value) {
  416. var stream;
  417. if(this.remoteStreams[jid] &&
  418. this.remoteStreams[jid][MediaStreamType.VIDEO_TYPE])
  419. {
  420. stream = this.remoteStreams[jid][MediaStreamType.VIDEO_TYPE];
  421. }
  422. if(!stream)
  423. return false;
  424. var isMuted = (value === "true");
  425. if (isMuted != stream.muted) {
  426. stream.setMute(isMuted);
  427. return true;
  428. }
  429. return false;
  430. }
  431. };
  432. module.exports = RTC;
  433. },{"./DataChannels":1,"./LocalStream.js":2,"./MediaStream.js":3,"./RTCUtils.js":5,"events":6}],5:[function(require,module,exports){
  434. //This should be uncommented when app.js supports require
  435. //var RTCBrowserType = require("../../service/RTC/RTCBrowserType.js");
  436. var constraints = {audio: false, video: false};
  437. function setResolutionConstraints(resolution, isAndroid)
  438. {
  439. if (resolution && !constraints.video || isAndroid) {
  440. constraints.video = { mandatory: {}, optional: [] };// same behaviour as true
  441. }
  442. // see https://code.google.com/p/chromium/issues/detail?id=143631#c9 for list of supported resolutions
  443. switch (resolution) {
  444. // 16:9 first
  445. case '1080':
  446. case 'fullhd':
  447. constraints.video.mandatory.minWidth = 1920;
  448. constraints.video.mandatory.minHeight = 1080;
  449. break;
  450. case '720':
  451. case 'hd':
  452. constraints.video.mandatory.minWidth = 1280;
  453. constraints.video.mandatory.minHeight = 720;
  454. break;
  455. case '360':
  456. constraints.video.mandatory.minWidth = 640;
  457. constraints.video.mandatory.minHeight = 360;
  458. break;
  459. case '180':
  460. constraints.video.mandatory.minWidth = 320;
  461. constraints.video.mandatory.minHeight = 180;
  462. break;
  463. // 4:3
  464. case '960':
  465. constraints.video.mandatory.minWidth = 960;
  466. constraints.video.mandatory.minHeight = 720;
  467. break;
  468. case '640':
  469. case 'vga':
  470. constraints.video.mandatory.minWidth = 640;
  471. constraints.video.mandatory.minHeight = 480;
  472. break;
  473. case '320':
  474. constraints.video.mandatory.minWidth = 320;
  475. constraints.video.mandatory.minHeight = 240;
  476. break;
  477. default:
  478. if (isAndroid) {
  479. constraints.video.mandatory.minWidth = 320;
  480. constraints.video.mandatory.minHeight = 240;
  481. constraints.video.mandatory.maxFrameRate = 15;
  482. }
  483. break;
  484. }
  485. if (constraints.video.mandatory.minWidth)
  486. constraints.video.mandatory.maxWidth = constraints.video.mandatory.minWidth;
  487. if (constraints.video.mandatory.minHeight)
  488. constraints.video.mandatory.maxHeight = constraints.video.mandatory.minHeight;
  489. }
  490. function setConstraints(um, resolution, bandwidth, fps, desktopStream, isAndroid)
  491. {
  492. if (um.indexOf('video') >= 0) {
  493. constraints.video = { mandatory: {}, optional: [] };// same behaviour as true
  494. }
  495. if (um.indexOf('audio') >= 0) {
  496. constraints.audio = { mandatory: {}, optional: []};// same behaviour as true
  497. }
  498. if (um.indexOf('screen') >= 0) {
  499. constraints.video = {
  500. mandatory: {
  501. chromeMediaSource: "screen",
  502. googLeakyBucket: true,
  503. maxWidth: window.screen.width,
  504. maxHeight: window.screen.height,
  505. maxFrameRate: 3
  506. },
  507. optional: []
  508. };
  509. }
  510. if (um.indexOf('desktop') >= 0) {
  511. constraints.video = {
  512. mandatory: {
  513. chromeMediaSource: "desktop",
  514. chromeMediaSourceId: desktopStream,
  515. googLeakyBucket: true,
  516. maxWidth: window.screen.width,
  517. maxHeight: window.screen.height,
  518. maxFrameRate: 3
  519. },
  520. optional: []
  521. };
  522. }
  523. if (constraints.audio) {
  524. // if it is good enough for hangouts...
  525. constraints.audio.optional.push(
  526. {googEchoCancellation: true},
  527. {googAutoGainControl: true},
  528. {googNoiseSupression: true},
  529. {googHighpassFilter: true},
  530. {googNoisesuppression2: true},
  531. {googEchoCancellation2: true},
  532. {googAutoGainControl2: true}
  533. );
  534. }
  535. if (constraints.video) {
  536. constraints.video.optional.push(
  537. {googNoiseReduction: false} // chrome 37 workaround for issue 3807, reenable in M38
  538. );
  539. if (um.indexOf('video') >= 0) {
  540. constraints.video.optional.push(
  541. {googLeakyBucket: true}
  542. );
  543. }
  544. }
  545. setResolutionConstraints(resolution, isAndroid);
  546. if (bandwidth) { // doesn't work currently, see webrtc issue 1846
  547. if (!constraints.video) constraints.video = {mandatory: {}, optional: []};//same behaviour as true
  548. constraints.video.optional.push({bandwidth: bandwidth});
  549. }
  550. if (fps) { // for some cameras it might be necessary to request 30fps
  551. // so they choose 30fps mjpg over 10fps yuy2
  552. if (!constraints.video) constraints.video = {mandatory: {}, optional: []};// same behaviour as true;
  553. constraints.video.mandatory.minFrameRate = fps;
  554. }
  555. }
  556. function RTCUtils(RTCService)
  557. {
  558. this.service = RTCService;
  559. if (navigator.mozGetUserMedia) {
  560. console.log('This appears to be Firefox');
  561. var version = parseInt(navigator.userAgent.match(/Firefox\/([0-9]+)\./)[1], 10);
  562. if (version >= 22) {
  563. this.peerconnection = mozRTCPeerConnection;
  564. this.browser = RTCBrowserType.RTC_BROWSER_FIREFOX;
  565. this.getUserMedia = navigator.mozGetUserMedia.bind(navigator);
  566. this.pc_constraints = {};
  567. this.attachMediaStream = function (element, stream) {
  568. element[0].mozSrcObject = stream;
  569. element[0].play();
  570. };
  571. this.getStreamID = function (stream) {
  572. var tracks = stream.getVideoTracks();
  573. if(!tracks || tracks.length == 0)
  574. {
  575. tracks = stream.getAudioTracks();
  576. }
  577. return tracks[0].id.replace(/[\{,\}]/g,"");
  578. };
  579. this.getVideoSrc = function (element) {
  580. return element.mozSrcObject;
  581. };
  582. this.setVideoSrc = function (element, src) {
  583. element.mozSrcObject = src;
  584. };
  585. RTCSessionDescription = mozRTCSessionDescription;
  586. RTCIceCandidate = mozRTCIceCandidate;
  587. }
  588. } else if (navigator.webkitGetUserMedia) {
  589. console.log('This appears to be Chrome');
  590. this.peerconnection = webkitRTCPeerConnection;
  591. this.browser = RTCBrowserType.RTC_BROWSER_CHROME;
  592. this.getUserMedia = navigator.webkitGetUserMedia.bind(navigator);
  593. this.attachMediaStream = function (element, stream) {
  594. element.attr('src', webkitURL.createObjectURL(stream));
  595. };
  596. this.getStreamID = function (stream) {
  597. // streams from FF endpoints have the characters '{' and '}'
  598. // that make jQuery choke.
  599. return stream.id.replace(/[\{,\}]/g,"");
  600. };
  601. this.getVideoSrc = function (element) {
  602. return element.getAttribute("src");
  603. };
  604. this.setVideoSrc = function (element, src) {
  605. element.setAttribute("src", src);
  606. };
  607. // DTLS should now be enabled by default but..
  608. this.pc_constraints = {'optional': [{'DtlsSrtpKeyAgreement': 'true'}]};
  609. if (navigator.userAgent.indexOf('Android') != -1) {
  610. this.pc_constraints = {}; // disable DTLS on Android
  611. }
  612. if (!webkitMediaStream.prototype.getVideoTracks) {
  613. webkitMediaStream.prototype.getVideoTracks = function () {
  614. return this.videoTracks;
  615. };
  616. }
  617. if (!webkitMediaStream.prototype.getAudioTracks) {
  618. webkitMediaStream.prototype.getAudioTracks = function () {
  619. return this.audioTracks;
  620. };
  621. }
  622. }
  623. else
  624. {
  625. try { console.log('Browser does not appear to be WebRTC-capable'); } catch (e) { }
  626. window.location.href = 'webrtcrequired.html';
  627. return;
  628. }
  629. if (this.browser !== RTCBrowserType.RTC_BROWSER_CHROME &&
  630. config.enableFirefoxSupport !== true) {
  631. window.location.href = 'chromeonly.html';
  632. return;
  633. }
  634. }
  635. RTCUtils.prototype.getUserMediaWithConstraints = function(
  636. um, success_callback, failure_callback, resolution,bandwidth, fps,
  637. desktopStream)
  638. {
  639. // Check if we are running on Android device
  640. var isAndroid = navigator.userAgent.indexOf('Android') != -1;
  641. setConstraints(um, resolution, bandwidth, fps, desktopStream, isAndroid);
  642. var isFF = navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
  643. try {
  644. if (config.enableSimulcast
  645. && constraints.video
  646. && constraints.video.chromeMediaSource !== 'screen'
  647. && constraints.video.chromeMediaSource !== 'desktop'
  648. && !isAndroid
  649. // We currently do not support FF, as it doesn't have multistream support.
  650. && !isFF) {
  651. simulcast.getUserMedia(constraints, function (stream) {
  652. console.log('onUserMediaSuccess');
  653. success_callback(stream);
  654. },
  655. function (error) {
  656. console.warn('Failed to get access to local media. Error ', error);
  657. if (failure_callback) {
  658. failure_callback(error);
  659. }
  660. });
  661. } else {
  662. this.getUserMedia(constraints,
  663. function (stream) {
  664. console.log('onUserMediaSuccess');
  665. success_callback(stream);
  666. },
  667. function (error) {
  668. console.warn('Failed to get access to local media. Error ', error);
  669. if (failure_callback) {
  670. failure_callback(error);
  671. }
  672. });
  673. }
  674. } catch (e) {
  675. console.error('GUM failed: ', e);
  676. if(failure_callback) {
  677. failure_callback(e);
  678. }
  679. }
  680. };
  681. /**
  682. * We ask for audio and video combined stream in order to get permissions and
  683. * not to ask twice.
  684. */
  685. RTCUtils.prototype.obtainAudioAndVideoPermissions = function() {
  686. var self = this;
  687. // Get AV
  688. var cb = function (stream) {
  689. console.log('got', stream, stream.getAudioTracks().length, stream.getVideoTracks().length);
  690. self.handleLocalStream(stream);
  691. trackUsage('localMedia', {
  692. audio: stream.getAudioTracks().length,
  693. video: stream.getVideoTracks().length
  694. });
  695. };
  696. var self = this;
  697. this.getUserMediaWithConstraints(
  698. ['audio', 'video'],
  699. cb,
  700. function (error) {
  701. console.error('failed to obtain audio/video stream - trying audio only', error);
  702. self.getUserMediaWithConstraints(
  703. ['audio'],
  704. cb,
  705. function (error) {
  706. console.error('failed to obtain audio/video stream - stop', error);
  707. trackUsage('localMediaError', {
  708. media: error.media || 'video',
  709. name : error.name
  710. });
  711. messageHandler.showError("Error",
  712. "Failed to obtain permissions to use the local microphone" +
  713. "and/or camera.");
  714. }
  715. );
  716. },
  717. config.resolution || '360');
  718. }
  719. RTCUtils.prototype.handleLocalStream = function(stream)
  720. {
  721. if(window.webkitMediaStream)
  722. {
  723. var audioStream = new webkitMediaStream();
  724. var videoStream = new webkitMediaStream();
  725. var audioTracks = stream.getAudioTracks();
  726. var videoTracks = stream.getVideoTracks();
  727. for (var i = 0; i < audioTracks.length; i++) {
  728. audioStream.addTrack(audioTracks[i]);
  729. }
  730. this.service.createLocalStream(audioStream, "audio");
  731. for (i = 0; i < videoTracks.length; i++) {
  732. videoStream.addTrack(videoTracks[i]);
  733. }
  734. this.service.createLocalStream(videoStream, "video");
  735. }
  736. else
  737. {//firefox
  738. this.service.createLocalStream(stream, "stream");
  739. }
  740. };
  741. module.exports = RTCUtils;
  742. },{}],6:[function(require,module,exports){
  743. // Copyright Joyent, Inc. and other Node contributors.
  744. //
  745. // Permission is hereby granted, free of charge, to any person obtaining a
  746. // copy of this software and associated documentation files (the
  747. // "Software"), to deal in the Software without restriction, including
  748. // without limitation the rights to use, copy, modify, merge, publish,
  749. // distribute, sublicense, and/or sell copies of the Software, and to permit
  750. // persons to whom the Software is furnished to do so, subject to the
  751. // following conditions:
  752. //
  753. // The above copyright notice and this permission notice shall be included
  754. // in all copies or substantial portions of the Software.
  755. //
  756. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  757. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  758. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  759. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  760. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  761. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  762. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  763. function EventEmitter() {
  764. this._events = this._events || {};
  765. this._maxListeners = this._maxListeners || undefined;
  766. }
  767. module.exports = EventEmitter;
  768. // Backwards-compat with node 0.10.x
  769. EventEmitter.EventEmitter = EventEmitter;
  770. EventEmitter.prototype._events = undefined;
  771. EventEmitter.prototype._maxListeners = undefined;
  772. // By default EventEmitters will print a warning if more than 10 listeners are
  773. // added to it. This is a useful default which helps finding memory leaks.
  774. EventEmitter.defaultMaxListeners = 10;
  775. // Obviously not all Emitters should be limited to 10. This function allows
  776. // that to be increased. Set to zero for unlimited.
  777. EventEmitter.prototype.setMaxListeners = function(n) {
  778. if (!isNumber(n) || n < 0 || isNaN(n))
  779. throw TypeError('n must be a positive number');
  780. this._maxListeners = n;
  781. return this;
  782. };
  783. EventEmitter.prototype.emit = function(type) {
  784. var er, handler, len, args, i, listeners;
  785. if (!this._events)
  786. this._events = {};
  787. // If there is no 'error' event listener then throw.
  788. if (type === 'error') {
  789. if (!this._events.error ||
  790. (isObject(this._events.error) && !this._events.error.length)) {
  791. er = arguments[1];
  792. if (er instanceof Error) {
  793. throw er; // Unhandled 'error' event
  794. } else {
  795. throw TypeError('Uncaught, unspecified "error" event.');
  796. }
  797. return false;
  798. }
  799. }
  800. handler = this._events[type];
  801. if (isUndefined(handler))
  802. return false;
  803. if (isFunction(handler)) {
  804. switch (arguments.length) {
  805. // fast cases
  806. case 1:
  807. handler.call(this);
  808. break;
  809. case 2:
  810. handler.call(this, arguments[1]);
  811. break;
  812. case 3:
  813. handler.call(this, arguments[1], arguments[2]);
  814. break;
  815. // slower
  816. default:
  817. len = arguments.length;
  818. args = new Array(len - 1);
  819. for (i = 1; i < len; i++)
  820. args[i - 1] = arguments[i];
  821. handler.apply(this, args);
  822. }
  823. } else if (isObject(handler)) {
  824. len = arguments.length;
  825. args = new Array(len - 1);
  826. for (i = 1; i < len; i++)
  827. args[i - 1] = arguments[i];
  828. listeners = handler.slice();
  829. len = listeners.length;
  830. for (i = 0; i < len; i++)
  831. listeners[i].apply(this, args);
  832. }
  833. return true;
  834. };
  835. EventEmitter.prototype.addListener = function(type, listener) {
  836. var m;
  837. if (!isFunction(listener))
  838. throw TypeError('listener must be a function');
  839. if (!this._events)
  840. this._events = {};
  841. // To avoid recursion in the case that type === "newListener"! Before
  842. // adding it to the listeners, first emit "newListener".
  843. if (this._events.newListener)
  844. this.emit('newListener', type,
  845. isFunction(listener.listener) ?
  846. listener.listener : listener);
  847. if (!this._events[type])
  848. // Optimize the case of one listener. Don't need the extra array object.
  849. this._events[type] = listener;
  850. else if (isObject(this._events[type]))
  851. // If we've already got an array, just append.
  852. this._events[type].push(listener);
  853. else
  854. // Adding the second element, need to change to array.
  855. this._events[type] = [this._events[type], listener];
  856. // Check for listener leak
  857. if (isObject(this._events[type]) && !this._events[type].warned) {
  858. var m;
  859. if (!isUndefined(this._maxListeners)) {
  860. m = this._maxListeners;
  861. } else {
  862. m = EventEmitter.defaultMaxListeners;
  863. }
  864. if (m && m > 0 && this._events[type].length > m) {
  865. this._events[type].warned = true;
  866. console.error('(node) warning: possible EventEmitter memory ' +
  867. 'leak detected. %d listeners added. ' +
  868. 'Use emitter.setMaxListeners() to increase limit.',
  869. this._events[type].length);
  870. if (typeof console.trace === 'function') {
  871. // not supported in IE 10
  872. console.trace();
  873. }
  874. }
  875. }
  876. return this;
  877. };
  878. EventEmitter.prototype.on = EventEmitter.prototype.addListener;
  879. EventEmitter.prototype.once = function(type, listener) {
  880. if (!isFunction(listener))
  881. throw TypeError('listener must be a function');
  882. var fired = false;
  883. function g() {
  884. this.removeListener(type, g);
  885. if (!fired) {
  886. fired = true;
  887. listener.apply(this, arguments);
  888. }
  889. }
  890. g.listener = listener;
  891. this.on(type, g);
  892. return this;
  893. };
  894. // emits a 'removeListener' event iff the listener was removed
  895. EventEmitter.prototype.removeListener = function(type, listener) {
  896. var list, position, length, i;
  897. if (!isFunction(listener))
  898. throw TypeError('listener must be a function');
  899. if (!this._events || !this._events[type])
  900. return this;
  901. list = this._events[type];
  902. length = list.length;
  903. position = -1;
  904. if (list === listener ||
  905. (isFunction(list.listener) && list.listener === listener)) {
  906. delete this._events[type];
  907. if (this._events.removeListener)
  908. this.emit('removeListener', type, listener);
  909. } else if (isObject(list)) {
  910. for (i = length; i-- > 0;) {
  911. if (list[i] === listener ||
  912. (list[i].listener && list[i].listener === listener)) {
  913. position = i;
  914. break;
  915. }
  916. }
  917. if (position < 0)
  918. return this;
  919. if (list.length === 1) {
  920. list.length = 0;
  921. delete this._events[type];
  922. } else {
  923. list.splice(position, 1);
  924. }
  925. if (this._events.removeListener)
  926. this.emit('removeListener', type, listener);
  927. }
  928. return this;
  929. };
  930. EventEmitter.prototype.removeAllListeners = function(type) {
  931. var key, listeners;
  932. if (!this._events)
  933. return this;
  934. // not listening for removeListener, no need to emit
  935. if (!this._events.removeListener) {
  936. if (arguments.length === 0)
  937. this._events = {};
  938. else if (this._events[type])
  939. delete this._events[type];
  940. return this;
  941. }
  942. // emit removeListener for all listeners on all events
  943. if (arguments.length === 0) {
  944. for (key in this._events) {
  945. if (key === 'removeListener') continue;
  946. this.removeAllListeners(key);
  947. }
  948. this.removeAllListeners('removeListener');
  949. this._events = {};
  950. return this;
  951. }
  952. listeners = this._events[type];
  953. if (isFunction(listeners)) {
  954. this.removeListener(type, listeners);
  955. } else {
  956. // LIFO order
  957. while (listeners.length)
  958. this.removeListener(type, listeners[listeners.length - 1]);
  959. }
  960. delete this._events[type];
  961. return this;
  962. };
  963. EventEmitter.prototype.listeners = function(type) {
  964. var ret;
  965. if (!this._events || !this._events[type])
  966. ret = [];
  967. else if (isFunction(this._events[type]))
  968. ret = [this._events[type]];
  969. else
  970. ret = this._events[type].slice();
  971. return ret;
  972. };
  973. EventEmitter.listenerCount = function(emitter, type) {
  974. var ret;
  975. if (!emitter._events || !emitter._events[type])
  976. ret = 0;
  977. else if (isFunction(emitter._events[type]))
  978. ret = 1;
  979. else
  980. ret = emitter._events[type].length;
  981. return ret;
  982. };
  983. function isFunction(arg) {
  984. return typeof arg === 'function';
  985. }
  986. function isNumber(arg) {
  987. return typeof arg === 'number';
  988. }
  989. function isObject(arg) {
  990. return typeof arg === 'object' && arg !== null;
  991. }
  992. function isUndefined(arg) {
  993. return arg === void 0;
  994. }
  995. },{}]},{},[4])(4)
  996. });