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

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