您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

conference.js 27KB

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