You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

conference.js 90KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562
  1. /* global $, APP, JitsiMeetJS, config, interfaceConfig */
  2. const logger = require("jitsi-meet-logger").getLogger(__filename);
  3. import {openConnection} from './connection';
  4. import AuthHandler from './modules/UI/authentication/AuthHandler';
  5. import Recorder from './modules/recorder/Recorder';
  6. import mediaDeviceHelper from './modules/devices/mediaDeviceHelper';
  7. import { reload, reportError } from './modules/util/helpers';
  8. import * as RemoteControlEvents
  9. from './service/remotecontrol/RemoteControlEvents';
  10. import UIEvents from './service/UI/UIEvents';
  11. import UIUtil from './modules/UI/util/UIUtil';
  12. import * as JitsiMeetConferenceEvents from './ConferenceEvents';
  13. import { initAnalytics } from './react/features/analytics';
  14. import EventEmitter from "events";
  15. import {
  16. AVATAR_ID_COMMAND,
  17. AVATAR_URL_COMMAND,
  18. conferenceFailed,
  19. conferenceJoined,
  20. conferenceLeft,
  21. dataChannelOpened,
  22. toggleAudioOnly,
  23. EMAIL_COMMAND,
  24. lockStateChanged,
  25. p2pStatusChanged
  26. } from './react/features/base/conference';
  27. import { updateDeviceList } from './react/features/base/devices';
  28. import {
  29. isAnalyticsEnabled,
  30. isFatalJitsiConnectionError
  31. } from './react/features/base/lib-jitsi-meet';
  32. import {
  33. isVideoMutedByUser,
  34. MEDIA_TYPE,
  35. setAudioAvailable,
  36. setAudioMuted,
  37. setVideoAvailable,
  38. setVideoMuted
  39. } from './react/features/base/media';
  40. import {
  41. dominantSpeakerChanged,
  42. localParticipantConnectionStatusChanged,
  43. localParticipantRoleChanged,
  44. MAX_DISPLAY_NAME_LENGTH,
  45. participantConnectionStatusChanged,
  46. participantJoined,
  47. participantLeft,
  48. participantPresenceChanged,
  49. participantRoleChanged,
  50. participantUpdated
  51. } from './react/features/base/participants';
  52. import {
  53. createLocalTracksF,
  54. isLocalTrackMuted,
  55. replaceLocalTrack,
  56. trackAdded,
  57. trackRemoved
  58. } from './react/features/base/tracks';
  59. import { getLocationContextRoot } from './react/features/base/util';
  60. import { statsEmitter } from './react/features/connection-indicator';
  61. import { showDesktopPicker } from './react/features/desktop-picker';
  62. import { maybeOpenFeedbackDialog } from './react/features/feedback';
  63. import {
  64. mediaPermissionPromptVisibilityChanged,
  65. suspendDetected
  66. } from './react/features/overlay';
  67. import { showDesktopSharingButton } from './react/features/toolbox';
  68. const { participantConnectionStatus } = JitsiMeetJS.constants;
  69. const ConnectionEvents = JitsiMeetJS.events.connection;
  70. const ConnectionErrors = JitsiMeetJS.errors.connection;
  71. const ConferenceEvents = JitsiMeetJS.events.conference;
  72. const ConferenceErrors = JitsiMeetJS.errors.conference;
  73. const TrackEvents = JitsiMeetJS.events.track;
  74. const TrackErrors = JitsiMeetJS.errors.track;
  75. const eventEmitter = new EventEmitter();
  76. let room;
  77. let connection;
  78. /*
  79. * Logic to open a desktop picker put on the window global for
  80. * lib-jitsi-meet to detect and invoke
  81. */
  82. window.JitsiMeetScreenObtainer = {
  83. openDesktopPicker(options, onSourceChoose) {
  84. APP.store.dispatch(showDesktopPicker(options, onSourceChoose));
  85. }
  86. };
  87. /**
  88. * Known custom conference commands.
  89. */
  90. const commands = {
  91. AVATAR_ID: AVATAR_ID_COMMAND,
  92. AVATAR_URL: AVATAR_URL_COMMAND,
  93. CUSTOM_ROLE: "custom-role",
  94. EMAIL: EMAIL_COMMAND,
  95. ETHERPAD: "etherpad",
  96. SHARED_VIDEO: "shared-video"
  97. };
  98. /**
  99. * Open Connection. When authentication failed it shows auth dialog.
  100. * @param roomName the room name to use
  101. * @returns Promise<JitsiConnection>
  102. */
  103. function connect(roomName) {
  104. return openConnection({retry: true, roomName: roomName})
  105. .catch(function (err) {
  106. if (err === ConnectionErrors.PASSWORD_REQUIRED) {
  107. APP.UI.notifyTokenAuthFailed();
  108. } else {
  109. APP.UI.notifyConnectionFailed(err);
  110. }
  111. throw err;
  112. });
  113. }
  114. /**
  115. * Share data to other users.
  116. * @param command the command
  117. * @param {string} value new value
  118. */
  119. function sendData(command, value) {
  120. if (!room) {
  121. return;
  122. }
  123. room.removeCommand(command);
  124. room.sendCommand(command, {value: value});
  125. }
  126. /**
  127. * Sets up initially the properties of the local participant - email, avatarID,
  128. * avatarURL, displayName, etc.
  129. */
  130. function _setupLocalParticipantProperties() {
  131. const email = APP.settings.getEmail();
  132. email && sendData(commands.EMAIL, email);
  133. const avatarUrl = APP.settings.getAvatarUrl();
  134. avatarUrl && sendData(commands.AVATAR_URL, avatarUrl);
  135. if (!email && !avatarUrl) {
  136. sendData(commands.AVATAR_ID, APP.settings.getAvatarId());
  137. }
  138. let nick = APP.settings.getDisplayName();
  139. if (config.useNicks && !nick) {
  140. nick = APP.UI.askForNickname();
  141. APP.settings.setDisplayName(nick);
  142. }
  143. nick && room.setDisplayName(nick);
  144. }
  145. /**
  146. * Get user nickname by user id.
  147. * @param {string} id user id
  148. * @returns {string?} user nickname or undefined if user is unknown.
  149. */
  150. function getDisplayName(id) {
  151. if (APP.conference.isLocalId(id)) {
  152. return APP.settings.getDisplayName();
  153. }
  154. let participant = room.getParticipantById(id);
  155. if (participant && participant.getDisplayName()) {
  156. return participant.getDisplayName();
  157. }
  158. }
  159. /**
  160. * Mute or unmute local audio stream if it exists.
  161. * @param {boolean} muted - if audio stream should be muted or unmuted.
  162. */
  163. function muteLocalAudio(muted) {
  164. APP.store.dispatch(setAudioMuted(muted));
  165. }
  166. /**
  167. * Mute or unmute local video stream if it exists.
  168. * @param {boolean} muted if video stream should be muted or unmuted.
  169. *
  170. */
  171. function muteLocalVideo(muted) {
  172. APP.store.dispatch(setVideoMuted(muted));
  173. }
  174. /**
  175. * Check if the welcome page is enabled and redirects to it.
  176. * If requested show a thank you dialog before that.
  177. * If we have a close page enabled, redirect to it without
  178. * showing any other dialog.
  179. *
  180. * @param {object} options used to decide which particular close page to show
  181. * or if close page is disabled, whether we should show the thankyou dialog
  182. * @param {boolean} options.thankYouDialogVisible - whether we should
  183. * show thank you dialog
  184. * @param {boolean} options.feedbackSubmitted - whether feedback was submitted
  185. */
  186. function maybeRedirectToWelcomePage(options) {
  187. // if close page is enabled redirect to it, without further action
  188. if (config.enableClosePage) {
  189. const { isGuest } = APP.store.getState()['features/jwt'];
  190. // save whether current user is guest or not, before navigating
  191. // to close page
  192. window.sessionStorage.setItem('guest', isGuest);
  193. assignWindowLocationPathname('static/'
  194. + (options.feedbackSubmitted ? "close.html" : "close2.html"));
  195. return;
  196. }
  197. // else: show thankYou dialog only if there is no feedback
  198. if (options.thankYouDialogVisible)
  199. APP.UI.messageHandler.openMessageDialog(
  200. null, "dialog.thankYou", {appName:interfaceConfig.APP_NAME});
  201. // if Welcome page is enabled redirect to welcome page after 3 sec.
  202. if (config.enableWelcomePage) {
  203. setTimeout(() => {
  204. APP.settings.setWelcomePageEnabled(true);
  205. assignWindowLocationPathname('./');
  206. }, 3000);
  207. }
  208. }
  209. /**
  210. * Assigns a specific pathname to window.location.pathname taking into account
  211. * the context root of the Web app.
  212. *
  213. * @param {string} pathname - The pathname to assign to
  214. * window.location.pathname. If the specified pathname is relative, the context
  215. * root of the Web app will be prepended to the specified pathname before
  216. * assigning it to window.location.pathname.
  217. * @return {void}
  218. */
  219. function assignWindowLocationPathname(pathname) {
  220. const windowLocation = window.location;
  221. if (!pathname.startsWith('/')) {
  222. // A pathname equal to ./ specifies the current directory. It will be
  223. // fine but pointless to include it because contextRoot is the current
  224. // directory.
  225. pathname.startsWith('./') && (pathname = pathname.substring(2));
  226. pathname = getLocationContextRoot(windowLocation) + pathname;
  227. }
  228. windowLocation.pathname = pathname;
  229. }
  230. class ConferenceConnector {
  231. constructor(resolve, reject) {
  232. this._resolve = resolve;
  233. this._reject = reject;
  234. this.reconnectTimeout = null;
  235. room.on(ConferenceEvents.CONFERENCE_JOINED,
  236. this._handleConferenceJoined.bind(this));
  237. room.on(ConferenceEvents.CONFERENCE_FAILED,
  238. this._onConferenceFailed.bind(this));
  239. room.on(ConferenceEvents.CONFERENCE_ERROR,
  240. this._onConferenceError.bind(this));
  241. }
  242. _handleConferenceFailed(err) {
  243. this._unsubscribe();
  244. this._reject(err);
  245. }
  246. _onConferenceFailed(err, ...params) {
  247. APP.store.dispatch(conferenceFailed(room, err, ...params));
  248. logger.error('CONFERENCE FAILED:', err, ...params);
  249. switch (err) {
  250. case ConferenceErrors.CONNECTION_ERROR:
  251. {
  252. let [msg] = params;
  253. APP.UI.notifyConnectionFailed(msg);
  254. }
  255. break;
  256. case ConferenceErrors.NOT_ALLOWED_ERROR:
  257. {
  258. // let's show some auth not allowed page
  259. assignWindowLocationPathname('static/authError.html');
  260. }
  261. break;
  262. // not enough rights to create conference
  263. case ConferenceErrors.AUTHENTICATION_REQUIRED: {
  264. // Schedule reconnect to check if someone else created the room.
  265. this.reconnectTimeout = setTimeout(() => room.join(), 5000);
  266. const { password }
  267. = APP.store.getState()['features/base/conference'];
  268. AuthHandler.requireAuth(room, password);
  269. }
  270. break;
  271. case ConferenceErrors.RESERVATION_ERROR:
  272. {
  273. let [code, msg] = params;
  274. APP.UI.notifyReservationError(code, msg);
  275. }
  276. break;
  277. case ConferenceErrors.GRACEFUL_SHUTDOWN:
  278. APP.UI.notifyGracefulShutdown();
  279. break;
  280. case ConferenceErrors.JINGLE_FATAL_ERROR:
  281. APP.UI.notifyInternalError();
  282. break;
  283. case ConferenceErrors.CONFERENCE_DESTROYED:
  284. {
  285. let [reason] = params;
  286. APP.UI.hideStats();
  287. APP.UI.notifyConferenceDestroyed(reason);
  288. }
  289. break;
  290. // FIXME FOCUS_DISCONNECTED is confusing event name.
  291. // What really happens there is that the library is not ready yet,
  292. // because Jicofo is not available, but it is going to give
  293. // it another try.
  294. case ConferenceErrors.FOCUS_DISCONNECTED:
  295. {
  296. let [focus, retrySec] = params;
  297. APP.UI.notifyFocusDisconnected(focus, retrySec);
  298. }
  299. break;
  300. case ConferenceErrors.FOCUS_LEFT:
  301. case ConferenceErrors.VIDEOBRIDGE_NOT_AVAILABLE:
  302. // FIXME the conference should be stopped by the library and not by
  303. // the app. Both the errors above are unrecoverable from the library
  304. // perspective.
  305. room.leave().then(() => connection.disconnect());
  306. break;
  307. case ConferenceErrors.CONFERENCE_MAX_USERS:
  308. connection.disconnect();
  309. APP.UI.notifyMaxUsersLimitReached();
  310. break;
  311. case ConferenceErrors.INCOMPATIBLE_SERVER_VERSIONS:
  312. reload();
  313. break;
  314. default:
  315. this._handleConferenceFailed(err, ...params);
  316. }
  317. }
  318. _onConferenceError(err, ...params) {
  319. logger.error('CONFERENCE Error:', err, params);
  320. switch (err) {
  321. case ConferenceErrors.CHAT_ERROR:
  322. {
  323. let [code, msg] = params;
  324. APP.UI.showChatError(code, msg);
  325. }
  326. break;
  327. default:
  328. logger.error("Unknown error.", err);
  329. }
  330. }
  331. _unsubscribe() {
  332. room.off(
  333. ConferenceEvents.CONFERENCE_JOINED, this._handleConferenceJoined);
  334. room.off(
  335. ConferenceEvents.CONFERENCE_FAILED, this._onConferenceFailed);
  336. if (this.reconnectTimeout !== null) {
  337. clearTimeout(this.reconnectTimeout);
  338. }
  339. AuthHandler.closeAuth();
  340. }
  341. _handleConferenceJoined() {
  342. this._unsubscribe();
  343. this._resolve();
  344. }
  345. connect() {
  346. room.join();
  347. }
  348. }
  349. /**
  350. * Disconnects the connection.
  351. * @returns resolved Promise. We need this in order to make the Promise.all
  352. * call in hangup() to resolve when all operations are finished.
  353. */
  354. function disconnect() {
  355. connection.disconnect();
  356. APP.API.notifyConferenceLeft(APP.conference.roomName);
  357. return Promise.resolve();
  358. }
  359. /**
  360. * Handles CONNECTION_FAILED events from lib-jitsi-meet.
  361. *
  362. * @param {JitsiMeetJS.connection.error} error - The reported error.
  363. * @returns {void}
  364. * @private
  365. */
  366. function _connectionFailedHandler(error) {
  367. if (isFatalJitsiConnectionError(error)) {
  368. APP.connection.removeEventListener(
  369. ConnectionEvents.CONNECTION_FAILED,
  370. _connectionFailedHandler);
  371. if (room)
  372. room.leave();
  373. }
  374. }
  375. export default {
  376. /**
  377. * Flag used to delay modification of the muted status of local media tracks
  378. * until those are created (or not, but at that point it's certain that
  379. * the tracks won't exist).
  380. */
  381. _localTracksInitialized: false,
  382. isModerator: false,
  383. isSharingScreen: false,
  384. /**
  385. * Indicates if the desktop sharing functionality has been enabled.
  386. * It takes into consideration {@link isDesktopSharingDisabledByConfig}
  387. * as well as the status returned by
  388. * {@link JitsiMeetJS.isDesktopSharingEnabled()}. The latter can be false
  389. * either if the desktop sharing is not supported by the current browser
  390. * or if it was disabled through lib-jitsi-meet specific options (check
  391. * config.js for listed options).
  392. */
  393. isDesktopSharingEnabled: false,
  394. /**
  395. * Set to <tt>true</tt> if the desktop sharing functionality has been
  396. * explicitly disabled in the config.
  397. */
  398. isDesktopSharingDisabledByConfig: false,
  399. /**
  400. * The text displayed when the desktop sharing button is disabled through
  401. * the config. The value is set through
  402. * {@link interfaceConfig.DESKTOP_SHARING_BUTTON_DISABLED_TOOLTIP}.
  403. */
  404. desktopSharingDisabledTooltip: null,
  405. /*
  406. * Whether the local "raisedHand" flag is on.
  407. */
  408. isHandRaised: false,
  409. /*
  410. * Whether the local participant is the dominant speaker in the conference.
  411. */
  412. isDominantSpeaker: false,
  413. /**
  414. * The local audio track (if any).
  415. * FIXME tracks from redux store should be the single source of truth
  416. * @type {JitsiLocalTrack|null}
  417. */
  418. localAudio: null,
  419. /**
  420. * The local video track (if any).
  421. * FIXME tracks from redux store should be the single source of truth, but
  422. * more refactoring is required around screen sharing ('localVideo' usages).
  423. * @type {JitsiLocalTrack|null}
  424. */
  425. localVideo: null,
  426. /**
  427. * Creates local media tracks and connects to a room. Will show error
  428. * dialogs in case accessing the local microphone and/or camera failed. Will
  429. * show guidance overlay for users on how to give access to camera and/or
  430. * microphone.
  431. * @param {string} roomName
  432. * @param {object} options
  433. * @param {boolean} options.startAudioOnly=false - if <tt>true</tt> then
  434. * only audio track will be created and the audio only mode will be turned
  435. * on.
  436. * @param {boolean} options.startScreenSharing=false - if <tt>true</tt>
  437. * should start with screensharing instead of camera video.
  438. * @param {boolean} options.startWithAudioMuted - will start the conference
  439. * without any audio tracks.
  440. * @param {boolean} options.startWithVideoMuted - will start the conference
  441. * without any video tracks.
  442. * @returns {Promise.<JitsiLocalTrack[], JitsiConnection>}
  443. */
  444. createInitialLocalTracksAndConnect(roomName, options = {}) {
  445. let audioAndVideoError,
  446. audioOnlyError,
  447. screenSharingError,
  448. videoOnlyError;
  449. const initialDevices = [];
  450. let requestedAudio = false;
  451. let requestedVideo = false;
  452. if (!options.startWithAudioMuted) {
  453. initialDevices.push('audio');
  454. requestedAudio = true;
  455. }
  456. if (!options.startWithVideoMuted
  457. && !options.startAudioOnly
  458. && !options.startScreenSharing) {
  459. initialDevices.push('video');
  460. requestedVideo = true;
  461. }
  462. JitsiMeetJS.mediaDevices.addEventListener(
  463. JitsiMeetJS.events.mediaDevices.PERMISSION_PROMPT_IS_SHOWN,
  464. browser =>
  465. APP.store.dispatch(
  466. mediaPermissionPromptVisibilityChanged(true, browser))
  467. );
  468. let tryCreateLocalTracks;
  469. // Enable audio only mode
  470. if (config.startAudioOnly) {
  471. APP.store.dispatch(toggleAudioOnly());
  472. }
  473. // FIXME is there any simpler way to rewrite this spaghetti below ?
  474. if (options.startScreenSharing) {
  475. tryCreateLocalTracks = this._createDesktopTrack()
  476. .then(desktopStream => {
  477. if (!requestedAudio) {
  478. return [desktopStream];
  479. }
  480. return createLocalTracksF({ devices: ['audio'] }, true)
  481. .then(([audioStream]) => {
  482. return [desktopStream, audioStream];
  483. })
  484. .catch(error => {
  485. audioOnlyError = error;
  486. return [desktopStream];
  487. });
  488. }).catch(error => {
  489. logger.error('Failed to obtain desktop stream', error);
  490. screenSharingError = error;
  491. return requestedAudio
  492. ? createLocalTracksF({ devices: ['audio'] }, true)
  493. : [];
  494. }).catch(error => {
  495. audioOnlyError = error;
  496. return [];
  497. });
  498. } else if (!requestedAudio && !requestedVideo) {
  499. // Resolve with no tracks
  500. tryCreateLocalTracks = Promise.resolve([]);
  501. } else {
  502. tryCreateLocalTracks = createLocalTracksF(
  503. { devices: initialDevices }, true)
  504. .catch(err => {
  505. if (requestedAudio && requestedVideo) {
  506. // Try audio only...
  507. audioAndVideoError = err;
  508. return createLocalTracksF({devices: ['audio']}, true);
  509. } else if (requestedAudio && !requestedVideo) {
  510. audioOnlyError = err;
  511. return [];
  512. } else if (requestedVideo && !requestedAudio) {
  513. videoOnlyError = err;
  514. return [];
  515. }
  516. logger.error('Should never happen');
  517. }).catch(err => {
  518. // Log this just in case...
  519. if (!requestedAudio) {
  520. logger.error('The impossible just happened', err);
  521. }
  522. audioOnlyError = err;
  523. // Try video only...
  524. return requestedVideo
  525. ? createLocalTracksF({devices: ['video']}, true)
  526. : [];
  527. })
  528. .catch(err => {
  529. // Log this just in case...
  530. if (!requestedVideo) {
  531. logger.error('The impossible just happened', err);
  532. }
  533. videoOnlyError = err;
  534. return [];
  535. });
  536. }
  537. return Promise.all([ tryCreateLocalTracks, connect(roomName) ])
  538. .then(([tracks, con]) => {
  539. APP.store.dispatch(
  540. mediaPermissionPromptVisibilityChanged(false));
  541. // FIXME If there will be microphone error it will cover any
  542. // screensharing dialog, but it's still better than in
  543. // the reverse order where the screensharing dialog will
  544. // sometimes be closing the microphone alert ($.prompt.close();
  545. // is called). Need to figure out dialogs chaining to fix that.
  546. if (screenSharingError) {
  547. this._handleScreenSharingError(screenSharingError);
  548. }
  549. if (audioAndVideoError || audioOnlyError) {
  550. if (audioOnlyError || videoOnlyError) {
  551. // If both requests for 'audio' + 'video' and 'audio'
  552. // only failed, we assume that there are some problems
  553. // with user's microphone and show corresponding dialog.
  554. APP.UI.showMicErrorNotification(audioOnlyError);
  555. APP.UI.showCameraErrorNotification(videoOnlyError);
  556. } else {
  557. // If request for 'audio' + 'video' failed, but request
  558. // for 'audio' only was OK, we assume that we had
  559. // problems with camera and show corresponding dialog.
  560. APP.UI.showCameraErrorNotification(audioAndVideoError);
  561. }
  562. }
  563. return [tracks, con];
  564. });
  565. },
  566. /**
  567. * Open new connection and join to the conference.
  568. * @param {object} options
  569. * @param {string} roomName name of the conference
  570. * @returns {Promise}
  571. */
  572. init(options) {
  573. this.roomName = options.roomName;
  574. // attaches global error handler, if there is already one, respect it
  575. if (JitsiMeetJS.getGlobalOnErrorHandler){
  576. var oldOnErrorHandler = window.onerror;
  577. window.onerror = function (message, source, lineno, colno, error) {
  578. JitsiMeetJS.getGlobalOnErrorHandler(
  579. message, source, lineno, colno, error);
  580. if (oldOnErrorHandler)
  581. oldOnErrorHandler(message, source, lineno, colno, error);
  582. };
  583. var oldOnUnhandledRejection = window.onunhandledrejection;
  584. window.onunhandledrejection = function(event) {
  585. JitsiMeetJS.getGlobalOnErrorHandler(
  586. null, null, null, null, event.reason);
  587. if (oldOnUnhandledRejection)
  588. oldOnUnhandledRejection(event);
  589. };
  590. }
  591. return JitsiMeetJS.init(
  592. Object.assign({
  593. enableAnalyticsLogging: isAnalyticsEnabled(APP.store)
  594. },
  595. config)
  596. ).then(() => {
  597. initAnalytics(APP.store);
  598. return this.createInitialLocalTracksAndConnect(
  599. options.roomName, {
  600. startAudioOnly: config.startAudioOnly,
  601. startScreenSharing: config.startScreenSharing,
  602. startWithAudioMuted: config.startWithAudioMuted,
  603. startWithVideoMuted: config.startWithVideoMuted,
  604. });
  605. }).then(([tracks, con]) => {
  606. tracks.forEach(track => {
  607. if (track.isAudioTrack() && this.isLocalAudioMuted()) {
  608. track.mute();
  609. } else if (track.isVideoTrack()
  610. && this.isLocalVideoMuted()) {
  611. track.mute();
  612. }
  613. });
  614. logger.log('initialized with %s local tracks', tracks.length);
  615. this._localTracksInitialized = true;
  616. con.addEventListener(
  617. ConnectionEvents.CONNECTION_FAILED,
  618. _connectionFailedHandler);
  619. APP.connection = connection = con;
  620. // Desktop sharing related stuff:
  621. this.isDesktopSharingDisabledByConfig
  622. = config.disableDesktopSharing;
  623. this.isDesktopSharingEnabled
  624. = !this.isDesktopSharingDisabledByConfig
  625. && JitsiMeetJS.isDesktopSharingEnabled();
  626. this.desktopSharingDisabledTooltip
  627. = interfaceConfig.DESKTOP_SHARING_BUTTON_DISABLED_TOOLTIP;
  628. eventEmitter.emit(
  629. JitsiMeetConferenceEvents.DESKTOP_SHARING_ENABLED_CHANGED,
  630. this.isDesktopSharingEnabled);
  631. APP.store.dispatch(showDesktopSharingButton());
  632. this._createRoom(tracks);
  633. APP.remoteControl.init();
  634. // if user didn't give access to mic or camera or doesn't have
  635. // them at all, we mark corresponding toolbar buttons as muted,
  636. // so that the user can try unmute later on and add audio/video
  637. // to the conference
  638. if (!tracks.find((t) => t.isAudioTrack())) {
  639. this.setAudioMuteStatus(true);
  640. }
  641. if (!tracks.find((t) => t.isVideoTrack())) {
  642. this.setVideoMuteStatus(true);
  643. }
  644. this._initDeviceList();
  645. if (config.iAmRecorder)
  646. this.recorder = new Recorder();
  647. // XXX The API will take care of disconnecting from the XMPP
  648. // server (and, thus, leaving the room) on unload.
  649. return new Promise((resolve, reject) => {
  650. (new ConferenceConnector(resolve, reject)).connect();
  651. });
  652. });
  653. },
  654. /**
  655. * Check if id is id of the local user.
  656. * @param {string} id id to check
  657. * @returns {boolean}
  658. */
  659. isLocalId(id) {
  660. return this.getMyUserId() === id;
  661. },
  662. /**
  663. * Tells whether the local video is muted or not.
  664. * @return {boolean}
  665. */
  666. isLocalVideoMuted() {
  667. // If the tracks are not ready, read from base/media state
  668. return this._localTracksInitialized
  669. ? isLocalTrackMuted(
  670. APP.store.getState()['features/base/tracks'],
  671. MEDIA_TYPE.VIDEO)
  672. : isVideoMutedByUser(APP.store);
  673. },
  674. /**
  675. * Simulates toolbar button click for audio mute. Used by shortcuts and API.
  676. * @param {boolean} mute true for mute and false for unmute.
  677. * @param {boolean} [showUI] when set to false will not display any error
  678. * dialogs in case of media permissions error.
  679. */
  680. muteAudio(mute, showUI = true) {
  681. // Not ready to modify track's state yet
  682. if (!this._localTracksInitialized) {
  683. // This will only modify base/media.audio.muted which is then synced
  684. // up with the track at the end of local tracks initialization.
  685. muteLocalAudio(mute);
  686. this.setAudioMuteStatus(mute);
  687. return;
  688. } else if (this.isLocalAudioMuted() === mute) {
  689. // NO-OP
  690. return;
  691. }
  692. if (!this.localAudio && !mute) {
  693. const maybeShowErrorDialog = error => {
  694. showUI && APP.UI.showMicErrorNotification(error);
  695. };
  696. createLocalTracksF({ devices: ['audio'] }, false)
  697. .then(([audioTrack]) => audioTrack)
  698. .catch(error => {
  699. maybeShowErrorDialog(error);
  700. // Rollback the audio muted status by using null track
  701. return null;
  702. })
  703. .then(audioTrack => this.useAudioStream(audioTrack));
  704. } else {
  705. muteLocalAudio(mute);
  706. }
  707. },
  708. /**
  709. * Returns whether local audio is muted or not.
  710. * @returns {boolean}
  711. */
  712. isLocalAudioMuted() {
  713. // If the tracks are not ready, read from base/media state
  714. return this._localTracksInitialized
  715. ? isLocalTrackMuted(
  716. APP.store.getState()['features/base/tracks'],
  717. MEDIA_TYPE.AUDIO)
  718. : Boolean(
  719. APP.store.getState()['features/base/media'].audio.muted);
  720. },
  721. /**
  722. * Simulates toolbar button click for audio mute. Used by shortcuts
  723. * and API.
  724. * @param {boolean} [showUI] when set to false will not display any error
  725. * dialogs in case of media permissions error.
  726. */
  727. toggleAudioMuted(showUI = true) {
  728. this.muteAudio(!this.isLocalAudioMuted(), showUI);
  729. },
  730. /**
  731. * Simulates toolbar button click for video mute. Used by shortcuts and API.
  732. * @param mute true for mute and false for unmute.
  733. * @param {boolean} [showUI] when set to false will not display any error
  734. * dialogs in case of media permissions error.
  735. */
  736. muteVideo(mute, showUI = true) {
  737. // If not ready to modify track's state yet adjust the base/media
  738. if (!this._localTracksInitialized) {
  739. // This will only modify base/media.video.muted which is then synced
  740. // up with the track at the end of local tracks initialization.
  741. muteLocalVideo(mute);
  742. this.setVideoMuteStatus(mute);
  743. return;
  744. } else if (this.isLocalVideoMuted() === mute) {
  745. // NO-OP
  746. return;
  747. }
  748. // FIXME it is possible to queue this task twice, but it's not causing
  749. // any issues. Specifically this can happen when the previous
  750. // get user media call is blocked on "ask user for permissions" dialog.
  751. if (!this.localVideo && !mute) {
  752. const maybeShowErrorDialog = error => {
  753. showUI && APP.UI.showCameraErrorNotification(error);
  754. };
  755. // Try to create local video if there wasn't any.
  756. // This handles the case when user joined with no video
  757. // (dismissed screen sharing screen or in audio only mode), but
  758. // decided to add it later on by clicking on muted video icon or
  759. // turning off the audio only mode.
  760. //
  761. // FIXME when local track creation is moved to react/redux
  762. // it should take care of the use case described above
  763. createLocalTracksF({ devices: ['video'] }, false)
  764. .then(([videoTrack]) => videoTrack)
  765. .catch(error => {
  766. // FIXME should send some feedback to the API on error ?
  767. maybeShowErrorDialog(error);
  768. // Rollback the video muted status by using null track
  769. return null;
  770. })
  771. .then(videoTrack => this.useVideoStream(videoTrack));
  772. } else {
  773. // FIXME show error dialog if it fails (should be handled by react)
  774. muteLocalVideo(mute);
  775. }
  776. },
  777. /**
  778. * Simulates toolbar button click for video mute. Used by shortcuts and API.
  779. * @param {boolean} [showUI] when set to false will not display any error
  780. * dialogs in case of media permissions error.
  781. */
  782. toggleVideoMuted(showUI = true) {
  783. this.muteVideo(!this.isLocalVideoMuted(), showUI);
  784. },
  785. /**
  786. * Retrieve list of conference participants (without local user).
  787. * @returns {JitsiParticipant[]}
  788. */
  789. listMembers() {
  790. return room.getParticipants();
  791. },
  792. /**
  793. * Retrieve list of ids of conference participants (without local user).
  794. * @returns {string[]}
  795. */
  796. listMembersIds() {
  797. return room.getParticipants().map(p => p.getId());
  798. },
  799. /**
  800. * Checks whether the participant identified by id is a moderator.
  801. * @id id to search for participant
  802. * @return {boolean} whether the participant is moderator
  803. */
  804. isParticipantModerator(id) {
  805. let user = room.getParticipantById(id);
  806. return user && user.isModerator();
  807. },
  808. /**
  809. * Check if SIP is supported.
  810. * @returns {boolean}
  811. */
  812. sipGatewayEnabled() {
  813. return room.isSIPCallingSupported();
  814. },
  815. get membersCount() {
  816. return room.getParticipants().length + 1;
  817. },
  818. /**
  819. * Returns true if the callstats integration is enabled, otherwise returns
  820. * false.
  821. *
  822. * @returns true if the callstats integration is enabled, otherwise returns
  823. * false.
  824. */
  825. isCallstatsEnabled() {
  826. return room && room.isCallstatsEnabled();
  827. },
  828. /**
  829. * Sends the given feedback through CallStats if enabled.
  830. *
  831. * @param overallFeedback an integer between 1 and 5 indicating the
  832. * user feedback
  833. * @param detailedFeedback detailed feedback from the user. Not yet used
  834. */
  835. sendFeedback(overallFeedback, detailedFeedback) {
  836. return room.sendFeedback (overallFeedback, detailedFeedback);
  837. },
  838. /**
  839. * Get speaker stats that track total dominant speaker time.
  840. *
  841. * @returns {object} A hash with keys being user ids and values being the
  842. * library's SpeakerStats model used for calculating time as dominant
  843. * speaker.
  844. */
  845. getSpeakerStats() {
  846. return room.getSpeakerStats();
  847. },
  848. /**
  849. * Returns the connection times stored in the library.
  850. */
  851. getConnectionTimes() {
  852. return this._room.getConnectionTimes();
  853. },
  854. // used by torture currently
  855. isJoined() {
  856. return this._room
  857. && this._room.isJoined();
  858. },
  859. getConnectionState() {
  860. return this._room
  861. && this._room.getConnectionState();
  862. },
  863. /**
  864. * Obtains current P2P ICE connection state.
  865. * @return {string|null} ICE connection state or <tt>null</tt> if there's no
  866. * P2P connection
  867. */
  868. getP2PConnectionState() {
  869. return this._room
  870. && this._room.getP2PConnectionState();
  871. },
  872. /**
  873. * Starts P2P (for tests only)
  874. * @private
  875. */
  876. _startP2P() {
  877. try {
  878. this._room && this._room.startP2PSession();
  879. } catch (error) {
  880. logger.error("Start P2P failed", error);
  881. throw error;
  882. }
  883. },
  884. /**
  885. * Stops P2P (for tests only)
  886. * @private
  887. */
  888. _stopP2P() {
  889. try {
  890. this._room && this._room.stopP2PSession();
  891. } catch (error) {
  892. logger.error("Stop P2P failed", error);
  893. throw error;
  894. }
  895. },
  896. /**
  897. * Checks whether or not our connection is currently in interrupted and
  898. * reconnect attempts are in progress.
  899. *
  900. * @returns {boolean} true if the connection is in interrupted state or
  901. * false otherwise.
  902. */
  903. isConnectionInterrupted() {
  904. return this._room.isConnectionInterrupted();
  905. },
  906. /**
  907. * Finds JitsiParticipant for given id.
  908. *
  909. * @param {string} id participant's identifier(MUC nickname).
  910. *
  911. * @returns {JitsiParticipant|null} participant instance for given id or
  912. * null if not found.
  913. */
  914. getParticipantById(id) {
  915. return room ? room.getParticipantById(id) : null;
  916. },
  917. /**
  918. * Get participant connection status for the participant.
  919. *
  920. * @param {string} id participant's identifier(MUC nickname)
  921. *
  922. * @returns {ParticipantConnectionStatus|null} the status of the participant
  923. * or null if no such participant is found or participant is the local user.
  924. */
  925. getParticipantConnectionStatus(id) {
  926. let participant = this.getParticipantById(id);
  927. return participant ? participant.getConnectionStatus() : null;
  928. },
  929. /**
  930. * Gets the display name foe the <tt>JitsiParticipant</tt> identified by
  931. * the given <tt>id</tt>.
  932. *
  933. * @param id {string} the participant's id(MUC nickname/JVB endpoint id)
  934. *
  935. * @return {string} the participant's display name or the default string if
  936. * absent.
  937. */
  938. getParticipantDisplayName(id) {
  939. let displayName = getDisplayName(id);
  940. if (displayName) {
  941. return displayName;
  942. } else {
  943. if (APP.conference.isLocalId(id)) {
  944. return APP.translation.generateTranslationHTML(
  945. interfaceConfig.DEFAULT_LOCAL_DISPLAY_NAME);
  946. } else {
  947. return interfaceConfig.DEFAULT_REMOTE_DISPLAY_NAME;
  948. }
  949. }
  950. },
  951. getMyUserId() {
  952. return this._room
  953. && this._room.myUserId();
  954. },
  955. /**
  956. * Indicates if recording is supported in this conference.
  957. */
  958. isRecordingSupported() {
  959. return this._room && this._room.isRecordingSupported();
  960. },
  961. /**
  962. * Returns the recording state or undefined if the room is not defined.
  963. */
  964. getRecordingState() {
  965. return (this._room) ? this._room.getRecordingState() : undefined;
  966. },
  967. /**
  968. * Will be filled with values only when config.debug is enabled.
  969. * Its used by torture to check audio levels.
  970. */
  971. audioLevelsMap: {},
  972. /**
  973. * Returns the stored audio level (stored only if config.debug is enabled)
  974. * @param id the id for the user audio level to return (the id value is
  975. * returned for the participant using getMyUserId() method)
  976. */
  977. getPeerSSRCAudioLevel(id) {
  978. return this.audioLevelsMap[id];
  979. },
  980. /**
  981. * @return {number} the number of participants in the conference with at
  982. * least one track.
  983. */
  984. getNumberOfParticipantsWithTracks() {
  985. return this._room.getParticipants()
  986. .filter((p) => p.getTracks().length > 0)
  987. .length;
  988. },
  989. /**
  990. * Returns the stats.
  991. */
  992. getStats() {
  993. return room.connectionQuality.getStats();
  994. },
  995. // end used by torture
  996. getLogs() {
  997. return room.getLogs();
  998. },
  999. /**
  1000. * Download logs, a function that can be called from console while
  1001. * debugging.
  1002. * @param filename (optional) specify target filename
  1003. */
  1004. saveLogs(filename = 'meetlog.json') {
  1005. // this can be called from console and will not have reference to this
  1006. // that's why we reference the global var
  1007. let logs = APP.conference.getLogs();
  1008. let data = encodeURIComponent(JSON.stringify(logs, null, ' '));
  1009. let elem = document.createElement('a');
  1010. elem.download = filename;
  1011. elem.href = 'data:application/json;charset=utf-8,\n' + data;
  1012. elem.dataset.downloadurl
  1013. = ['text/json', elem.download, elem.href].join(':');
  1014. elem.dispatchEvent(new MouseEvent('click', {
  1015. view: window,
  1016. bubbles: true,
  1017. cancelable: false
  1018. }));
  1019. },
  1020. /**
  1021. * Exposes a Command(s) API on this instance. It is necessitated by (1) the
  1022. * desire to keep room private to this instance and (2) the need of other
  1023. * modules to send and receive commands to and from participants.
  1024. * Eventually, this instance remains in control with respect to the
  1025. * decision whether the Command(s) API of room (i.e. lib-jitsi-meet's
  1026. * JitsiConference) is to be used in the implementation of the Command(s)
  1027. * API of this instance.
  1028. */
  1029. commands: {
  1030. /**
  1031. * Known custom conference commands.
  1032. */
  1033. defaults: commands,
  1034. /**
  1035. * Receives notifications from other participants about commands aka
  1036. * custom events (sent by sendCommand or sendCommandOnce methods).
  1037. * @param command {String} the name of the command
  1038. * @param handler {Function} handler for the command
  1039. */
  1040. addCommandListener () {
  1041. room.addCommandListener.apply(room, arguments);
  1042. },
  1043. /**
  1044. * Removes command.
  1045. * @param name {String} the name of the command.
  1046. */
  1047. removeCommand () {
  1048. room.removeCommand.apply(room, arguments);
  1049. },
  1050. /**
  1051. * Sends command.
  1052. * @param name {String} the name of the command.
  1053. * @param values {Object} with keys and values that will be sent.
  1054. */
  1055. sendCommand () {
  1056. room.sendCommand.apply(room, arguments);
  1057. },
  1058. /**
  1059. * Sends command one time.
  1060. * @param name {String} the name of the command.
  1061. * @param values {Object} with keys and values that will be sent.
  1062. */
  1063. sendCommandOnce () {
  1064. room.sendCommandOnce.apply(room, arguments);
  1065. }
  1066. },
  1067. _createRoom (localTracks) {
  1068. room = connection.initJitsiConference(APP.conference.roomName,
  1069. this._getConferenceOptions());
  1070. this._setLocalAudioVideoStreams(localTracks);
  1071. this._room = room; // FIXME do not use this
  1072. _setupLocalParticipantProperties();
  1073. this._setupListeners();
  1074. },
  1075. /**
  1076. * Sets local video and audio streams.
  1077. * @param {JitsiLocalTrack[]} tracks=[]
  1078. * @returns {Promise[]}
  1079. * @private
  1080. */
  1081. _setLocalAudioVideoStreams(tracks = []) {
  1082. return tracks.map(track => {
  1083. if (track.isAudioTrack()) {
  1084. return this.useAudioStream(track);
  1085. } else if (track.isVideoTrack()) {
  1086. return this.useVideoStream(track);
  1087. } else {
  1088. logger.error(
  1089. "Ignored not an audio nor a video track: ", track);
  1090. return Promise.resolve();
  1091. }
  1092. });
  1093. },
  1094. _getConferenceOptions() {
  1095. let options = config;
  1096. if (config.enableRecording && !config.recordingType) {
  1097. options.recordingType = (config.hosts &&
  1098. (typeof config.hosts.jirecon != "undefined"))?
  1099. "jirecon" : "colibri";
  1100. }
  1101. return options;
  1102. },
  1103. /**
  1104. * Start using provided video stream.
  1105. * Stops previous video stream.
  1106. * @param {JitsiLocalTrack} [stream] new stream to use or null
  1107. * @returns {Promise}
  1108. */
  1109. useVideoStream(newStream) {
  1110. return APP.store.dispatch(
  1111. replaceLocalTrack(this.localVideo, newStream, room))
  1112. .then(() => {
  1113. this.localVideo = newStream;
  1114. if (newStream) {
  1115. this.isSharingScreen = newStream.videoType === 'desktop';
  1116. APP.UI.addLocalStream(newStream);
  1117. } else {
  1118. this.isSharingScreen = false;
  1119. }
  1120. this.setVideoMuteStatus(this.isLocalVideoMuted());
  1121. APP.UI.updateDesktopSharingButtons();
  1122. });
  1123. },
  1124. /**
  1125. * Start using provided audio stream.
  1126. * Stops previous audio stream.
  1127. * @param {JitsiLocalTrack} [stream] new stream to use or null
  1128. * @returns {Promise}
  1129. */
  1130. useAudioStream(newStream) {
  1131. return APP.store.dispatch(
  1132. replaceLocalTrack(this.localAudio, newStream, room))
  1133. .then(() => {
  1134. this.localAudio = newStream;
  1135. if (newStream) {
  1136. APP.UI.addLocalStream(newStream);
  1137. }
  1138. this.setAudioMuteStatus(this.isLocalAudioMuted());
  1139. });
  1140. },
  1141. /**
  1142. * Triggers a tooltip to display when a feature was attempted to be used
  1143. * while in audio only mode.
  1144. *
  1145. * @param {string} featureName - The name of the feature that attempted to
  1146. * toggle.
  1147. * @private
  1148. * @returns {void}
  1149. */
  1150. _displayAudioOnlyTooltip(featureName) {
  1151. let buttonName = null;
  1152. let tooltipElementId = null;
  1153. switch (featureName) {
  1154. case 'screenShare':
  1155. buttonName = 'desktop';
  1156. tooltipElementId = 'screenshareWhileAudioOnly';
  1157. break;
  1158. case 'videoMute':
  1159. buttonName = 'camera';
  1160. tooltipElementId = 'unmuteWhileAudioOnly';
  1161. break;
  1162. }
  1163. if (tooltipElementId) {
  1164. APP.UI.showToolbar(6000);
  1165. APP.UI.showCustomToolbarPopup(
  1166. buttonName, tooltipElementId, true, 5000);
  1167. }
  1168. },
  1169. /**
  1170. * Returns whether or not the conference is currently in audio only mode.
  1171. *
  1172. * @returns {boolean}
  1173. */
  1174. isAudioOnly() {
  1175. return Boolean(
  1176. APP.store.getState()['features/base/conference'].audioOnly);
  1177. },
  1178. videoSwitchInProgress: false,
  1179. /**
  1180. * This fields stores a handler which will create a Promise which turns off
  1181. * the screen sharing and restores the previous video state (was there
  1182. * any video, before switching to screen sharing ? was it muted ?).
  1183. *
  1184. * Once called this fields is cleared to <tt>null</tt>.
  1185. * @type {Function|null}
  1186. */
  1187. _untoggleScreenSharing: null,
  1188. /**
  1189. * Creates a Promise which turns off the screen sharing and restores
  1190. * the previous state described by the arguments.
  1191. *
  1192. * This method is bound to the appropriate values, after switching to screen
  1193. * sharing and stored in {@link _untoggleScreenSharing}.
  1194. *
  1195. * @param {boolean} didHaveVideo indicates if there was a camera video being
  1196. * used, before switching to screen sharing.
  1197. * @param {boolean} wasVideoMuted indicates if the video was muted, before
  1198. * switching to screen sharing.
  1199. * @return {Promise} resolved after the screen sharing is turned off, or
  1200. * rejected with some error (no idea what kind of error, possible GUM error)
  1201. * in case it fails.
  1202. * @private
  1203. */
  1204. _turnScreenSharingOff(didHaveVideo, wasVideoMuted) {
  1205. this._untoggleScreenSharing = null;
  1206. this.videoSwitchInProgress = true;
  1207. APP.remoteControl.receiver.stop();
  1208. let promise = null;
  1209. if (didHaveVideo) {
  1210. promise = createLocalTracksF({ devices: ['video'] })
  1211. .then(([stream]) => this.useVideoStream(stream))
  1212. .then(() => {
  1213. JitsiMeetJS.analytics.sendEvent(
  1214. 'conference.sharingDesktop.stop');
  1215. logger.log('switched back to local video');
  1216. if (!this.localVideo && wasVideoMuted) {
  1217. return Promise.reject('No local video to be muted!');
  1218. } else if (wasVideoMuted && this.localVideo) {
  1219. return this.localVideo.mute();
  1220. }
  1221. })
  1222. .catch(error => {
  1223. logger.error('failed to switch back to local video', error);
  1224. return this.useVideoStream(null).then(() => {
  1225. // Still fail with the original err
  1226. return Promise.reject(error);
  1227. });
  1228. });
  1229. } else {
  1230. promise = this.useVideoStream(null);
  1231. }
  1232. return promise.then(
  1233. () => {
  1234. this.videoSwitchInProgress = false;
  1235. },
  1236. error => {
  1237. this.videoSwitchInProgress = false;
  1238. throw error;
  1239. });
  1240. },
  1241. /**
  1242. * Toggles between screen sharing and camera video if the toggle parameter
  1243. * is not specified and starts the procedure for obtaining new screen
  1244. * sharing/video track otherwise.
  1245. *
  1246. * @param {boolean} [toggle] - If true - new screen sharing track will be
  1247. * obtained. If false - new video track will be obtain. If not specified -
  1248. * toggles between screen sharing and camera video.
  1249. * @param {Object} [options] - Screen sharing options that will be passed to
  1250. * createLocalTracks.
  1251. * @param {Array<string>} [options.desktopSharingSources] - Array with the
  1252. * sources that have to be displayed in the desktop picker window ('screen',
  1253. * 'window', etc.).
  1254. * @return {Promise.<T>}
  1255. */
  1256. toggleScreenSharing(toggle = !this._untoggleScreenSharing, options = {}) {
  1257. if (this.videoSwitchInProgress) {
  1258. return Promise.reject('Switch in progress.');
  1259. }
  1260. if (!this.isDesktopSharingEnabled) {
  1261. return Promise.reject(
  1262. 'Cannot toggle screen sharing: not supported.');
  1263. }
  1264. if (this.isAudioOnly()) {
  1265. this._displayAudioOnlyTooltip('screenShare');
  1266. return Promise.reject('No screensharing in audio only mode');
  1267. }
  1268. if (toggle) {
  1269. return this._switchToScreenSharing(options);
  1270. } else {
  1271. return this._untoggleScreenSharing();
  1272. }
  1273. },
  1274. /**
  1275. * Creates desktop (screensharing) {@link JitsiLocalTrack}
  1276. * @param {Object} [options] - Screen sharing options that will be passed to
  1277. * createLocalTracks.
  1278. *
  1279. * @return {Promise.<JitsiLocalTrack>} - A Promise resolved with
  1280. * {@link JitsiLocalTrack} for the screensharing or rejected with
  1281. * {@link JitsiTrackError}.
  1282. *
  1283. * @private
  1284. */
  1285. _createDesktopTrack(options = {}) {
  1286. let externalInstallation = false;
  1287. let DSExternalInstallationInProgress = false;
  1288. const didHaveVideo = Boolean(this.localVideo);
  1289. const wasVideoMuted = this.isLocalVideoMuted();
  1290. return createLocalTracksF({
  1291. desktopSharingSources: options.desktopSharingSources,
  1292. devices: ['desktop'],
  1293. desktopSharingExtensionExternalInstallation: {
  1294. interval: 500,
  1295. checkAgain: () => DSExternalInstallationInProgress,
  1296. listener: (status, url) => {
  1297. switch(status) {
  1298. case "waitingForExtension": {
  1299. DSExternalInstallationInProgress = true;
  1300. externalInstallation = true;
  1301. const listener = () => {
  1302. // Wait a little bit more just to be sure that we
  1303. // won't miss the extension installation
  1304. setTimeout(
  1305. () => {
  1306. DSExternalInstallationInProgress = false;
  1307. },
  1308. 500);
  1309. APP.UI.removeListener(
  1310. UIEvents.EXTERNAL_INSTALLATION_CANCELED,
  1311. listener);
  1312. };
  1313. APP.UI.addListener(
  1314. UIEvents.EXTERNAL_INSTALLATION_CANCELED,
  1315. listener);
  1316. APP.UI.showExtensionExternalInstallationDialog(url);
  1317. break;
  1318. }
  1319. case "extensionFound":
  1320. // Close the dialog.
  1321. externalInstallation && $.prompt.close();
  1322. break;
  1323. default:
  1324. // Unknown status
  1325. }
  1326. }
  1327. }
  1328. }).then(([desktopStream]) => {
  1329. // Stores the "untoggle" handler which remembers whether was
  1330. // there any video before and whether was it muted.
  1331. this._untoggleScreenSharing
  1332. = this._turnScreenSharingOff
  1333. .bind(this, didHaveVideo, wasVideoMuted);
  1334. desktopStream.on(
  1335. TrackEvents.LOCAL_TRACK_STOPPED,
  1336. () => {
  1337. // If the stream was stopped during screen sharing
  1338. // session then we should switch back to video.
  1339. this.isSharingScreen
  1340. && this._untoggleScreenSharing
  1341. && this._untoggleScreenSharing();
  1342. }
  1343. );
  1344. // close external installation dialog on success.
  1345. externalInstallation && $.prompt.close();
  1346. return desktopStream;
  1347. }, error => {
  1348. DSExternalInstallationInProgress = false;
  1349. // close external installation dialog on success.
  1350. externalInstallation && $.prompt.close();
  1351. throw error;
  1352. });
  1353. },
  1354. /**
  1355. * Tries to switch to the screenshairng mode by disposing camera stream and
  1356. * replacing it with a desktop one.
  1357. *
  1358. * @param {Object} [options] - Screen sharing options that will be passed to
  1359. * createLocalTracks.
  1360. *
  1361. * @return {Promise} - A Promise resolved if the operation succeeds or
  1362. * rejected with some unknown type of error in case it fails. Promise will
  1363. * be rejected immediately if {@link videoSwitchInProgress} is true.
  1364. *
  1365. * @private
  1366. */
  1367. _switchToScreenSharing(options = {}) {
  1368. if (this.videoSwitchInProgress) {
  1369. return Promise.reject('Switch in progress.');
  1370. }
  1371. this.videoSwitchInProgress = true;
  1372. return this._createDesktopTrack(options).then(stream => {
  1373. return this.useVideoStream(stream);
  1374. }).then(() => {
  1375. this.videoSwitchInProgress = false;
  1376. JitsiMeetJS.analytics.sendEvent('conference.sharingDesktop.start');
  1377. logger.log('sharing local desktop');
  1378. }).catch(error => {
  1379. this.videoSwitchInProgress = false;
  1380. // Pawel: With this call I'm trying to preserve the original
  1381. // behaviour although it is not clear why would we "untoggle"
  1382. // on failure. I suppose it was to restore video in case there
  1383. // was some problem during "this.useVideoStream(desktopStream)".
  1384. // It's important to note that the handler will not be available
  1385. // if we fail early on trying to get desktop media (which makes
  1386. // sense, because the camera video is still being used, so
  1387. // nothing to "untoggle").
  1388. if (this._untoggleScreenSharing) {
  1389. this._untoggleScreenSharing();
  1390. }
  1391. // FIXME the code inside of _handleScreenSharingError is
  1392. // asynchronous, but does not return a Promise and is not part of
  1393. // the current Promise chain.
  1394. this._handleScreenSharingError(error);
  1395. return Promise.reject(error);
  1396. });
  1397. },
  1398. /**
  1399. * Handles {@link JitsiTrackError} returned by the lib-jitsi-meet when
  1400. * trying to create screensharing track. It will either do nothing if
  1401. * the dialog was canceled on user's request or display inline installation
  1402. * dialog and ask the user to install the extension, once the extension is
  1403. * installed it will switch the conference to screensharing. The last option
  1404. * is that an unrecoverable error dialog will be displayed.
  1405. * @param {JitsiTrackError} error - The error returned by
  1406. * {@link _createDesktopTrack} Promise.
  1407. * @private
  1408. */
  1409. _handleScreenSharingError(error) {
  1410. if (error.name === TrackErrors.CHROME_EXTENSION_USER_CANCELED) {
  1411. return;
  1412. }
  1413. logger.error('failed to share local desktop', error);
  1414. if (error.name === TrackErrors.CHROME_EXTENSION_USER_GESTURE_REQUIRED) {
  1415. // If start with screen sharing the extension will fail to install
  1416. // (if not found), because the request has been triggered by the
  1417. // script. Show a dialog which asks user to click "install" and try
  1418. // again switching to the screen sharing.
  1419. APP.UI.showExtensionInlineInstallationDialog(
  1420. () => {
  1421. this.toggleScreenSharing().catch(() => {});
  1422. }
  1423. );
  1424. return;
  1425. } else if (error.name === TrackErrors.FIREFOX_EXTENSION_NEEDED) {
  1426. APP.UI.showExtensionRequiredDialog(
  1427. config.desktopSharingFirefoxExtensionURL
  1428. );
  1429. return;
  1430. }
  1431. // Handling:
  1432. // TrackErrors.PERMISSION_DENIED
  1433. // TrackErrors.CHROME_EXTENSION_INSTALLATION_ERROR
  1434. // TrackErrors.GENERAL
  1435. // and any other
  1436. let dialogTxt;
  1437. let dialogTitleKey;
  1438. if (error.name === TrackErrors.PERMISSION_DENIED) {
  1439. dialogTxt = APP.translation.generateTranslationHTML(
  1440. "dialog.screenSharingPermissionDeniedError");
  1441. dialogTitleKey = "dialog.error";
  1442. } else {
  1443. dialogTxt = APP.translation.generateTranslationHTML(
  1444. "dialog.failtoinstall");
  1445. dialogTitleKey = "dialog.permissionDenied";
  1446. }
  1447. APP.UI.messageHandler.openDialog(dialogTitleKey, dialogTxt, false);
  1448. },
  1449. /**
  1450. * Setup interaction between conference and UI.
  1451. */
  1452. _setupListeners() {
  1453. // add local streams when joined to the conference
  1454. room.on(ConferenceEvents.CONFERENCE_JOINED, () => {
  1455. APP.store.dispatch(conferenceJoined(room));
  1456. APP.UI.mucJoined();
  1457. APP.API.notifyConferenceJoined(APP.conference.roomName);
  1458. APP.UI.markVideoInterrupted(false);
  1459. });
  1460. room.on(
  1461. ConferenceEvents.CONFERENCE_LEFT,
  1462. (...args) => APP.store.dispatch(conferenceLeft(room, ...args)));
  1463. room.on(
  1464. ConferenceEvents.AUTH_STATUS_CHANGED,
  1465. (authEnabled, authLogin) =>
  1466. APP.UI.updateAuthInfo(authEnabled, authLogin));
  1467. room.on(ConferenceEvents.PARTCIPANT_FEATURES_CHANGED,
  1468. user => APP.UI.onUserFeaturesChanged(user));
  1469. room.on(ConferenceEvents.USER_JOINED, (id, user) => {
  1470. if (user.isHidden())
  1471. return;
  1472. APP.store.dispatch(participantJoined({
  1473. id,
  1474. name: user.getDisplayName(),
  1475. role: user.getRole()
  1476. }));
  1477. logger.log('USER %s connnected', id, user);
  1478. APP.API.notifyUserJoined(id);
  1479. APP.UI.addUser(user);
  1480. // check the roles for the new user and reflect them
  1481. APP.UI.updateUserRole(user);
  1482. });
  1483. room.on(ConferenceEvents.USER_LEFT, (id, user) => {
  1484. APP.store.dispatch(participantLeft(id, user));
  1485. logger.log('USER %s LEFT', id, user);
  1486. APP.API.notifyUserLeft(id);
  1487. APP.UI.removeUser(id, user.getDisplayName());
  1488. APP.UI.onSharedVideoStop(id);
  1489. });
  1490. room.on(ConferenceEvents.USER_STATUS_CHANGED, (id, status) => {
  1491. APP.store.dispatch(participantPresenceChanged(id, status));
  1492. let user = room.getParticipantById(id);
  1493. if (user) {
  1494. APP.UI.updateUserStatus(user, status);
  1495. }
  1496. });
  1497. room.on(ConferenceEvents.USER_ROLE_CHANGED, (id, role) => {
  1498. if (this.isLocalId(id)) {
  1499. logger.info(`My role changed, new role: ${role}`);
  1500. APP.store.dispatch(localParticipantRoleChanged(role));
  1501. if (this.isModerator !== room.isModerator()) {
  1502. this.isModerator = room.isModerator();
  1503. APP.UI.updateLocalRole(room.isModerator());
  1504. }
  1505. } else {
  1506. APP.store.dispatch(participantRoleChanged(id, role));
  1507. let user = room.getParticipantById(id);
  1508. if (user) {
  1509. APP.UI.updateUserRole(user);
  1510. }
  1511. }
  1512. });
  1513. room.on(ConferenceEvents.TRACK_ADDED, (track) => {
  1514. if (!track || track.isLocal())
  1515. return;
  1516. APP.store.dispatch(trackAdded(track));
  1517. });
  1518. room.on(ConferenceEvents.TRACK_REMOVED, (track) => {
  1519. if (!track || track.isLocal())
  1520. return;
  1521. APP.store.dispatch(trackRemoved(track));
  1522. });
  1523. room.on(ConferenceEvents.TRACK_AUDIO_LEVEL_CHANGED, (id, lvl) => {
  1524. if (this.isLocalId(id)
  1525. && this.localAudio && this.localAudio.isMuted()) {
  1526. lvl = 0;
  1527. }
  1528. if (config.debug) {
  1529. this.audioLevelsMap[id] = lvl;
  1530. if (config.debugAudioLevels)
  1531. logger.log("AudioLevel:" + id + "/" + lvl);
  1532. }
  1533. APP.UI.setAudioLevel(id, lvl);
  1534. });
  1535. room.on(ConferenceEvents.TALK_WHILE_MUTED, () => {
  1536. APP.UI.showToolbar(6000);
  1537. APP.UI.showCustomToolbarPopup(
  1538. 'microphone', 'talkWhileMutedPopup', true, 5000);
  1539. });
  1540. room.on(
  1541. ConferenceEvents.LAST_N_ENDPOINTS_CHANGED,
  1542. (leavingIds, enteringIds) => {
  1543. APP.UI.handleLastNEndpoints(leavingIds, enteringIds);
  1544. });
  1545. room.on(
  1546. ConferenceEvents.P2P_STATUS,
  1547. (jitsiConference, p2p) => {
  1548. APP.store.dispatch(p2pStatusChanged(p2p));
  1549. });
  1550. room.on(
  1551. ConferenceEvents.PARTICIPANT_CONN_STATUS_CHANGED,
  1552. (id, connectionStatus) => {
  1553. APP.store.dispatch(participantConnectionStatusChanged(
  1554. id, connectionStatus));
  1555. APP.UI.participantConnectionStatusChanged(id);
  1556. });
  1557. room.on(ConferenceEvents.DOMINANT_SPEAKER_CHANGED, (id) => {
  1558. APP.store.dispatch(dominantSpeakerChanged(id));
  1559. if (this.isLocalId(id)) {
  1560. this.isDominantSpeaker = true;
  1561. this.setRaisedHand(false);
  1562. } else {
  1563. this.isDominantSpeaker = false;
  1564. var participant = room.getParticipantById(id);
  1565. if (participant) {
  1566. APP.UI.setRaisedHandStatus(participant, false);
  1567. }
  1568. }
  1569. APP.UI.markDominantSpeaker(id);
  1570. });
  1571. if (!interfaceConfig.filmStripOnly) {
  1572. room.on(ConferenceEvents.CONNECTION_INTERRUPTED, () => {
  1573. APP.UI.markVideoInterrupted(true);
  1574. });
  1575. room.on(ConferenceEvents.CONNECTION_RESTORED, () => {
  1576. APP.UI.markVideoInterrupted(false);
  1577. });
  1578. room.on(ConferenceEvents.MESSAGE_RECEIVED, (id, body, ts) => {
  1579. let nick = getDisplayName(id);
  1580. APP.API.notifyReceivedChatMessage({
  1581. id,
  1582. nick,
  1583. body,
  1584. ts
  1585. });
  1586. APP.UI.addMessage(id, nick, body, ts);
  1587. });
  1588. APP.UI.addListener(UIEvents.MESSAGE_CREATED, (message) => {
  1589. APP.API.notifySendingChatMessage(message);
  1590. room.sendTextMessage(message);
  1591. });
  1592. APP.UI.addListener(UIEvents.SELECTED_ENDPOINT, (id) => {
  1593. try {
  1594. // do not try to select participant if there is none (we
  1595. // are alone in the room), otherwise an error will be
  1596. // thrown cause reporting mechanism is not available
  1597. // (datachannels currently)
  1598. if (room.getParticipants().length === 0)
  1599. return;
  1600. room.selectParticipant(id);
  1601. } catch (e) {
  1602. JitsiMeetJS.analytics.sendEvent(
  1603. 'selectParticipant.failed');
  1604. reportError(e);
  1605. }
  1606. });
  1607. APP.UI.addListener(
  1608. UIEvents.VIDEO_UNMUTING_WHILE_AUDIO_ONLY,
  1609. () => this._displayAudioOnlyTooltip('videoMute'));
  1610. }
  1611. room.on(ConferenceEvents.CONNECTION_INTERRUPTED, () => {
  1612. APP.store.dispatch(localParticipantConnectionStatusChanged(
  1613. participantConnectionStatus.INTERRUPTED));
  1614. APP.UI.showLocalConnectionInterrupted(true);
  1615. });
  1616. room.on(ConferenceEvents.CONNECTION_RESTORED, () => {
  1617. APP.store.dispatch(localParticipantConnectionStatusChanged(
  1618. participantConnectionStatus.ACTIVE));
  1619. APP.UI.showLocalConnectionInterrupted(false);
  1620. });
  1621. room.on(ConferenceEvents.DISPLAY_NAME_CHANGED, (id, displayName) => {
  1622. const formattedDisplayName
  1623. = displayName.substr(0, MAX_DISPLAY_NAME_LENGTH);
  1624. APP.store.dispatch(participantUpdated({
  1625. id,
  1626. name: formattedDisplayName
  1627. }));
  1628. APP.API.notifyDisplayNameChanged(id, formattedDisplayName);
  1629. APP.UI.changeDisplayName(id, formattedDisplayName);
  1630. });
  1631. room.on(
  1632. ConferenceEvents.LOCK_STATE_CHANGED,
  1633. (...args) => APP.store.dispatch(lockStateChanged(room, ...args)));
  1634. APP.remoteControl.on(RemoteControlEvents.ACTIVE_CHANGED, isActive => {
  1635. room.setLocalParticipantProperty(
  1636. "remoteControlSessionStatus",
  1637. isActive
  1638. );
  1639. APP.UI.setLocalRemoteControlActiveChanged();
  1640. });
  1641. room.on(ConferenceEvents.PARTICIPANT_PROPERTY_CHANGED,
  1642. (participant, name, oldValue, newValue) => {
  1643. switch (name) {
  1644. case 'raisedHand':
  1645. APP.UI.setRaisedHandStatus(participant, newValue);
  1646. break;
  1647. case 'remoteControlSessionStatus':
  1648. APP.UI.setRemoteControlActiveStatus(
  1649. participant.getId(),
  1650. newValue);
  1651. break;
  1652. default:
  1653. // ignore
  1654. }
  1655. });
  1656. room.on(ConferenceEvents.RECORDER_STATE_CHANGED, (status, error) => {
  1657. logger.log("Received recorder status change: ", status, error);
  1658. APP.UI.updateRecordingState(status);
  1659. });
  1660. room.on(ConferenceEvents.KICKED, () => {
  1661. APP.UI.hideStats();
  1662. APP.UI.notifyKicked();
  1663. // FIXME close
  1664. });
  1665. room.on(ConferenceEvents.SUSPEND_DETECTED, () => {
  1666. APP.store.dispatch(suspendDetected());
  1667. // After wake up, we will be in a state where conference is left
  1668. // there will be dialog shown to user.
  1669. // We do not want video/audio as we show an overlay and after it
  1670. // user need to rejoin or close, while waking up we can detect
  1671. // camera wakeup as a problem with device.
  1672. // We also do not care about device change, which happens
  1673. // on resume after suspending PC.
  1674. if (this.deviceChangeListener)
  1675. JitsiMeetJS.mediaDevices.removeEventListener(
  1676. JitsiMeetJS.events.mediaDevices.DEVICE_LIST_CHANGED,
  1677. this.deviceChangeListener);
  1678. // stop local video
  1679. if (this.localVideo) {
  1680. this.localVideo.dispose();
  1681. this.localVideo = null;
  1682. }
  1683. // stop local audio
  1684. if (this.localAudio) {
  1685. this.localAudio.dispose();
  1686. this.localAudio = null;
  1687. }
  1688. });
  1689. room.on(ConferenceEvents.DTMF_SUPPORT_CHANGED, (isDTMFSupported) => {
  1690. APP.UI.updateDTMFSupport(isDTMFSupported);
  1691. });
  1692. APP.UI.addListener(UIEvents.AUDIO_MUTED, muted => {
  1693. this.muteAudio(muted);
  1694. });
  1695. APP.UI.addListener(UIEvents.VIDEO_MUTED, muted => {
  1696. if (this.isAudioOnly() && !muted) {
  1697. this._displayAudioOnlyTooltip('videoMute');
  1698. } else {
  1699. this.muteVideo(muted);
  1700. }
  1701. });
  1702. statsEmitter.startListeningForStats(room);
  1703. room.addCommandListener(this.commands.defaults.ETHERPAD, ({value}) => {
  1704. APP.UI.initEtherpad(value);
  1705. });
  1706. APP.UI.addListener(UIEvents.EMAIL_CHANGED, this.changeLocalEmail);
  1707. room.addCommandListener(this.commands.defaults.EMAIL, (data, from) => {
  1708. APP.store.dispatch(participantUpdated({
  1709. id: from,
  1710. email: data.value
  1711. }));
  1712. APP.UI.setUserEmail(from, data.value);
  1713. });
  1714. room.addCommandListener(
  1715. this.commands.defaults.AVATAR_URL,
  1716. (data, from) => {
  1717. APP.store.dispatch(
  1718. participantUpdated({
  1719. id: from,
  1720. avatarURL: data.value
  1721. }));
  1722. APP.UI.setUserAvatarUrl(from, data.value);
  1723. });
  1724. room.addCommandListener(this.commands.defaults.AVATAR_ID,
  1725. (data, from) => {
  1726. APP.store.dispatch(
  1727. participantUpdated({
  1728. id: from,
  1729. avatarID: data.value
  1730. }));
  1731. APP.UI.setUserAvatarID(from, data.value);
  1732. });
  1733. APP.UI.addListener(UIEvents.NICKNAME_CHANGED,
  1734. this.changeLocalDisplayName.bind(this));
  1735. APP.UI.addListener(UIEvents.START_MUTED_CHANGED,
  1736. (startAudioMuted, startVideoMuted) => {
  1737. room.setStartMutedPolicy({
  1738. audio: startAudioMuted,
  1739. video: startVideoMuted
  1740. });
  1741. }
  1742. );
  1743. room.on(
  1744. ConferenceEvents.START_MUTED_POLICY_CHANGED,
  1745. ({ audio, video }) => {
  1746. APP.UI.onStartMutedChanged(audio, video);
  1747. }
  1748. );
  1749. room.on(ConferenceEvents.STARTED_MUTED, () => {
  1750. (room.isStartAudioMuted() || room.isStartVideoMuted())
  1751. && APP.UI.notifyInitiallyMuted();
  1752. });
  1753. room.on(
  1754. ConferenceEvents.AVAILABLE_DEVICES_CHANGED, function (id, devices) {
  1755. APP.UI.updateDevicesAvailability(id, devices);
  1756. }
  1757. );
  1758. room.on(
  1759. ConferenceEvents.DATA_CHANNEL_OPENED, () => {
  1760. APP.store.dispatch(dataChannelOpened());
  1761. }
  1762. );
  1763. // call hangup
  1764. APP.UI.addListener(UIEvents.HANGUP, () => {
  1765. this.hangup(true);
  1766. });
  1767. // logout
  1768. APP.UI.addListener(UIEvents.LOGOUT, () => {
  1769. AuthHandler.logout(room).then(url => {
  1770. if (url) {
  1771. UIUtil.redirect(url);
  1772. } else {
  1773. this.hangup(true);
  1774. }
  1775. });
  1776. });
  1777. APP.UI.addListener(UIEvents.RESOLUTION_CHANGED,
  1778. (id, oldResolution, newResolution, delay) => {
  1779. var logObject = {
  1780. id: "resolution_change",
  1781. participant: id,
  1782. oldValue: oldResolution,
  1783. newValue: newResolution,
  1784. delay: delay
  1785. };
  1786. room.sendApplicationLog(JSON.stringify(logObject));
  1787. // We only care about the delay between simulcast streams.
  1788. // Longer delays will be caused by something else and will just
  1789. // poison the data.
  1790. if (delay < 2000) {
  1791. JitsiMeetJS.analytics.sendEvent('stream.switch.delay',
  1792. {value: delay});
  1793. }
  1794. });
  1795. // Starts or stops the recording for the conference.
  1796. APP.UI.addListener(UIEvents.RECORDING_TOGGLED, (options) => {
  1797. room.toggleRecording(options);
  1798. });
  1799. APP.UI.addListener(UIEvents.SUBJECT_CHANGED, (topic) => {
  1800. room.setSubject(topic);
  1801. });
  1802. room.on(ConferenceEvents.SUBJECT_CHANGED, function (subject) {
  1803. APP.UI.setSubject(subject);
  1804. });
  1805. APP.UI.addListener(UIEvents.USER_KICKED, (id) => {
  1806. room.kickParticipant(id);
  1807. });
  1808. APP.UI.addListener(UIEvents.REMOTE_AUDIO_MUTED, (id) => {
  1809. room.muteParticipant(id);
  1810. });
  1811. APP.UI.addListener(UIEvents.AUTH_CLICKED, () => {
  1812. AuthHandler.authenticate(room);
  1813. });
  1814. APP.UI.addListener(
  1815. UIEvents.VIDEO_DEVICE_CHANGED,
  1816. (cameraDeviceId) => {
  1817. JitsiMeetJS.analytics.sendEvent('settings.changeDevice.video');
  1818. createLocalTracksF({
  1819. devices: ['video'],
  1820. cameraDeviceId: cameraDeviceId,
  1821. micDeviceId: null
  1822. })
  1823. .then(([stream]) => {
  1824. if (this.isAudioOnly()) {
  1825. return stream.mute()
  1826. .then(() => stream);
  1827. }
  1828. return stream;
  1829. })
  1830. .then(stream => {
  1831. this.useVideoStream(stream);
  1832. logger.log('switched local video device');
  1833. APP.settings.setCameraDeviceId(cameraDeviceId, true);
  1834. })
  1835. .catch((err) => {
  1836. APP.UI.showCameraErrorNotification(err);
  1837. });
  1838. }
  1839. );
  1840. APP.UI.addListener(
  1841. UIEvents.AUDIO_DEVICE_CHANGED,
  1842. (micDeviceId) => {
  1843. JitsiMeetJS.analytics.sendEvent(
  1844. 'settings.changeDevice.audioIn');
  1845. createLocalTracksF({
  1846. devices: ['audio'],
  1847. cameraDeviceId: null,
  1848. micDeviceId: micDeviceId
  1849. })
  1850. .then(([stream]) => {
  1851. this.useAudioStream(stream);
  1852. logger.log('switched local audio device');
  1853. APP.settings.setMicDeviceId(micDeviceId, true);
  1854. })
  1855. .catch((err) => {
  1856. APP.UI.showMicErrorNotification(err);
  1857. });
  1858. }
  1859. );
  1860. APP.UI.addListener(
  1861. UIEvents.AUDIO_OUTPUT_DEVICE_CHANGED,
  1862. (audioOutputDeviceId) => {
  1863. JitsiMeetJS.analytics.sendEvent(
  1864. 'settings.changeDevice.audioOut');
  1865. APP.settings.setAudioOutputDeviceId(audioOutputDeviceId)
  1866. .then(() => logger.log('changed audio output device'))
  1867. .catch((err) => {
  1868. logger.warn('Failed to change audio output device. ' +
  1869. 'Default or previously set audio output device ' +
  1870. 'will be used instead.', err);
  1871. });
  1872. }
  1873. );
  1874. APP.UI.addListener(UIEvents.TOGGLE_AUDIO_ONLY, audioOnly => {
  1875. // FIXME On web video track is stored both in redux and in
  1876. // 'localVideo' field, video is attempted to be unmuted twice when
  1877. // turning off the audio only mode. This will crash the app with
  1878. // 'unmute operation is already in progress'.
  1879. // Because there's no logic in redux about creating new track in
  1880. // case unmute when not track exists the things have to go through
  1881. // muteVideo logic in such case.
  1882. const tracks = APP.store.getState()['features/base/tracks'];
  1883. const isTrackInRedux
  1884. = Boolean(
  1885. tracks.find(
  1886. track => track.jitsiTrack
  1887. && track.jitsiTrack.getType() === 'video'));
  1888. if (!isTrackInRedux) {
  1889. this.muteVideo(audioOnly);
  1890. }
  1891. // Immediately update the UI by having remote videos and the large
  1892. // video update themselves instead of waiting for some other event
  1893. // to cause the update, usually PARTICIPANT_CONN_STATUS_CHANGED.
  1894. // There is no guarantee another event will trigger the update
  1895. // immediately and in all situations, for example because a remote
  1896. // participant is having connection trouble so no status changes.
  1897. APP.UI.updateAllVideos();
  1898. });
  1899. APP.UI.addListener(
  1900. UIEvents.TOGGLE_SCREENSHARING, this.toggleScreenSharing.bind(this)
  1901. );
  1902. APP.UI.addListener(UIEvents.UPDATE_SHARED_VIDEO,
  1903. (url, state, time, isMuted, volume) => {
  1904. // send start and stop commands once, and remove any updates
  1905. // that had left
  1906. if (state === 'stop' || state === 'start' || state === 'playing') {
  1907. room.removeCommand(this.commands.defaults.SHARED_VIDEO);
  1908. room.sendCommandOnce(this.commands.defaults.SHARED_VIDEO, {
  1909. value: url,
  1910. attributes: {
  1911. state: state,
  1912. time: time,
  1913. muted: isMuted,
  1914. volume: volume
  1915. }
  1916. });
  1917. }
  1918. else {
  1919. // in case of paused, in order to allow late users to join
  1920. // paused
  1921. room.removeCommand(this.commands.defaults.SHARED_VIDEO);
  1922. room.sendCommand(this.commands.defaults.SHARED_VIDEO, {
  1923. value: url,
  1924. attributes: {
  1925. state: state,
  1926. time: time,
  1927. muted: isMuted,
  1928. volume: volume
  1929. }
  1930. });
  1931. }
  1932. });
  1933. room.addCommandListener(
  1934. this.commands.defaults.SHARED_VIDEO, ({value, attributes}, id) => {
  1935. if (attributes.state === 'stop') {
  1936. APP.UI.onSharedVideoStop(id, attributes);
  1937. }
  1938. else if (attributes.state === 'start') {
  1939. APP.UI.onSharedVideoStart(id, value, attributes);
  1940. }
  1941. else if (attributes.state === 'playing'
  1942. || attributes.state === 'pause') {
  1943. APP.UI.onSharedVideoUpdate(id, value, attributes);
  1944. }
  1945. });
  1946. },
  1947. /**
  1948. * Adds any room listener.
  1949. * @param {string} eventName one of the ConferenceEvents
  1950. * @param {Function} listener the function to be called when the event
  1951. * occurs
  1952. */
  1953. addConferenceListener(eventName, listener) {
  1954. room.on(eventName, listener);
  1955. },
  1956. /**
  1957. * Removes any room listener.
  1958. * @param {string} eventName one of the ConferenceEvents
  1959. * @param {Function} listener the listener to be removed.
  1960. */
  1961. removeConferenceListener(eventName, listener) {
  1962. room.off(eventName, listener);
  1963. },
  1964. /**
  1965. * Inits list of current devices and event listener for device change.
  1966. * @private
  1967. */
  1968. _initDeviceList() {
  1969. JitsiMeetJS.mediaDevices.isDeviceListAvailable()
  1970. .then(isDeviceListAvailable => {
  1971. if (isDeviceListAvailable
  1972. && JitsiMeetJS.mediaDevices.isDeviceChangeAvailable()) {
  1973. JitsiMeetJS.mediaDevices.enumerateDevices(devices => {
  1974. // Ugly way to synchronize real device IDs with local
  1975. // storage and settings menu. This is a workaround until
  1976. // getConstraints() method will be implemented
  1977. // in browsers.
  1978. if (this.localAudio) {
  1979. APP.settings.setMicDeviceId(
  1980. this.localAudio.getDeviceId(), false);
  1981. }
  1982. if (this.localVideo) {
  1983. APP.settings.setCameraDeviceId(
  1984. this.localVideo.getDeviceId(), false);
  1985. }
  1986. mediaDeviceHelper.setCurrentMediaDevices(devices);
  1987. APP.UI.onAvailableDevicesChanged(devices);
  1988. APP.store.dispatch(updateDeviceList(devices));
  1989. });
  1990. this.deviceChangeListener = (devices) =>
  1991. window.setTimeout(
  1992. () => this._onDeviceListChanged(devices), 0);
  1993. JitsiMeetJS.mediaDevices.addEventListener(
  1994. JitsiMeetJS.events.mediaDevices.DEVICE_LIST_CHANGED,
  1995. this.deviceChangeListener);
  1996. }
  1997. })
  1998. .catch((error) => {
  1999. logger.warn(`Error getting device list: ${error}`);
  2000. });
  2001. },
  2002. /**
  2003. * Event listener for JitsiMediaDevicesEvents.DEVICE_LIST_CHANGED to
  2004. * handle change of available media devices.
  2005. * @private
  2006. * @param {MediaDeviceInfo[]} devices
  2007. * @returns {Promise}
  2008. */
  2009. _onDeviceListChanged(devices) {
  2010. let currentDevices = mediaDeviceHelper.getCurrentMediaDevices();
  2011. // Event handler can be fired before direct
  2012. // enumerateDevices() call, so handle this situation here.
  2013. if (!currentDevices.audioinput &&
  2014. !currentDevices.videoinput &&
  2015. !currentDevices.audiooutput) {
  2016. mediaDeviceHelper.setCurrentMediaDevices(devices);
  2017. currentDevices = mediaDeviceHelper.getCurrentMediaDevices();
  2018. }
  2019. let newDevices =
  2020. mediaDeviceHelper.getNewMediaDevicesAfterDeviceListChanged(
  2021. devices,
  2022. this.isSharingScreen,
  2023. this.localVideo,
  2024. this.localAudio);
  2025. let promises = [];
  2026. let audioWasMuted = this.isLocalAudioMuted();
  2027. let videoWasMuted = this.isLocalVideoMuted();
  2028. let availableAudioInputDevices =
  2029. mediaDeviceHelper.getDevicesFromListByKind(devices, 'audioinput');
  2030. let availableVideoInputDevices =
  2031. mediaDeviceHelper.getDevicesFromListByKind(devices, 'videoinput');
  2032. if (typeof newDevices.audiooutput !== 'undefined') {
  2033. // Just ignore any errors in catch block.
  2034. promises.push(APP.settings
  2035. .setAudioOutputDeviceId(newDevices.audiooutput)
  2036. .catch());
  2037. }
  2038. promises.push(
  2039. mediaDeviceHelper.createLocalTracksAfterDeviceListChanged(
  2040. createLocalTracksF,
  2041. newDevices.videoinput,
  2042. newDevices.audioinput)
  2043. .then(tracks =>
  2044. Promise.all(this._setLocalAudioVideoStreams(tracks)))
  2045. .then(() => {
  2046. // If audio was muted before, or we unplugged current device
  2047. // and selected new one, then mute new audio track.
  2048. if (audioWasMuted ||
  2049. currentDevices.audioinput.length >
  2050. availableAudioInputDevices.length) {
  2051. muteLocalAudio(true);
  2052. }
  2053. // If video was muted before, or we unplugged current device
  2054. // and selected new one, then mute new video track.
  2055. if (!this.isSharingScreen &&
  2056. (videoWasMuted ||
  2057. currentDevices.videoinput.length >
  2058. availableVideoInputDevices.length)) {
  2059. muteLocalVideo(true);
  2060. }
  2061. }));
  2062. return Promise.all(promises)
  2063. .then(() => {
  2064. mediaDeviceHelper.setCurrentMediaDevices(devices);
  2065. APP.UI.onAvailableDevicesChanged(devices);
  2066. });
  2067. },
  2068. /**
  2069. * Determines whether or not the audio button should be enabled.
  2070. */
  2071. updateAudioIconEnabled() {
  2072. const audioMediaDevices
  2073. = mediaDeviceHelper.getCurrentMediaDevices().audioinput;
  2074. const audioDeviceCount
  2075. = audioMediaDevices ? audioMediaDevices.length : 0;
  2076. // The audio functionality is considered available if there are any
  2077. // audio devices detected or if the local audio stream already exists.
  2078. const available = audioDeviceCount > 0 || Boolean(this.localAudio);
  2079. logger.debug(
  2080. 'Microphone button enabled: ' + available,
  2081. 'local audio: ' + this.localAudio,
  2082. 'audio devices: ' + audioMediaDevices,
  2083. 'device count: ' + audioDeviceCount);
  2084. APP.store.dispatch(setAudioAvailable(available));
  2085. APP.API.notifyAudioAvailabilityChanged(available);
  2086. },
  2087. /**
  2088. * Determines whether or not the video button should be enabled.
  2089. */
  2090. updateVideoIconEnabled() {
  2091. const videoMediaDevices
  2092. = mediaDeviceHelper.getCurrentMediaDevices().videoinput;
  2093. const videoDeviceCount
  2094. = videoMediaDevices ? videoMediaDevices.length : 0;
  2095. // The video functionality is considered available if there are any
  2096. // video devices detected or if there is local video stream already
  2097. // active which could be either screensharing stream or a video track
  2098. // created before the permissions were rejected (through browser
  2099. // config).
  2100. const available = videoDeviceCount > 0 || Boolean(this.localVideo);
  2101. logger.debug(
  2102. 'Camera button enabled: ' + available,
  2103. 'local video: ' + this.localVideo,
  2104. 'video devices: ' + videoMediaDevices,
  2105. 'device count: ' + videoDeviceCount);
  2106. APP.store.dispatch(setVideoAvailable(available));
  2107. APP.API.notifyVideoAvailabilityChanged(available);
  2108. },
  2109. /**
  2110. * Toggles the local "raised hand" status.
  2111. */
  2112. maybeToggleRaisedHand() {
  2113. this.setRaisedHand(!this.isHandRaised);
  2114. },
  2115. /**
  2116. * Sets the local "raised hand" status to a particular value.
  2117. */
  2118. setRaisedHand(raisedHand) {
  2119. if (raisedHand !== this.isHandRaised)
  2120. {
  2121. APP.UI.onLocalRaiseHandChanged(raisedHand);
  2122. this.isHandRaised = raisedHand;
  2123. // Advertise the updated status
  2124. room.setLocalParticipantProperty("raisedHand", raisedHand);
  2125. // Update the view
  2126. APP.UI.setLocalRaisedHandStatus(raisedHand);
  2127. }
  2128. },
  2129. /**
  2130. * Log event to callstats and analytics.
  2131. * @param {string} name the event name
  2132. * @param {int} value the value (it's int because google analytics supports
  2133. * only int).
  2134. * @param {string} label short text which provides more info about the event
  2135. * which allows to distinguish between few event cases of the same name
  2136. * NOTE: Should be used after conference.init
  2137. */
  2138. logEvent(name, value, label) {
  2139. if (JitsiMeetJS.analytics) {
  2140. JitsiMeetJS.analytics.sendEvent(name, {value, label});
  2141. }
  2142. if (room) {
  2143. room.sendApplicationLog(JSON.stringify({name, value, label}));
  2144. }
  2145. },
  2146. /**
  2147. * Methods logs an application event given in the JSON format.
  2148. * @param {string} logJSON an event to be logged in JSON format
  2149. */
  2150. logJSON(logJSON) {
  2151. if (room) {
  2152. room.sendApplicationLog(logJSON);
  2153. }
  2154. },
  2155. /**
  2156. * Disconnect from the conference and optionally request user feedback.
  2157. * @param {boolean} [requestFeedback=false] if user feedback should be
  2158. * requested
  2159. */
  2160. hangup(requestFeedback = false) {
  2161. eventEmitter.emit(JitsiMeetConferenceEvents.BEFORE_HANGUP);
  2162. let requestFeedbackPromise;
  2163. if (requestFeedback) {
  2164. requestFeedbackPromise
  2165. = APP.store.dispatch(maybeOpenFeedbackDialog(room))
  2166. // false because the thank you dialog shouldn't be displayed
  2167. .catch(() => Promise.resolve(false));
  2168. } else {
  2169. requestFeedbackPromise = Promise.resolve(true);
  2170. }
  2171. // All promises are returning Promise.resolve to make Promise.all to
  2172. // be resolved when both Promises are finished. Otherwise Promise.all
  2173. // will reject on first rejected Promise and we can redirect the page
  2174. // before all operations are done.
  2175. Promise.all([
  2176. requestFeedbackPromise,
  2177. room.leave().then(disconnect, disconnect)
  2178. ]).then(values => {
  2179. APP.API.notifyReadyToClose();
  2180. maybeRedirectToWelcomePage(values[0]);
  2181. });
  2182. },
  2183. /**
  2184. * Changes the email for the local user
  2185. * @param email {string} the new email
  2186. */
  2187. changeLocalEmail(email = '') {
  2188. email = String(email).trim();
  2189. if (email === APP.settings.getEmail()) {
  2190. return;
  2191. }
  2192. const localId = room ? room.myUserId() : undefined;
  2193. APP.store.dispatch(participantUpdated({
  2194. id: localId,
  2195. local: true,
  2196. email
  2197. }));
  2198. APP.settings.setEmail(email);
  2199. APP.UI.setUserEmail(localId, email);
  2200. sendData(commands.EMAIL, email);
  2201. },
  2202. /**
  2203. * Changes the avatar url for the local user
  2204. * @param url {string} the new url
  2205. */
  2206. changeLocalAvatarUrl(url = '') {
  2207. url = String(url).trim();
  2208. if (url === APP.settings.getAvatarUrl()) {
  2209. return;
  2210. }
  2211. const localId = room ? room.myUserId() : undefined;
  2212. APP.store.dispatch(participantUpdated({
  2213. id: localId,
  2214. local: true,
  2215. avatarURL: url
  2216. }));
  2217. APP.settings.setAvatarUrl(url);
  2218. APP.UI.setUserAvatarUrl(localId, url);
  2219. sendData(commands.AVATAR_URL, url);
  2220. },
  2221. /**
  2222. * Sends a message via the data channel.
  2223. * @param {string} to the id of the endpoint that should receive the
  2224. * message. If "" - the message will be sent to all participants.
  2225. * @param {object} payload the payload of the message.
  2226. * @throws NetworkError or InvalidStateError or Error if the operation
  2227. * fails.
  2228. */
  2229. sendEndpointMessage(to, payload) {
  2230. room.sendEndpointMessage(to, payload);
  2231. },
  2232. /**
  2233. * Adds new listener.
  2234. * @param {String} eventName the name of the event
  2235. * @param {Function} listener the listener.
  2236. */
  2237. addListener(eventName, listener) {
  2238. eventEmitter.addListener(eventName, listener);
  2239. },
  2240. /**
  2241. * Removes listener.
  2242. * @param {String} eventName the name of the event that triggers the
  2243. * listener
  2244. * @param {Function} listener the listener.
  2245. */
  2246. removeListener(eventName, listener) {
  2247. eventEmitter.removeListener(eventName, listener);
  2248. },
  2249. /**
  2250. * Changes the display name for the local user
  2251. * @param nickname {string} the new display name
  2252. */
  2253. changeLocalDisplayName(nickname = '') {
  2254. const formattedNickname
  2255. = nickname.trim().substr(0, MAX_DISPLAY_NAME_LENGTH);
  2256. if (formattedNickname === APP.settings.getDisplayName()) {
  2257. return;
  2258. }
  2259. APP.store.dispatch(participantUpdated({
  2260. id: this.getMyUserId(),
  2261. local: true,
  2262. name: formattedNickname
  2263. }));
  2264. APP.settings.setDisplayName(formattedNickname);
  2265. if (room) {
  2266. room.setDisplayName(formattedNickname);
  2267. APP.UI.changeDisplayName(this.getMyUserId(), formattedNickname);
  2268. }
  2269. },
  2270. /**
  2271. * Returns the desktop sharing source id or undefined if the desktop sharing
  2272. * is not active at the moment.
  2273. *
  2274. * @returns {string|undefined} - The source id. If the track is not desktop
  2275. * track or the source id is not available, undefined will be returned.
  2276. */
  2277. getDesktopSharingSourceId() {
  2278. return this.localVideo.sourceId;
  2279. },
  2280. /**
  2281. * Returns the desktop sharing source type or undefined if the desktop
  2282. * sharing is not active at the moment.
  2283. *
  2284. * @returns {'screen'|'window'|undefined} - The source type. If the track is
  2285. * not desktop track or the source type is not available, undefined will be
  2286. * returned.
  2287. */
  2288. getDesktopSharingSourceType() {
  2289. return this.localVideo.sourceType;
  2290. },
  2291. /**
  2292. * Sets the video muted status.
  2293. *
  2294. * @param {boolean} muted - New muted status.
  2295. */
  2296. setVideoMuteStatus(muted) {
  2297. APP.UI.setVideoMuted(this.getMyUserId(), muted);
  2298. APP.API.notifyVideoMutedStatusChanged(muted);
  2299. },
  2300. /**
  2301. * Sets the audio muted status.
  2302. *
  2303. * @param {boolean} muted - New muted status.
  2304. */
  2305. setAudioMuteStatus(muted) {
  2306. APP.UI.setAudioMuted(this.getMyUserId(), muted);
  2307. APP.API.notifyAudioMutedStatusChanged(muted);
  2308. }
  2309. };