Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

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