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

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