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

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