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

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