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

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