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

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