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

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