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.

conference.js 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702
  1. /* global $, APP, JitsiMeetJS, config, interfaceConfig */
  2. import {openConnection} from './connection';
  3. //FIXME:
  4. import createRoomLocker from './modules/UI/authentication/RoomLocker';
  5. //FIXME:
  6. import AuthHandler from './modules/UI/authentication/AuthHandler';
  7. import CQEvents from './service/connectionquality/CQEvents';
  8. import UIEvents from './service/UI/UIEvents';
  9. import DSEvents from './service/desktopsharing/DesktopSharingEventTypes';
  10. const ConnectionEvents = JitsiMeetJS.events.connection;
  11. const ConnectionErrors = JitsiMeetJS.errors.connection;
  12. const ConferenceEvents = JitsiMeetJS.events.conference;
  13. const ConferenceErrors = JitsiMeetJS.errors.conference;
  14. let room, connection, localTracks, localAudio, localVideo, roomLocker;
  15. const Commands = {
  16. CONNECTION_QUALITY: "stats",
  17. EMAIL: "email",
  18. VIDEO_TYPE: "videoType",
  19. ETHERPAD: "etherpad",
  20. PREZI: "prezi",
  21. STOP_PREZI: "stop-prezi"
  22. };
  23. function connect() {
  24. return openConnection({retry: true}).catch(function (err) {
  25. if (err === ConnectionErrors.PASSWORD_REQUIRED) {
  26. APP.UI.notifyTokenAuthFailed();
  27. } else {
  28. APP.UI.notifyConnectionFailed(err);
  29. }
  30. throw err;
  31. });
  32. }
  33. const addTrack = (track) => {
  34. room.addTrack(track);
  35. if (track.isAudioTrack()) {
  36. return;
  37. }
  38. room.removeCommand(Commands.VIDEO_TYPE);
  39. room.sendCommand(Commands.VIDEO_TYPE, {
  40. value: track.videoType,
  41. attributes: {
  42. xmlns: 'http://jitsi.org/jitmeet/video'
  43. }
  44. });
  45. };
  46. // share email with other users
  47. const sendEmail = (email) => {
  48. room.sendCommand(Commands.EMAIL, {
  49. value: email,
  50. attributes: {
  51. id: room.myUserId()
  52. }
  53. });
  54. };
  55. const unload = () => {
  56. room.leave();
  57. connection.disconnect();
  58. };
  59. const getDisplayName = (id) => {
  60. if (APP.conference.isLocalId(id)) {
  61. return APP.settings.getDisplayName();
  62. }
  63. let participant = room.getParticipantById(id);
  64. if (participant && participant.getDisplayName()) {
  65. return participant.getDisplayName();
  66. }
  67. };
  68. class ConferenceConnector {
  69. constructor(resolve, reject) {
  70. this._resolve = resolve;
  71. this._reject = reject;
  72. this.reconnectTimeout = null;
  73. room.on(ConferenceEvents.CONFERENCE_JOINED,
  74. this._handleConferenceJoined.bind(this));
  75. room.on(ConferenceEvents.CONFERENCE_FAILED,
  76. this._onConferenceFailed.bind(this));
  77. }
  78. _handleConferenceFailed(err, msg) {
  79. this._unsubscribe();
  80. this._reject(err);
  81. }
  82. _onConferenceFailed(err, msg = '') {
  83. console.error('CONFERENCE FAILED:', err, msg);
  84. switch (err) {
  85. // room is locked by the password
  86. case ConferenceErrors.PASSWORD_REQUIRED:
  87. APP.UI.markRoomLocked(true);
  88. roomLocker.requirePassword().then(function () {
  89. room.join(roomLocker.password);
  90. });
  91. break;
  92. case ConferenceErrors.CONNECTION_ERROR:
  93. APP.UI.notifyConnectionFailed(msg);
  94. break;
  95. case ConferenceErrors.VIDEOBRIDGE_NOT_AVAILABLE:
  96. APP.UI.notifyBridgeDown();
  97. break;
  98. // not enough rights to create conference
  99. case ConferenceErrors.AUTHENTICATION_REQUIRED:
  100. // schedule reconnect to check if someone else created the room
  101. this.reconnectTimeout = setTimeout(function () {
  102. room.join();
  103. }, 5000);
  104. // notify user that auth is required
  105. AuthHandler.requireAuth(APP.conference.roomName);
  106. break;
  107. default:
  108. this._handleConferenceFailed(err, msg);
  109. }
  110. }
  111. _unsubscribe() {
  112. room.off(
  113. ConferenceEvents.CONFERENCE_JOINED, this._handleConferenceJoined);
  114. room.off(
  115. ConferenceEvents.CONFERENCE_FAILED, this._onConferenceFailed);
  116. if (this.reconnectTimeout !== null) {
  117. clearTimeout(this.reconnectTimeout);
  118. }
  119. AuthHandler.closeAuth();
  120. }
  121. _handleConferenceJoined() {
  122. this._unsubscribe();
  123. this._resolve();
  124. }
  125. connect() {
  126. room.join();
  127. }
  128. }
  129. export default {
  130. localId: undefined,
  131. isModerator: false,
  132. audioMuted: false,
  133. videoMuted: false,
  134. init(options) {
  135. this.roomName = options.roomName;
  136. JitsiMeetJS.setLogLevel(JitsiMeetJS.logLevels.TRACE);
  137. return JitsiMeetJS.init(config).then(() => {
  138. return Promise.all([
  139. this.createLocalTracks('audio', 'video').catch(
  140. () => {return [];}),
  141. connect()
  142. ]);
  143. }).then(([tracks, con]) => {
  144. console.log('initialized with %s local tracks', tracks.length);
  145. localTracks = tracks;
  146. connection = con;
  147. this._createRoom();
  148. $(window).bind('beforeunload', unload );
  149. $(window).bind('unload', unload );
  150. return new Promise((resolve, reject) => {
  151. (new ConferenceConnector(resolve, reject)).connect();
  152. });
  153. });
  154. },
  155. createLocalTracks (...devices) {
  156. return JitsiMeetJS.createLocalTracks({
  157. // copy array to avoid mutations inside library
  158. devices: devices.slice(0),
  159. resolution: config.resolution
  160. }).catch(function (err) {
  161. console.error('failed to create local tracks', ...devices, err);
  162. APP.statistics.onGetUserMediaFailed(err);
  163. return Promise.reject(err);
  164. });
  165. },
  166. isLocalId (id) {
  167. return this.localId === id;
  168. },
  169. /**
  170. * Simulates toolbar button click for audio mute. Used by shortcuts and API.
  171. * @param mute true for mute and false for unmute.
  172. */
  173. muteAudio (mute) {
  174. //FIXME: Maybe we should create method for that in the UI instead of
  175. //accessing directly eventEmitter????
  176. APP.UI.eventEmitter.emit(UIEvents.AUDIO_MUTED, mute);
  177. },
  178. /**
  179. * Simulates toolbar button click for audio mute. Used by shortcuts and API.
  180. */
  181. toggleAudioMuted () {
  182. this.muteAudio(!this.audioMuted);
  183. },
  184. /**
  185. * Simulates toolbar button click for video mute. Used by shortcuts and API.
  186. * @param mute true for mute and false for unmute.
  187. */
  188. muteVideo (mute) {
  189. //FIXME: Maybe we should create method for that in the UI instead of
  190. //accessing directly eventEmitter????
  191. APP.UI.eventEmitter.emit(UIEvents.VIDEO_MUTED, mute);
  192. },
  193. /**
  194. * Simulates toolbar button click for video mute. Used by shortcuts and API.
  195. */
  196. toggleVideoMuted () {
  197. this.muteVideo(!this.videoMuted);
  198. },
  199. listMembers () {
  200. return room.getParticipants();
  201. },
  202. listMembersIds () {
  203. return room.getParticipants().map(p => p.getId());
  204. },
  205. sipGatewayEnabled () {
  206. return room.isSIPCallingSupported();
  207. },
  208. get membersCount () {
  209. return room.getParticipants().length + 1;
  210. },
  211. get startAudioMuted () {
  212. return room && room.getStartMutedPolicy().audio;
  213. },
  214. get startVideoMuted () {
  215. return room && room.getStartMutedPolicy().video;
  216. },
  217. /**
  218. * Returns true if the callstats integration is enabled, otherwise returns
  219. * false.
  220. *
  221. * @returns true if the callstats integration is enabled, otherwise returns
  222. * false.
  223. */
  224. isCallstatsEnabled () {
  225. return room.isCallstatsEnabled();
  226. },
  227. /**
  228. * Sends the given feedback through CallStats if enabled.
  229. *
  230. * @param overallFeedback an integer between 1 and 5 indicating the
  231. * user feedback
  232. * @param detailedFeedback detailed feedback from the user. Not yet used
  233. */
  234. sendFeedback (overallFeedback, detailedFeedback) {
  235. return room.sendFeedback (overallFeedback, detailedFeedback);
  236. },
  237. // used by torture currently
  238. isJoined () {
  239. return this._room
  240. && this._room.isJoined();
  241. },
  242. getConnectionState () {
  243. return this._room
  244. && this._room.getConnectionState();
  245. },
  246. getMyUserId () {
  247. return this._room
  248. && this._room.myUserId();
  249. },
  250. /**
  251. * Will be filled with values only when config.debug is enabled.
  252. * Its used by torture to check audio levels.
  253. */
  254. audioLevelsMap: {},
  255. getPeerSSRCAudioLevel (id) {
  256. return this.audioLevelsMap[id];
  257. },
  258. /**
  259. * Will check for number of remote particiapnts that have at least one
  260. * remote track.
  261. * @return boolean whether we have enough participants with remote streams
  262. */
  263. checkEnoughParticipants (number) {
  264. var participants = this._room.getParticipants();
  265. var foundParticipants = 0;
  266. for (var i = 0; i < participants.length; i += 1) {
  267. if (participants[i].getTracks().length > 0) {
  268. foundParticipants++;
  269. }
  270. }
  271. return foundParticipants >= number;
  272. },
  273. // end used by torture
  274. getLogs () {
  275. return room.getLogs();
  276. },
  277. _createRoom () {
  278. room = connection.initJitsiConference(APP.conference.roomName,
  279. this._getConferenceOptions());
  280. this.localId = room.myUserId();
  281. localTracks.forEach((track) => {
  282. if(track.isAudioTrack()) {
  283. localAudio = track;
  284. }
  285. else if (track.isVideoTrack()) {
  286. localVideo = track;
  287. }
  288. addTrack(track);
  289. APP.UI.addLocalStream(track);
  290. });
  291. roomLocker = createRoomLocker(room);
  292. this._room = room; // FIXME do not use this
  293. this.localId = room.myUserId();
  294. let email = APP.settings.getEmail();
  295. email && sendEmail(email);
  296. let nick = APP.settings.getDisplayName();
  297. (config.useNicks && !nick) && (() => {
  298. nick = APP.UI.askForNickname();
  299. APP.settings.setDisplayName(nick);
  300. })();
  301. nick && room.setDisplayName(nick);
  302. this._setupListeners();
  303. },
  304. _getConferenceOptions() {
  305. let options = config;
  306. if(config.enableRecording) {
  307. options.recordingType = (config.hosts &&
  308. (typeof config.hosts.jirecon != "undefined"))?
  309. "jirecon" : "colibri";
  310. }
  311. return options;
  312. },
  313. _setupListeners () {
  314. // add local streams when joined to the conference
  315. room.on(ConferenceEvents.CONFERENCE_JOINED, () => {
  316. APP.UI.updateAuthInfo(room.isAuthEnabled(), room.getAuthLogin());
  317. APP.UI.mucJoined();
  318. });
  319. room.on(ConferenceEvents.USER_JOINED, (id, user) => {
  320. console.log('USER %s connnected', id, user);
  321. // FIXME email???
  322. APP.UI.addUser(id, user.getDisplayName());
  323. // chek the roles for the new user and reflect them
  324. APP.UI.updateUserRole(user);
  325. });
  326. room.on(ConferenceEvents.USER_LEFT, (id, user) => {
  327. console.log('USER %s LEFT', id, user);
  328. APP.UI.removeUser(id, user.getDisplayName());
  329. APP.UI.stopPrezi(id);
  330. });
  331. room.on(ConferenceEvents.USER_ROLE_CHANGED, (id, role) => {
  332. if (this.isLocalId(id)) {
  333. console.info(`My role changed, new role: ${role}`);
  334. this.isModerator = room.isModerator();
  335. APP.UI.updateLocalRole(room.isModerator());
  336. } else {
  337. let user = room.getParticipantById(id);
  338. if (user) {
  339. APP.UI.updateUserRole(user);
  340. }
  341. }
  342. });
  343. room.on(ConferenceEvents.TRACK_ADDED, (track) => {
  344. if(!track || track.isLocal())
  345. return;
  346. APP.UI.addRemoteStream(track);
  347. });
  348. room.on(ConferenceEvents.TRACK_REMOVED, (track) => {
  349. // FIXME handle
  350. });
  351. room.on(ConferenceEvents.TRACK_MUTE_CHANGED, (track) => {
  352. if(!track)
  353. return;
  354. const handler = (track.getType() === "audio")?
  355. APP.UI.setAudioMuted : APP.UI.setVideoMuted;
  356. let id;
  357. const mute = track.isMuted();
  358. if(track.isLocal()){
  359. id = this.localId;
  360. if(track.getType() === "audio") {
  361. this.audioMuted = mute;
  362. } else {
  363. this.videoMuted = mute;
  364. }
  365. } else {
  366. id = track.getParticipantId();
  367. }
  368. handler(id , mute);
  369. });
  370. room.on(ConferenceEvents.TRACK_AUDIO_LEVEL_CHANGED, (id, lvl) => {
  371. if(this.isLocalId(id) && localAudio.isMuted()) {
  372. lvl = 0;
  373. }
  374. if(config.debug)
  375. this.audioLevelsMap[id] = lvl;
  376. APP.UI.setAudioLevel(id, lvl);
  377. });
  378. room.on(ConferenceEvents.IN_LAST_N_CHANGED, (inLastN) => {
  379. //FIXME
  380. if (config.muteLocalVideoIfNotInLastN) {
  381. // TODO mute or unmute if required
  382. // mark video on UI
  383. // APP.UI.markVideoMuted(true/false);
  384. }
  385. });
  386. room.on(ConferenceEvents.LAST_N_ENDPOINTS_CHANGED, (ids) => {
  387. APP.UI.handleLastNEndpoints(ids);
  388. });
  389. room.on(ConferenceEvents.DOMINANT_SPEAKER_CHANGED, (id) => {
  390. APP.UI.markDominantSpeaker(id);
  391. });
  392. if (!interfaceConfig.filmStripOnly) {
  393. room.on(ConferenceEvents.CONNECTION_INTERRUPTED, () => {
  394. APP.UI.markVideoInterrupted(true);
  395. });
  396. room.on(ConferenceEvents.CONNECTION_RESTORED, () => {
  397. APP.UI.markVideoInterrupted(false);
  398. });
  399. room.on(ConferenceEvents.MESSAGE_RECEIVED, (id, text, ts) => {
  400. APP.UI.addMessage(id, getDisplayName(id), text, ts);
  401. });
  402. }
  403. room.on(ConferenceEvents.DISPLAY_NAME_CHANGED, (id, displayName) => {
  404. APP.UI.changeDisplayName(id, displayName);
  405. });
  406. room.on(ConferenceEvents.RECORDING_STATE_CHANGED, (status, error) => {
  407. if(status == "error") {
  408. console.error(error);
  409. return;
  410. }
  411. APP.UI.updateRecordingState(status);
  412. });
  413. room.on(ConferenceEvents.KICKED, () => {
  414. APP.UI.notifyKicked();
  415. // FIXME close
  416. });
  417. room.on(ConferenceEvents.DTMF_SUPPORT_CHANGED, (isDTMFSupported) => {
  418. APP.UI.updateDTMFSupport(isDTMFSupported);
  419. });
  420. APP.UI.addListener(UIEvents.ROOM_LOCK_CLICKED, () => {
  421. if (room.isModerator()) {
  422. let promise = roomLocker.isLocked
  423. ? roomLocker.askToUnlock()
  424. : roomLocker.askToLock();
  425. promise.then(() => {
  426. APP.UI.markRoomLocked(roomLocker.isLocked);
  427. });
  428. } else {
  429. roomLocker.notifyModeratorRequired();
  430. }
  431. });
  432. APP.UI.addListener(UIEvents.AUDIO_MUTED, (muted) => {
  433. (muted)? localAudio.mute() : localAudio.unmute();
  434. });
  435. APP.UI.addListener(UIEvents.VIDEO_MUTED, (muted) => {
  436. (muted)? localVideo.mute() : localVideo.unmute();
  437. });
  438. if (!interfaceConfig.filmStripOnly) {
  439. APP.UI.addListener(UIEvents.MESSAGE_CREATED, (message) => {
  440. room.sendTextMessage(message);
  441. });
  442. }
  443. APP.connectionquality.addListener(
  444. CQEvents.LOCALSTATS_UPDATED,
  445. (percent, stats) => {
  446. APP.UI.updateLocalStats(percent, stats);
  447. // send local stats to other users
  448. room.sendCommandOnce(Commands.CONNECTION_QUALITY, {
  449. children: APP.connectionquality.convertToMUCStats(stats),
  450. attributes: {
  451. xmlns: 'http://jitsi.org/jitmeet/stats'
  452. }
  453. });
  454. }
  455. );
  456. APP.connectionquality.addListener(CQEvents.STOP, () => {
  457. APP.UI.hideStats();
  458. room.removeCommand(Commands.CONNECTION_QUALITY);
  459. });
  460. // listen to remote stats
  461. room.addCommandListener(Commands.CONNECTION_QUALITY,(values, from) => {
  462. APP.connectionquality.updateRemoteStats(from, values);
  463. });
  464. APP.connectionquality.addListener(CQEvents.REMOTESTATS_UPDATED,
  465. (id, percent, stats) => {
  466. APP.UI.updateRemoteStats(id, percent, stats);
  467. });
  468. room.addCommandListener(Commands.ETHERPAD, ({value}) => {
  469. APP.UI.initEtherpad(value);
  470. });
  471. room.addCommandListener(Commands.PREZI, ({value, attributes}) => {
  472. APP.UI.showPrezi(attributes.id, value, attributes.slide);
  473. });
  474. room.addCommandListener(Commands.STOP_PREZI, ({attributes}) => {
  475. APP.UI.stopPrezi(attributes.id);
  476. });
  477. APP.UI.addListener(UIEvents.SHARE_PREZI, (url, slide) => {
  478. console.log('Sharing Prezi %s slide %s', url, slide);
  479. room.removeCommand(Commands.PREZI);
  480. room.sendCommand(Commands.PREZI, {
  481. value: url,
  482. attributes: {
  483. id: room.myUserId(),
  484. slide
  485. }
  486. });
  487. });
  488. APP.UI.addListener(UIEvents.STOP_SHARING_PREZI, () => {
  489. room.removeCommand(Commands.PREZI);
  490. room.sendCommandOnce(Commands.STOP_PREZI, {
  491. attributes: {
  492. id: room.myUserId()
  493. }
  494. });
  495. });
  496. room.addCommandListener(Commands.VIDEO_TYPE, ({value}, from) => {
  497. APP.UI.onPeerVideoTypeChanged(from, value);
  498. });
  499. APP.UI.addListener(UIEvents.EMAIL_CHANGED, (email) => {
  500. APP.settings.setEmail(email);
  501. APP.UI.setUserAvatar(room.myUserId(), email);
  502. sendEmail(email);
  503. });
  504. room.addCommandListener(Commands.EMAIL, (data) => {
  505. APP.UI.setUserAvatar(data.attributes.id, data.value);
  506. });
  507. APP.UI.addListener(UIEvents.NICKNAME_CHANGED, (nickname) => {
  508. APP.settings.setDisplayName(nickname);
  509. room.setDisplayName(nickname);
  510. APP.UI.changeDisplayName(APP.conference.localId, nickname);
  511. });
  512. APP.UI.addListener(UIEvents.START_MUTED_CHANGED,
  513. (startAudioMuted, startVideoMuted) => {
  514. room.setStartMutedPolicy({audio: startAudioMuted,
  515. video: startVideoMuted});
  516. }
  517. );
  518. room.on(
  519. ConferenceEvents.START_MUTED_POLICY_CHANGED,
  520. (policy) => {
  521. APP.UI.onStartMutedChanged();
  522. }
  523. );
  524. room.on(ConferenceEvents.STARTED_MUTED, () => {
  525. (room.isStartAudioMuted() || room.isStartVideoMuted())
  526. && APP.UI.notifyInitiallyMuted();
  527. });
  528. APP.UI.addListener(UIEvents.USER_INVITED, (roomUrl) => {
  529. APP.UI.inviteParticipants(
  530. roomUrl,
  531. APP.conference.roomName,
  532. roomLocker.password,
  533. APP.settings.getDisplayName()
  534. );
  535. });
  536. // call hangup
  537. APP.UI.addListener(UIEvents.HANGUP, () => {
  538. APP.UI.requestFeedback().then(() => {
  539. connection.disconnect();
  540. config.enableWelcomePage && setTimeout(() => {
  541. window.localStorage.welcomePageDisabled = false;
  542. window.location.pathname = "/";
  543. }, 3000);
  544. }, (err) => {console.error(err);});
  545. });
  546. // logout
  547. APP.UI.addListener(UIEvents.LOGOUT, () => {
  548. // FIXME handle logout
  549. // APP.xmpp.logout(function (url) {
  550. // if (url) {
  551. // window.location.href = url;
  552. // } else {
  553. // hangup();
  554. // }
  555. // });
  556. });
  557. APP.UI.addListener(UIEvents.SIP_DIAL, (sipNumber) => {
  558. room.dial(sipNumber);
  559. });
  560. // Starts or stops the recording for the conference.
  561. APP.UI.addListener(UIEvents.RECORDING_TOGGLE, (predefinedToken) => {
  562. if (predefinedToken) {
  563. room.toggleRecording({token: predefinedToken});
  564. return;
  565. }
  566. APP.UI.requestRecordingToken().then((token) => {
  567. room.toggleRecording({token: token});
  568. });
  569. });
  570. APP.UI.addListener(UIEvents.TOPIC_CHANGED, (topic) => {
  571. // FIXME handle topic change
  572. // APP.xmpp.setSubject(topic);
  573. // on SUBJECT_CHANGED UI.setSubject(topic);
  574. });
  575. APP.UI.addListener(UIEvents.USER_KICKED, (id) => {
  576. room.kickParticipant(id);
  577. });
  578. APP.UI.addListener(UIEvents.REMOTE_AUDIO_MUTED, (id) => {
  579. room.muteParticipant(id);
  580. });
  581. APP.UI.addListener(UIEvents.AUTH_CLICKED, () => {
  582. AuthHandler.authenticate(room);
  583. });
  584. APP.UI.addListener(UIEvents.SELECTED_ENDPOINT, (id) => {
  585. room.selectParticipant(id);
  586. });
  587. APP.UI.addListener(UIEvents.PINNED_ENDPOINT, (id) => {
  588. room.pinParticipant(id);
  589. });
  590. APP.UI.addListener(UIEvents.TOGGLE_SCREENSHARING, () => {
  591. APP.desktopsharing.toggleScreenSharing();
  592. });
  593. APP.desktopsharing.addListener(DSEvents.SWITCHING_DONE,
  594. (isSharingScreen) => {
  595. APP.UI.updateDesktopSharingButtons(isSharingScreen);
  596. });
  597. APP.desktopsharing.addListener(DSEvents.FIREFOX_EXTENSION_NEEDED,
  598. (url) => {
  599. APP.UI.showExtensionRequiredDialog(url);
  600. });
  601. APP.desktopsharing.addListener(DSEvents.NEW_STREAM_CREATED,
  602. (track, callback) => {
  603. const localCallback = (newTrack) => {
  604. if(!newTrack || !newTrack.isLocal() ||
  605. newTrack !== localVideo)
  606. return;
  607. if(localVideo.isMuted() &&
  608. localVideo.videoType !== track.videoType) {
  609. localVideo.mute();
  610. }
  611. callback();
  612. if(room)
  613. room.off(ConferenceEvents.TRACK_ADDED, localCallback);
  614. };
  615. if(room) {
  616. room.on(ConferenceEvents.TRACK_ADDED, localCallback);
  617. }
  618. localVideo.stop();
  619. localVideo = track;
  620. addTrack(track);
  621. if(!room)
  622. localCallback();
  623. APP.UI.addLocalStream(track);
  624. }
  625. );
  626. }
  627. };