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

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