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.

RTC.bundle.js 36KB

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