Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979
  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(APP.conference.roomName);
  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. APP.UI.notifyFocusLeft();
  202. break;
  203. default:
  204. this._handleConferenceFailed(err, ...params);
  205. }
  206. }
  207. _onConferenceError(err, ...params) {
  208. console.error('CONFERENCE Error:', err, params);
  209. switch (err) {
  210. case ConferenceErrors.CHAT_ERROR:
  211. {
  212. let [code, msg] = params;
  213. APP.UI.showChatError(code, msg);
  214. }
  215. break;
  216. default:
  217. console.error("Unknown error.");
  218. }
  219. }
  220. _unsubscribe() {
  221. room.off(
  222. ConferenceEvents.CONFERENCE_JOINED, this._handleConferenceJoined);
  223. room.off(
  224. ConferenceEvents.CONFERENCE_FAILED, this._onConferenceFailed);
  225. if (this.reconnectTimeout !== null) {
  226. clearTimeout(this.reconnectTimeout);
  227. }
  228. AuthHandler.closeAuth();
  229. }
  230. _handleConferenceJoined() {
  231. this._unsubscribe();
  232. this._resolve();
  233. }
  234. connect() {
  235. room.join();
  236. }
  237. }
  238. export default {
  239. localId: undefined,
  240. isModerator: false,
  241. audioMuted: false,
  242. videoMuted: false,
  243. isSharingScreen: false,
  244. isDesktopSharingEnabled: false,
  245. /**
  246. * Open new connection and join to the conference.
  247. * @param {object} options
  248. * @param {string} roomName name of the conference
  249. * @returns {Promise}
  250. */
  251. init(options) {
  252. this.roomName = options.roomName;
  253. JitsiMeetJS.setLogLevel(JitsiMeetJS.logLevels.TRACE);
  254. return JitsiMeetJS.init(config).then(() => {
  255. return Promise.all([
  256. // try to retrieve audio and video
  257. createLocalTracks('audio', 'video')
  258. // if failed then try to retrieve only audio
  259. .catch(() => createLocalTracks('audio'))
  260. // if audio also failed then just return empty array
  261. .catch(() => []),
  262. connect(options.roomName)
  263. ]);
  264. }).then(([tracks, con]) => {
  265. console.log('initialized with %s local tracks', tracks.length);
  266. connection = con;
  267. this._createRoom(tracks);
  268. this.isDesktopSharingEnabled =
  269. JitsiMeetJS.isDesktopSharingEnabled();
  270. // update list of available devices
  271. if (JitsiMeetJS.isDeviceListAvailable() &&
  272. JitsiMeetJS.isDeviceChangeAvailable()) {
  273. JitsiMeetJS.enumerateDevices((devices) => {
  274. this.availableDevices = devices;
  275. APP.UI.onAvailableDevicesChanged();
  276. });
  277. }
  278. // XXX The API will take care of disconnecting from the XMPP server
  279. // (and, thus, leaving the room) on unload.
  280. return new Promise((resolve, reject) => {
  281. (new ConferenceConnector(resolve, reject)).connect();
  282. });
  283. });
  284. },
  285. /**
  286. * Check if id is id of the local user.
  287. * @param {string} id id to check
  288. * @returns {boolean}
  289. */
  290. isLocalId (id) {
  291. return this.localId === id;
  292. },
  293. /**
  294. * Simulates toolbar button click for audio mute. Used by shortcuts and API.
  295. * @param mute true for mute and false for unmute.
  296. */
  297. muteAudio (mute) {
  298. muteLocalAudio(mute);
  299. },
  300. /**
  301. * Returns whether local audio is muted or not.
  302. * @returns {boolean}
  303. */
  304. isLocalAudioMuted() {
  305. return this.audioMuted;
  306. },
  307. /**
  308. * Simulates toolbar button click for audio mute. Used by shortcuts and API.
  309. */
  310. toggleAudioMuted () {
  311. this.muteAudio(!this.audioMuted);
  312. },
  313. /**
  314. * Simulates toolbar button click for video mute. Used by shortcuts and API.
  315. * @param mute true for mute and false for unmute.
  316. */
  317. muteVideo (mute) {
  318. muteLocalVideo(mute);
  319. },
  320. /**
  321. * Simulates toolbar button click for video mute. Used by shortcuts and API.
  322. */
  323. toggleVideoMuted () {
  324. this.muteVideo(!this.videoMuted);
  325. },
  326. /**
  327. * Retrieve list of conference participants (without local user).
  328. * @returns {JitsiParticipant[]}
  329. */
  330. listMembers () {
  331. return room.getParticipants();
  332. },
  333. /**
  334. * Retrieve list of ids of conference participants (without local user).
  335. * @returns {string[]}
  336. */
  337. listMembersIds () {
  338. return room.getParticipants().map(p => p.getId());
  339. },
  340. /**
  341. * List of available cameras and microphones.
  342. */
  343. availableDevices: [],
  344. /**
  345. * Check if SIP is supported.
  346. * @returns {boolean}
  347. */
  348. sipGatewayEnabled () {
  349. return room.isSIPCallingSupported();
  350. },
  351. get membersCount () {
  352. return room.getParticipants().length + 1;
  353. },
  354. get startAudioMuted () {
  355. return room && room.getStartMutedPolicy().audio;
  356. },
  357. get startVideoMuted () {
  358. return room && room.getStartMutedPolicy().video;
  359. },
  360. /**
  361. * Returns true if the callstats integration is enabled, otherwise returns
  362. * false.
  363. *
  364. * @returns true if the callstats integration is enabled, otherwise returns
  365. * false.
  366. */
  367. isCallstatsEnabled () {
  368. return room.isCallstatsEnabled();
  369. },
  370. /**
  371. * Sends the given feedback through CallStats if enabled.
  372. *
  373. * @param overallFeedback an integer between 1 and 5 indicating the
  374. * user feedback
  375. * @param detailedFeedback detailed feedback from the user. Not yet used
  376. */
  377. sendFeedback (overallFeedback, detailedFeedback) {
  378. return room.sendFeedback (overallFeedback, detailedFeedback);
  379. },
  380. // used by torture currently
  381. isJoined () {
  382. return this._room
  383. && this._room.isJoined();
  384. },
  385. getConnectionState () {
  386. return this._room
  387. && this._room.getConnectionState();
  388. },
  389. getMyUserId () {
  390. return this._room
  391. && this._room.myUserId();
  392. },
  393. /**
  394. * Will be filled with values only when config.debug is enabled.
  395. * Its used by torture to check audio levels.
  396. */
  397. audioLevelsMap: {},
  398. /**
  399. * Returns the stored audio level (stored only if config.debug is enabled)
  400. * @param id the id for the user audio level to return (the id value is
  401. * returned for the participant using getMyUserId() method)
  402. */
  403. getPeerSSRCAudioLevel (id) {
  404. return this.audioLevelsMap[id];
  405. },
  406. /**
  407. * Will check for number of remote particiapnts that have at least one
  408. * remote track.
  409. * @return {boolean} whether we have enough participants with remote streams
  410. */
  411. checkEnoughParticipants (number) {
  412. var participants = this._room.getParticipants();
  413. var foundParticipants = 0;
  414. for (var i = 0; i < participants.length; i += 1) {
  415. if (participants[i].getTracks().length > 0) {
  416. foundParticipants++;
  417. }
  418. }
  419. return foundParticipants >= number;
  420. },
  421. /**
  422. * Returns the stats.
  423. */
  424. getStats() {
  425. return ConnectionQuality.getStats();
  426. },
  427. // end used by torture
  428. getLogs () {
  429. return room.getLogs();
  430. },
  431. _createRoom (localTracks) {
  432. room = connection.initJitsiConference(APP.conference.roomName,
  433. this._getConferenceOptions());
  434. this.localId = room.myUserId();
  435. localTracks.forEach((track) => {
  436. room.addTrack(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. */
  469. useVideoStream (stream) {
  470. if (localVideo) {
  471. localVideo.stop();
  472. }
  473. localVideo = stream;
  474. if (stream) {
  475. this.videoMuted = stream.isMuted();
  476. APP.UI.addLocalStream(stream);
  477. this.isSharingScreen = stream.videoType === 'desktop';
  478. } else {
  479. this.videoMuted = false;
  480. this.isSharingScreen = false;
  481. }
  482. APP.UI.setVideoMuted(this.localId, this.videoMuted);
  483. APP.UI.updateDesktopSharingButtons();
  484. },
  485. /**
  486. * Start using provided audio stream.
  487. * Stops previous audio stream.
  488. * @param {JitsiLocalTrack} [stream] new stream to use or null
  489. */
  490. useAudioStream (stream) {
  491. if (localAudio) {
  492. localAudio.stop();
  493. }
  494. localAudio = stream;
  495. if (stream) {
  496. this.audioMuted = stream.isMuted();
  497. APP.UI.addLocalStream(stream);
  498. } else {
  499. this.audioMuted = false;
  500. }
  501. APP.UI.setAudioMuted(this.localId, this.audioMuted);
  502. },
  503. videoSwitchInProgress: false,
  504. toggleScreenSharing () {
  505. if (this.videoSwitchInProgress) {
  506. console.warn("Switch in progress.");
  507. return;
  508. }
  509. if (!this.isDesktopSharingEnabled) {
  510. console.warn("Cannot toggle screen sharing: not supported.");
  511. return;
  512. }
  513. this.videoSwitchInProgress = true;
  514. if (this.isSharingScreen) {
  515. // stop sharing desktop and share video
  516. createLocalTracks('video').then(function ([stream]) {
  517. return room.addTrack(stream);
  518. }).then((stream) => {
  519. this.useVideoStream(stream);
  520. this.videoSwitchInProgress = false;
  521. console.log('sharing local video');
  522. }).catch(function (err) {
  523. this.useVideoStream(null);
  524. this.videoSwitchInProgress = false;
  525. console.error('failed to share local video', err);
  526. });
  527. } else {
  528. // stop sharing video and share desktop
  529. createDesktopTrack().then(([stream]) => {
  530. stream.on(
  531. TrackEvents.TRACK_STOPPED,
  532. () => {
  533. // if stream was stopped during screensharing session
  534. // then we should switch to video
  535. // otherwise we stopped it because we already switched
  536. // to video, so nothing to do here
  537. if (this.isSharingScreen) {
  538. this.toggleScreenSharing();
  539. }
  540. }
  541. );
  542. return room.addTrack(stream);
  543. }).then((stream) => {
  544. this.useVideoStream(stream);
  545. this.videoSwitchInProgress = false;
  546. console.log('sharing local desktop');
  547. }).catch((err) => {
  548. this.videoSwitchInProgress = false;
  549. console.error('failed to share local desktop', err);
  550. });
  551. }
  552. },
  553. /**
  554. * Setup interaction between conference and UI.
  555. */
  556. _setupListeners () {
  557. // add local streams when joined to the conference
  558. room.on(ConferenceEvents.CONFERENCE_JOINED, () => {
  559. APP.UI.updateAuthInfo(room.isAuthEnabled(), room.getAuthLogin());
  560. APP.UI.mucJoined();
  561. });
  562. room.on(ConferenceEvents.USER_JOINED, (id, user) => {
  563. console.log('USER %s connnected', id, user);
  564. APP.API.notifyUserJoined(id);
  565. // FIXME email???
  566. APP.UI.addUser(id, user.getDisplayName());
  567. // chek the roles for the new user and reflect them
  568. APP.UI.updateUserRole(user);
  569. });
  570. room.on(ConferenceEvents.USER_LEFT, (id, user) => {
  571. console.log('USER %s LEFT', id, user);
  572. APP.API.notifyUserLeft(id);
  573. APP.UI.removeUser(id, user.getDisplayName());
  574. APP.UI.stopPrezi(id);
  575. });
  576. room.on(ConferenceEvents.USER_ROLE_CHANGED, (id, role) => {
  577. if (this.isLocalId(id)) {
  578. console.info(`My role changed, new role: ${role}`);
  579. this.isModerator = room.isModerator();
  580. APP.UI.updateLocalRole(room.isModerator());
  581. } else {
  582. let user = room.getParticipantById(id);
  583. if (user) {
  584. APP.UI.updateUserRole(user);
  585. }
  586. }
  587. });
  588. room.on(ConferenceEvents.TRACK_ADDED, (track) => {
  589. if(!track || track.isLocal())
  590. return;
  591. track.on(TrackEvents.TRACK_VIDEOTYPE_CHANGED, (type) => {
  592. APP.UI.onPeerVideoTypeChanged(track.getParticipantId(), type);
  593. });
  594. APP.UI.addRemoteStream(track);
  595. });
  596. room.on(ConferenceEvents.TRACK_REMOVED, (track) => {
  597. // FIXME handle
  598. });
  599. room.on(ConferenceEvents.TRACK_MUTE_CHANGED, (track) => {
  600. if(!track)
  601. return;
  602. const handler = (track.getType() === "audio")?
  603. APP.UI.setAudioMuted : APP.UI.setVideoMuted;
  604. let id;
  605. const mute = track.isMuted();
  606. if(track.isLocal()){
  607. id = this.localId;
  608. if(track.getType() === "audio") {
  609. this.audioMuted = mute;
  610. } else {
  611. this.videoMuted = mute;
  612. }
  613. } else {
  614. id = track.getParticipantId();
  615. }
  616. handler(id , mute);
  617. });
  618. room.on(ConferenceEvents.TRACK_AUDIO_LEVEL_CHANGED, (id, lvl) => {
  619. if(this.isLocalId(id) && localAudio && localAudio.isMuted()) {
  620. lvl = 0;
  621. }
  622. if(config.debug)
  623. {
  624. this.audioLevelsMap[id] = lvl;
  625. console.log("AudioLevel:" + id + "/" + lvl);
  626. }
  627. APP.UI.setAudioLevel(id, lvl);
  628. });
  629. room.on(ConferenceEvents.IN_LAST_N_CHANGED, (inLastN) => {
  630. //FIXME
  631. if (config.muteLocalVideoIfNotInLastN) {
  632. // TODO mute or unmute if required
  633. // mark video on UI
  634. // APP.UI.markVideoMuted(true/false);
  635. }
  636. });
  637. room.on(
  638. ConferenceEvents.LAST_N_ENDPOINTS_CHANGED, (ids, enteringIds) => {
  639. APP.UI.handleLastNEndpoints(ids, enteringIds);
  640. });
  641. room.on(ConferenceEvents.DOMINANT_SPEAKER_CHANGED, (id) => {
  642. APP.UI.markDominantSpeaker(id);
  643. });
  644. if (!interfaceConfig.filmStripOnly) {
  645. room.on(ConferenceEvents.CONNECTION_INTERRUPTED, () => {
  646. APP.UI.markVideoInterrupted(true);
  647. });
  648. room.on(ConferenceEvents.CONNECTION_RESTORED, () => {
  649. APP.UI.markVideoInterrupted(false);
  650. });
  651. room.on(ConferenceEvents.MESSAGE_RECEIVED, (id, text, ts) => {
  652. let nick = getDisplayName(id);
  653. APP.API.notifyReceivedChatMessage(id, nick, text, ts);
  654. APP.UI.addMessage(id, nick, text, ts);
  655. });
  656. }
  657. room.on(ConferenceEvents.DISPLAY_NAME_CHANGED, (id, displayName) => {
  658. APP.API.notifyDisplayNameChanged(id, displayName);
  659. APP.UI.changeDisplayName(id, displayName);
  660. });
  661. room.on(ConferenceEvents.RECORDING_STATE_CHANGED, (status, error) => {
  662. if(status == "error") {
  663. console.error(error);
  664. return;
  665. }
  666. APP.UI.updateRecordingState(status);
  667. });
  668. room.on(ConferenceEvents.USER_STATUS_CHANGED, function (id, status) {
  669. APP.UI.updateUserStatus(id, status);
  670. });
  671. room.on(ConferenceEvents.KICKED, () => {
  672. APP.UI.hideStats();
  673. APP.UI.notifyKicked();
  674. // FIXME close
  675. });
  676. room.on(ConferenceEvents.DTMF_SUPPORT_CHANGED, (isDTMFSupported) => {
  677. APP.UI.updateDTMFSupport(isDTMFSupported);
  678. });
  679. room.on(ConferenceEvents.FIREFOX_EXTENSION_NEEDED, function (url) {
  680. APP.UI.notifyFirefoxExtensionRequired(url);
  681. });
  682. APP.UI.addListener(UIEvents.ROOM_LOCK_CLICKED, () => {
  683. if (room.isModerator()) {
  684. let promise = roomLocker.isLocked
  685. ? roomLocker.askToUnlock()
  686. : roomLocker.askToLock();
  687. promise.then(() => {
  688. APP.UI.markRoomLocked(roomLocker.isLocked);
  689. });
  690. } else {
  691. roomLocker.notifyModeratorRequired();
  692. }
  693. });
  694. APP.UI.addListener(UIEvents.AUDIO_MUTED, muteLocalAudio);
  695. APP.UI.addListener(UIEvents.VIDEO_MUTED, muteLocalVideo);
  696. if (!interfaceConfig.filmStripOnly) {
  697. APP.UI.addListener(UIEvents.MESSAGE_CREATED, (message) => {
  698. APP.API.notifySendingChatMessage(message);
  699. room.sendTextMessage(message);
  700. });
  701. }
  702. room.on(ConferenceEvents.CONNECTION_STATS, function (stats) {
  703. ConnectionQuality.updateLocalStats(stats);
  704. });
  705. ConnectionQuality.addListener(
  706. CQEvents.LOCALSTATS_UPDATED,
  707. (percent, stats) => {
  708. APP.UI.updateLocalStats(percent, stats);
  709. // send local stats to other users
  710. room.sendCommandOnce(Commands.CONNECTION_QUALITY, {
  711. children: ConnectionQuality.convertToMUCStats(stats),
  712. attributes: {
  713. xmlns: 'http://jitsi.org/jitmeet/stats'
  714. }
  715. });
  716. }
  717. );
  718. // listen to remote stats
  719. room.addCommandListener(Commands.CONNECTION_QUALITY,(values, from) => {
  720. ConnectionQuality.updateRemoteStats(from, values);
  721. });
  722. ConnectionQuality.addListener(CQEvents.REMOTESTATS_UPDATED,
  723. (id, percent, stats) => {
  724. APP.UI.updateRemoteStats(id, percent, stats);
  725. });
  726. room.addCommandListener(Commands.ETHERPAD, ({value}) => {
  727. APP.UI.initEtherpad(value);
  728. });
  729. room.addCommandListener(Commands.PREZI, ({value, attributes}) => {
  730. APP.UI.showPrezi(attributes.id, value, attributes.slide);
  731. });
  732. room.addCommandListener(Commands.STOP_PREZI, ({attributes}) => {
  733. APP.UI.stopPrezi(attributes.id);
  734. });
  735. APP.UI.addListener(UIEvents.SHARE_PREZI, (url, slide) => {
  736. console.log('Sharing Prezi %s slide %s', url, slide);
  737. room.removeCommand(Commands.PREZI);
  738. room.sendCommand(Commands.PREZI, {
  739. value: url,
  740. attributes: {
  741. id: room.myUserId(),
  742. slide
  743. }
  744. });
  745. });
  746. APP.UI.addListener(UIEvents.STOP_SHARING_PREZI, () => {
  747. room.removeCommand(Commands.PREZI);
  748. room.sendCommandOnce(Commands.STOP_PREZI, {
  749. attributes: {
  750. id: room.myUserId()
  751. }
  752. });
  753. });
  754. APP.UI.addListener(UIEvents.EMAIL_CHANGED, (email) => {
  755. APP.settings.setEmail(email);
  756. APP.UI.setUserAvatar(room.myUserId(), email);
  757. sendEmail(email);
  758. });
  759. room.addCommandListener(Commands.EMAIL, (data) => {
  760. APP.UI.setUserAvatar(data.attributes.id, data.value);
  761. });
  762. APP.UI.addListener(UIEvents.NICKNAME_CHANGED, (nickname) => {
  763. APP.settings.setDisplayName(nickname);
  764. room.setDisplayName(nickname);
  765. APP.UI.changeDisplayName(APP.conference.localId, nickname);
  766. });
  767. APP.UI.addListener(UIEvents.START_MUTED_CHANGED,
  768. (startAudioMuted, startVideoMuted) => {
  769. room.setStartMutedPolicy({audio: startAudioMuted,
  770. video: startVideoMuted});
  771. }
  772. );
  773. room.on(
  774. ConferenceEvents.START_MUTED_POLICY_CHANGED,
  775. (policy) => {
  776. APP.UI.onStartMutedChanged();
  777. }
  778. );
  779. room.on(ConferenceEvents.STARTED_MUTED, () => {
  780. (room.isStartAudioMuted() || room.isStartVideoMuted())
  781. && APP.UI.notifyInitiallyMuted();
  782. });
  783. APP.UI.addListener(UIEvents.USER_INVITED, (roomUrl) => {
  784. APP.UI.inviteParticipants(
  785. roomUrl,
  786. APP.conference.roomName,
  787. roomLocker.password,
  788. APP.settings.getDisplayName()
  789. );
  790. });
  791. room.on(
  792. ConferenceEvents.AVAILABLE_DEVICES_CHANGED, function (id, devices) {
  793. APP.UI.updateDevicesAvailability(id, devices);
  794. }
  795. );
  796. // call hangup
  797. APP.UI.addListener(UIEvents.HANGUP, () => {
  798. APP.UI.requestFeedback().then(() => {
  799. connection.disconnect();
  800. config.enableWelcomePage && setTimeout(() => {
  801. window.localStorage.welcomePageDisabled = false;
  802. window.location.pathname = "/";
  803. }, 3000);
  804. }, (err) => {console.error(err);});
  805. });
  806. // logout
  807. APP.UI.addListener(UIEvents.LOGOUT, () => {
  808. // FIXME handle logout
  809. // APP.xmpp.logout(function (url) {
  810. // if (url) {
  811. // window.location.href = url;
  812. // } else {
  813. // hangup();
  814. // }
  815. // });
  816. });
  817. APP.UI.addListener(UIEvents.SIP_DIAL, (sipNumber) => {
  818. room.dial(sipNumber);
  819. });
  820. // Starts or stops the recording for the conference.
  821. APP.UI.addListener(UIEvents.RECORDING_TOGGLE, (predefinedToken) => {
  822. if (predefinedToken) {
  823. room.toggleRecording({token: predefinedToken});
  824. return;
  825. }
  826. APP.UI.requestRecordingToken().then((token) => {
  827. room.toggleRecording({token: token});
  828. });
  829. });
  830. APP.UI.addListener(UIEvents.SUBJECT_CHANGED, (topic) => {
  831. room.setSubject(topic);
  832. });
  833. room.on(ConferenceEvents.SUBJECT_CHANGED, function (subject) {
  834. APP.UI.setSubject(subject);
  835. });
  836. APP.UI.addListener(UIEvents.USER_KICKED, (id) => {
  837. room.kickParticipant(id);
  838. });
  839. APP.UI.addListener(UIEvents.REMOTE_AUDIO_MUTED, (id) => {
  840. room.muteParticipant(id);
  841. });
  842. APP.UI.addListener(UIEvents.AUTH_CLICKED, () => {
  843. AuthHandler.authenticate(room);
  844. });
  845. APP.UI.addListener(UIEvents.SELECTED_ENDPOINT, (id) => {
  846. room.selectParticipant(id);
  847. });
  848. APP.UI.addListener(UIEvents.PINNED_ENDPOINT, (id) => {
  849. room.pinParticipant(id);
  850. });
  851. APP.UI.addListener(
  852. UIEvents.VIDEO_DEVICE_CHANGED,
  853. (cameraDeviceId) => {
  854. APP.settings.setCameraDeviceId(cameraDeviceId);
  855. createLocalTracks('video').then(([stream]) => {
  856. room.addTrack(stream);
  857. this.useVideoStream(stream);
  858. console.log('switched local video device');
  859. });
  860. }
  861. );
  862. APP.UI.addListener(
  863. UIEvents.AUDIO_DEVICE_CHANGED,
  864. (micDeviceId) => {
  865. APP.settings.setMicDeviceId(micDeviceId);
  866. createLocalTracks('audio').then(([stream]) => {
  867. room.addTrack(stream);
  868. this.useAudioStream(stream);
  869. console.log('switched local audio device');
  870. });
  871. }
  872. );
  873. APP.UI.addListener(
  874. UIEvents.TOGGLE_SCREENSHARING, this.toggleScreenSharing.bind(this)
  875. );
  876. }
  877. };