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 37KB

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