選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

conference.js 31KB

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