Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

RTC.bundle.js 38KB

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