Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

conference.js 90KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558
  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. if (!nick) {
  1563. nick =
  1564. `${interfaceConfig.DEFAULT_REMOTE_DISPLAY_NAME} (${
  1565. id})`;
  1566. }
  1567. APP.API.notifyReceivedChatMessage({
  1568. id,
  1569. nick,
  1570. body,
  1571. ts
  1572. });
  1573. APP.UI.addMessage(id, nick, body, ts);
  1574. });
  1575. APP.UI.addListener(UIEvents.MESSAGE_CREATED, (message) => {
  1576. APP.API.notifySendingChatMessage(message);
  1577. room.sendTextMessage(message);
  1578. });
  1579. }
  1580. APP.UI.addListener(UIEvents.SELECTED_ENDPOINT, (id) => {
  1581. try {
  1582. // do not try to select participant if there is none (we
  1583. // are alone in the room), otherwise an error will be
  1584. // thrown cause reporting mechanism is not available
  1585. // (datachannels currently)
  1586. if (room.getParticipants().length === 0)
  1587. return;
  1588. room.selectParticipant(id);
  1589. } catch (e) {
  1590. sendEvent(
  1591. 'selectParticipant.failed');
  1592. reportError(e);
  1593. }
  1594. });
  1595. APP.UI.addListener(
  1596. UIEvents.VIDEO_UNMUTING_WHILE_AUDIO_ONLY,
  1597. () => this._displayAudioOnlyTooltip('videoMute'));
  1598. }
  1599. room.on(JitsiConferenceEvents.CONNECTION_INTERRUPTED, () => {
  1600. APP.store.dispatch(localParticipantConnectionStatusChanged(
  1601. JitsiParticipantConnectionStatus.INTERRUPTED));
  1602. APP.UI.showLocalConnectionInterrupted(true);
  1603. });
  1604. room.on(JitsiConferenceEvents.CONNECTION_RESTORED, () => {
  1605. APP.store.dispatch(localParticipantConnectionStatusChanged(
  1606. JitsiParticipantConnectionStatus.ACTIVE));
  1607. APP.UI.showLocalConnectionInterrupted(false);
  1608. });
  1609. room.on(JitsiConferenceEvents.DISPLAY_NAME_CHANGED, (id, displayName) => {
  1610. const formattedDisplayName
  1611. = displayName.substr(0, MAX_DISPLAY_NAME_LENGTH);
  1612. APP.store.dispatch(participantUpdated({
  1613. id,
  1614. name: formattedDisplayName
  1615. }));
  1616. APP.API.notifyDisplayNameChanged(id, formattedDisplayName);
  1617. APP.UI.changeDisplayName(id, formattedDisplayName);
  1618. });
  1619. room.on(
  1620. JitsiConferenceEvents.LOCK_STATE_CHANGED,
  1621. (...args) => APP.store.dispatch(lockStateChanged(room, ...args)));
  1622. APP.remoteControl.on(RemoteControlEvents.ACTIVE_CHANGED, isActive => {
  1623. room.setLocalParticipantProperty(
  1624. "remoteControlSessionStatus",
  1625. isActive
  1626. );
  1627. APP.UI.setLocalRemoteControlActiveChanged();
  1628. });
  1629. room.on(
  1630. JitsiConferenceEvents.PARTICIPANT_PROPERTY_CHANGED,
  1631. (participant, name, oldValue, newValue) => {
  1632. switch (name) {
  1633. case 'raisedHand':
  1634. APP.UI.setRaisedHandStatus(participant, newValue);
  1635. break;
  1636. case 'remoteControlSessionStatus':
  1637. APP.UI.setRemoteControlActiveStatus(
  1638. participant.getId(),
  1639. newValue);
  1640. break;
  1641. default:
  1642. // ignore
  1643. }
  1644. });
  1645. room.on(JitsiConferenceEvents.RECORDER_STATE_CHANGED, (status, error) => {
  1646. logger.log("Received recorder status change: ", status, error);
  1647. APP.UI.updateRecordingState(status);
  1648. });
  1649. room.on(JitsiConferenceEvents.KICKED, () => {
  1650. APP.UI.hideStats();
  1651. APP.UI.notifyKicked();
  1652. // FIXME close
  1653. });
  1654. room.on(JitsiConferenceEvents.SUSPEND_DETECTED, () => {
  1655. APP.store.dispatch(suspendDetected());
  1656. // After wake up, we will be in a state where conference is left
  1657. // there will be dialog shown to user.
  1658. // We do not want video/audio as we show an overlay and after it
  1659. // user need to rejoin or close, while waking up we can detect
  1660. // camera wakeup as a problem with device.
  1661. // We also do not care about device change, which happens
  1662. // on resume after suspending PC.
  1663. if (this.deviceChangeListener)
  1664. JitsiMeetJS.mediaDevices.removeEventListener(
  1665. JitsiMediaDevicesEvents.DEVICE_LIST_CHANGED,
  1666. this.deviceChangeListener);
  1667. // stop local video
  1668. if (this.localVideo) {
  1669. this.localVideo.dispose();
  1670. this.localVideo = null;
  1671. }
  1672. // stop local audio
  1673. if (this.localAudio) {
  1674. this.localAudio.dispose();
  1675. this.localAudio = null;
  1676. }
  1677. });
  1678. room.on(JitsiConferenceEvents.DTMF_SUPPORT_CHANGED, (isDTMFSupported) => {
  1679. APP.UI.updateDTMFSupport(isDTMFSupported);
  1680. });
  1681. APP.UI.addListener(UIEvents.AUDIO_MUTED, muted => {
  1682. this.muteAudio(muted);
  1683. });
  1684. APP.UI.addListener(UIEvents.VIDEO_MUTED, muted => {
  1685. if (this.isAudioOnly() && !muted) {
  1686. this._displayAudioOnlyTooltip('videoMute');
  1687. } else {
  1688. this.muteVideo(muted);
  1689. }
  1690. });
  1691. statsEmitter.startListeningForStats(room);
  1692. room.addCommandListener(this.commands.defaults.ETHERPAD, ({value}) => {
  1693. APP.UI.initEtherpad(value);
  1694. });
  1695. APP.UI.addListener(UIEvents.EMAIL_CHANGED, this.changeLocalEmail);
  1696. room.addCommandListener(this.commands.defaults.EMAIL, (data, from) => {
  1697. APP.store.dispatch(participantUpdated({
  1698. id: from,
  1699. email: data.value
  1700. }));
  1701. APP.UI.setUserEmail(from, data.value);
  1702. });
  1703. room.addCommandListener(
  1704. this.commands.defaults.AVATAR_URL,
  1705. (data, from) => {
  1706. APP.store.dispatch(
  1707. participantUpdated({
  1708. id: from,
  1709. avatarURL: data.value
  1710. }));
  1711. APP.UI.setUserAvatarUrl(from, data.value);
  1712. });
  1713. room.addCommandListener(this.commands.defaults.AVATAR_ID,
  1714. (data, from) => {
  1715. APP.store.dispatch(
  1716. participantUpdated({
  1717. id: from,
  1718. avatarID: data.value
  1719. }));
  1720. APP.UI.setUserAvatarID(from, data.value);
  1721. });
  1722. APP.UI.addListener(UIEvents.NICKNAME_CHANGED,
  1723. this.changeLocalDisplayName.bind(this));
  1724. APP.UI.addListener(UIEvents.START_MUTED_CHANGED,
  1725. (startAudioMuted, startVideoMuted) => {
  1726. room.setStartMutedPolicy({
  1727. audio: startAudioMuted,
  1728. video: startVideoMuted
  1729. });
  1730. }
  1731. );
  1732. room.on(
  1733. JitsiConferenceEvents.START_MUTED_POLICY_CHANGED,
  1734. ({ audio, video }) => {
  1735. APP.UI.onStartMutedChanged(audio, video);
  1736. }
  1737. );
  1738. room.on(JitsiConferenceEvents.STARTED_MUTED, () => {
  1739. (room.isStartAudioMuted() || room.isStartVideoMuted())
  1740. && APP.UI.notifyInitiallyMuted();
  1741. });
  1742. room.on(
  1743. JitsiConferenceEvents.AVAILABLE_DEVICES_CHANGED, function (id, devices) {
  1744. APP.UI.updateDevicesAvailability(id, devices);
  1745. }
  1746. );
  1747. room.on(
  1748. JitsiConferenceEvents.DATA_CHANNEL_OPENED, () => {
  1749. APP.store.dispatch(dataChannelOpened());
  1750. }
  1751. );
  1752. // call hangup
  1753. APP.UI.addListener(UIEvents.HANGUP, () => {
  1754. this.hangup(true);
  1755. });
  1756. // logout
  1757. APP.UI.addListener(UIEvents.LOGOUT, () => {
  1758. AuthHandler.logout(room).then(url => {
  1759. if (url) {
  1760. UIUtil.redirect(url);
  1761. } else {
  1762. this.hangup(true);
  1763. }
  1764. });
  1765. });
  1766. APP.UI.addListener(
  1767. UIEvents.RESOLUTION_CHANGED,
  1768. (id, oldResolution, newResolution, delay) => {
  1769. var logObject = {
  1770. id: "resolution_change",
  1771. participant: id,
  1772. oldValue: oldResolution,
  1773. newValue: newResolution,
  1774. delay: delay
  1775. };
  1776. room.sendApplicationLog(JSON.stringify(logObject));
  1777. // We only care about the delay between simulcast streams.
  1778. // Longer delays will be caused by something else and will just
  1779. // poison the data.
  1780. if (delay < 2000) {
  1781. sendEvent('stream.switch.delay',
  1782. {value: delay});
  1783. }
  1784. });
  1785. // Starts or stops the recording for the conference.
  1786. APP.UI.addListener(UIEvents.RECORDING_TOGGLED, (options) => {
  1787. room.toggleRecording(options);
  1788. });
  1789. APP.UI.addListener(UIEvents.SUBJECT_CHANGED, (topic) => {
  1790. room.setSubject(topic);
  1791. });
  1792. room.on(JitsiConferenceEvents.SUBJECT_CHANGED, function (subject) {
  1793. APP.UI.setSubject(subject);
  1794. });
  1795. APP.UI.addListener(UIEvents.USER_KICKED, (id) => {
  1796. room.kickParticipant(id);
  1797. });
  1798. APP.UI.addListener(UIEvents.REMOTE_AUDIO_MUTED, (id) => {
  1799. room.muteParticipant(id);
  1800. });
  1801. APP.UI.addListener(UIEvents.AUTH_CLICKED, () => {
  1802. AuthHandler.authenticate(room);
  1803. });
  1804. APP.UI.addListener(
  1805. UIEvents.VIDEO_DEVICE_CHANGED,
  1806. (cameraDeviceId) => {
  1807. sendEvent('settings.changeDevice.video');
  1808. createLocalTracksF({
  1809. devices: ['video'],
  1810. cameraDeviceId: cameraDeviceId,
  1811. micDeviceId: null
  1812. })
  1813. .then(([stream]) => {
  1814. if (this.isAudioOnly()) {
  1815. return stream.mute()
  1816. .then(() => stream);
  1817. }
  1818. return stream;
  1819. })
  1820. .then(stream => {
  1821. this.useVideoStream(stream);
  1822. logger.log('switched local video device');
  1823. APP.settings.setCameraDeviceId(cameraDeviceId, true);
  1824. })
  1825. .catch((err) => {
  1826. APP.UI.showCameraErrorNotification(err);
  1827. });
  1828. }
  1829. );
  1830. APP.UI.addListener(
  1831. UIEvents.AUDIO_DEVICE_CHANGED,
  1832. (micDeviceId) => {
  1833. sendEvent(
  1834. 'settings.changeDevice.audioIn');
  1835. createLocalTracksF({
  1836. devices: ['audio'],
  1837. cameraDeviceId: null,
  1838. micDeviceId: micDeviceId
  1839. })
  1840. .then(([stream]) => {
  1841. this.useAudioStream(stream);
  1842. logger.log('switched local audio device');
  1843. APP.settings.setMicDeviceId(micDeviceId, true);
  1844. })
  1845. .catch((err) => {
  1846. APP.UI.showMicErrorNotification(err);
  1847. });
  1848. }
  1849. );
  1850. APP.UI.addListener(
  1851. UIEvents.AUDIO_OUTPUT_DEVICE_CHANGED,
  1852. (audioOutputDeviceId) => {
  1853. sendEvent(
  1854. 'settings.changeDevice.audioOut');
  1855. APP.settings.setAudioOutputDeviceId(audioOutputDeviceId)
  1856. .then(() => logger.log('changed audio output device'))
  1857. .catch((err) => {
  1858. logger.warn('Failed to change audio output device. ' +
  1859. 'Default or previously set audio output device ' +
  1860. 'will be used instead.', err);
  1861. });
  1862. }
  1863. );
  1864. APP.UI.addListener(UIEvents.TOGGLE_AUDIO_ONLY, audioOnly => {
  1865. // FIXME On web video track is stored both in redux and in
  1866. // 'localVideo' field, video is attempted to be unmuted twice when
  1867. // turning off the audio only mode. This will crash the app with
  1868. // 'unmute operation is already in progress'.
  1869. // Because there's no logic in redux about creating new track in
  1870. // case unmute when not track exists the things have to go through
  1871. // muteVideo logic in such case.
  1872. const tracks = APP.store.getState()['features/base/tracks'];
  1873. const isTrackInRedux
  1874. = Boolean(
  1875. tracks.find(
  1876. track => track.jitsiTrack
  1877. && track.jitsiTrack.getType() === 'video'));
  1878. if (!isTrackInRedux) {
  1879. this.muteVideo(audioOnly);
  1880. }
  1881. // Immediately update the UI by having remote videos and the large
  1882. // video update themselves instead of waiting for some other event
  1883. // to cause the update, usually PARTICIPANT_CONN_STATUS_CHANGED.
  1884. // There is no guarantee another event will trigger the update
  1885. // immediately and in all situations, for example because a remote
  1886. // participant is having connection trouble so no status changes.
  1887. APP.UI.updateAllVideos();
  1888. });
  1889. APP.UI.addListener(
  1890. UIEvents.TOGGLE_SCREENSHARING, this.toggleScreenSharing.bind(this)
  1891. );
  1892. APP.UI.addListener(
  1893. UIEvents.UPDATE_SHARED_VIDEO,
  1894. (url, state, time, isMuted, volume) => {
  1895. // send start and stop commands once, and remove any updates
  1896. // that had left
  1897. if (state === 'stop'
  1898. || state === 'start'
  1899. || state === 'playing') {
  1900. room.removeCommand(this.commands.defaults.SHARED_VIDEO);
  1901. room.sendCommandOnce(this.commands.defaults.SHARED_VIDEO, {
  1902. value: url,
  1903. attributes: {
  1904. state: state,
  1905. time: time,
  1906. muted: isMuted,
  1907. volume: volume
  1908. }
  1909. });
  1910. }
  1911. else {
  1912. // in case of paused, in order to allow late users to join
  1913. // paused
  1914. room.removeCommand(this.commands.defaults.SHARED_VIDEO);
  1915. room.sendCommand(this.commands.defaults.SHARED_VIDEO, {
  1916. value: url,
  1917. attributes: {
  1918. state: state,
  1919. time: time,
  1920. muted: isMuted,
  1921. volume: volume
  1922. }
  1923. });
  1924. }
  1925. });
  1926. room.addCommandListener(
  1927. this.commands.defaults.SHARED_VIDEO, ({value, attributes}, id) => {
  1928. if (attributes.state === 'stop') {
  1929. APP.UI.onSharedVideoStop(id, attributes);
  1930. }
  1931. else if (attributes.state === 'start') {
  1932. APP.UI.onSharedVideoStart(id, value, attributes);
  1933. }
  1934. else if (attributes.state === 'playing'
  1935. || attributes.state === 'pause') {
  1936. APP.UI.onSharedVideoUpdate(id, value, attributes);
  1937. }
  1938. });
  1939. },
  1940. /**
  1941. * Adds any room listener.
  1942. * @param {string} eventName one of the JitsiConferenceEvents
  1943. * @param {Function} listener the function to be called when the event
  1944. * occurs
  1945. */
  1946. addConferenceListener(eventName, listener) {
  1947. room.on(eventName, listener);
  1948. },
  1949. /**
  1950. * Removes any room listener.
  1951. * @param {string} eventName one of the JitsiConferenceEvents
  1952. * @param {Function} listener the listener to be removed.
  1953. */
  1954. removeConferenceListener(eventName, listener) {
  1955. room.off(eventName, listener);
  1956. },
  1957. /**
  1958. * Inits list of current devices and event listener for device change.
  1959. * @private
  1960. */
  1961. _initDeviceList() {
  1962. JitsiMeetJS.mediaDevices.isDeviceListAvailable()
  1963. .then(isDeviceListAvailable => {
  1964. if (isDeviceListAvailable
  1965. && JitsiMeetJS.mediaDevices.isDeviceChangeAvailable()) {
  1966. JitsiMeetJS.mediaDevices.enumerateDevices(devices => {
  1967. // Ugly way to synchronize real device IDs with local
  1968. // storage and settings menu. This is a workaround until
  1969. // getConstraints() method will be implemented
  1970. // in browsers.
  1971. if (this.localAudio) {
  1972. APP.settings.setMicDeviceId(
  1973. this.localAudio.getDeviceId(), false);
  1974. }
  1975. if (this.localVideo) {
  1976. APP.settings.setCameraDeviceId(
  1977. this.localVideo.getDeviceId(), false);
  1978. }
  1979. mediaDeviceHelper.setCurrentMediaDevices(devices);
  1980. APP.UI.onAvailableDevicesChanged(devices);
  1981. APP.store.dispatch(updateDeviceList(devices));
  1982. });
  1983. this.deviceChangeListener = (devices) =>
  1984. window.setTimeout(
  1985. () => this._onDeviceListChanged(devices), 0);
  1986. JitsiMeetJS.mediaDevices.addEventListener(
  1987. JitsiMediaDevicesEvents.DEVICE_LIST_CHANGED,
  1988. this.deviceChangeListener);
  1989. }
  1990. })
  1991. .catch((error) => {
  1992. logger.warn(`Error getting device list: ${error}`);
  1993. });
  1994. },
  1995. /**
  1996. * Event listener for JitsiMediaDevicesEvents.DEVICE_LIST_CHANGED to
  1997. * handle change of available media devices.
  1998. * @private
  1999. * @param {MediaDeviceInfo[]} devices
  2000. * @returns {Promise}
  2001. */
  2002. _onDeviceListChanged(devices) {
  2003. let currentDevices = mediaDeviceHelper.getCurrentMediaDevices();
  2004. // Event handler can be fired before direct
  2005. // enumerateDevices() call, so handle this situation here.
  2006. if (!currentDevices.audioinput &&
  2007. !currentDevices.videoinput &&
  2008. !currentDevices.audiooutput) {
  2009. mediaDeviceHelper.setCurrentMediaDevices(devices);
  2010. currentDevices = mediaDeviceHelper.getCurrentMediaDevices();
  2011. }
  2012. let newDevices =
  2013. mediaDeviceHelper.getNewMediaDevicesAfterDeviceListChanged(
  2014. devices,
  2015. this.isSharingScreen,
  2016. this.localVideo,
  2017. this.localAudio);
  2018. let promises = [];
  2019. let audioWasMuted = this.isLocalAudioMuted();
  2020. let videoWasMuted = this.isLocalVideoMuted();
  2021. let availableAudioInputDevices =
  2022. mediaDeviceHelper.getDevicesFromListByKind(devices, 'audioinput');
  2023. let availableVideoInputDevices =
  2024. mediaDeviceHelper.getDevicesFromListByKind(devices, 'videoinput');
  2025. if (typeof newDevices.audiooutput !== 'undefined') {
  2026. // Just ignore any errors in catch block.
  2027. promises.push(APP.settings
  2028. .setAudioOutputDeviceId(newDevices.audiooutput)
  2029. .catch());
  2030. }
  2031. promises.push(
  2032. mediaDeviceHelper.createLocalTracksAfterDeviceListChanged(
  2033. createLocalTracksF,
  2034. newDevices.videoinput,
  2035. newDevices.audioinput)
  2036. .then(tracks =>
  2037. Promise.all(this._setLocalAudioVideoStreams(tracks)))
  2038. .then(() => {
  2039. // If audio was muted before, or we unplugged current device
  2040. // and selected new one, then mute new audio track.
  2041. if (audioWasMuted ||
  2042. currentDevices.audioinput.length >
  2043. availableAudioInputDevices.length) {
  2044. sendEvent('deviceListChanged.audio.muted');
  2045. logger.log('Audio mute: device list changed');
  2046. muteLocalAudio(true);
  2047. }
  2048. // If video was muted before, or we unplugged current device
  2049. // and selected new one, then mute new video track.
  2050. if (!this.isSharingScreen &&
  2051. (videoWasMuted ||
  2052. currentDevices.videoinput.length >
  2053. availableVideoInputDevices.length)) {
  2054. sendEvent('deviceListChanged.video.muted');
  2055. logger.log('Video mute: device list changed');
  2056. muteLocalVideo(true);
  2057. }
  2058. }));
  2059. return Promise.all(promises)
  2060. .then(() => {
  2061. mediaDeviceHelper.setCurrentMediaDevices(devices);
  2062. APP.UI.onAvailableDevicesChanged(devices);
  2063. });
  2064. },
  2065. /**
  2066. * Determines whether or not the audio button should be enabled.
  2067. */
  2068. updateAudioIconEnabled() {
  2069. const audioMediaDevices
  2070. = mediaDeviceHelper.getCurrentMediaDevices().audioinput;
  2071. const audioDeviceCount
  2072. = audioMediaDevices ? audioMediaDevices.length : 0;
  2073. // The audio functionality is considered available if there are any
  2074. // audio devices detected or if the local audio stream already exists.
  2075. const available = audioDeviceCount > 0 || Boolean(this.localAudio);
  2076. logger.debug(
  2077. 'Microphone button enabled: ' + available,
  2078. 'local audio: ' + this.localAudio,
  2079. 'audio devices: ' + audioMediaDevices,
  2080. 'device count: ' + audioDeviceCount);
  2081. APP.store.dispatch(setAudioAvailable(available));
  2082. APP.API.notifyAudioAvailabilityChanged(available);
  2083. },
  2084. /**
  2085. * Determines whether or not the video button should be enabled.
  2086. */
  2087. updateVideoIconEnabled() {
  2088. const videoMediaDevices
  2089. = mediaDeviceHelper.getCurrentMediaDevices().videoinput;
  2090. const videoDeviceCount
  2091. = videoMediaDevices ? videoMediaDevices.length : 0;
  2092. // The video functionality is considered available if there are any
  2093. // video devices detected or if there is local video stream already
  2094. // active which could be either screensharing stream or a video track
  2095. // created before the permissions were rejected (through browser
  2096. // config).
  2097. const available = videoDeviceCount > 0 || Boolean(this.localVideo);
  2098. logger.debug(
  2099. 'Camera button enabled: ' + available,
  2100. 'local video: ' + this.localVideo,
  2101. 'video devices: ' + videoMediaDevices,
  2102. 'device count: ' + videoDeviceCount);
  2103. APP.store.dispatch(setVideoAvailable(available));
  2104. APP.API.notifyVideoAvailabilityChanged(available);
  2105. },
  2106. /**
  2107. * Toggles the local "raised hand" status.
  2108. */
  2109. maybeToggleRaisedHand() {
  2110. this.setRaisedHand(!this.isHandRaised);
  2111. },
  2112. /**
  2113. * Sets the local "raised hand" status to a particular value.
  2114. */
  2115. setRaisedHand(raisedHand) {
  2116. if (raisedHand !== this.isHandRaised)
  2117. {
  2118. APP.UI.onLocalRaiseHandChanged(raisedHand);
  2119. this.isHandRaised = raisedHand;
  2120. // Advertise the updated status
  2121. room.setLocalParticipantProperty("raisedHand", raisedHand);
  2122. // Update the view
  2123. APP.UI.setLocalRaisedHandStatus(raisedHand);
  2124. }
  2125. },
  2126. /**
  2127. * Log event to callstats and analytics.
  2128. * @param {string} name the event name
  2129. * @param {int} value the value (it's int because google analytics supports
  2130. * only int).
  2131. * @param {string} label short text which provides more info about the event
  2132. * which allows to distinguish between few event cases of the same name
  2133. * NOTE: Should be used after conference.init
  2134. */
  2135. logEvent(name, value, label) {
  2136. sendEvent(name, {value, label});
  2137. if (room) {
  2138. room.sendApplicationLog(JSON.stringify({name, value, label}));
  2139. }
  2140. },
  2141. /**
  2142. * Methods logs an application event given in the JSON format.
  2143. * @param {string} logJSON an event to be logged in JSON format
  2144. */
  2145. logJSON(logJSON) {
  2146. if (room) {
  2147. room.sendApplicationLog(logJSON);
  2148. }
  2149. },
  2150. /**
  2151. * Disconnect from the conference and optionally request user feedback.
  2152. * @param {boolean} [requestFeedback=false] if user feedback should be
  2153. * requested
  2154. */
  2155. hangup(requestFeedback = false) {
  2156. eventEmitter.emit(JitsiMeetConferenceEvents.BEFORE_HANGUP);
  2157. let requestFeedbackPromise;
  2158. if (requestFeedback) {
  2159. requestFeedbackPromise
  2160. = APP.store.dispatch(maybeOpenFeedbackDialog(room))
  2161. // false because the thank you dialog shouldn't be displayed
  2162. .catch(() => Promise.resolve(false));
  2163. } else {
  2164. requestFeedbackPromise = Promise.resolve(true);
  2165. }
  2166. // All promises are returning Promise.resolve to make Promise.all to
  2167. // be resolved when both Promises are finished. Otherwise Promise.all
  2168. // will reject on first rejected Promise and we can redirect the page
  2169. // before all operations are done.
  2170. Promise.all([
  2171. requestFeedbackPromise,
  2172. room.leave().then(disconnect, disconnect)
  2173. ]).then(values => {
  2174. APP.API.notifyReadyToClose();
  2175. maybeRedirectToWelcomePage(values[0]);
  2176. });
  2177. },
  2178. /**
  2179. * Changes the email for the local user
  2180. * @param email {string} the new email
  2181. */
  2182. changeLocalEmail(email = '') {
  2183. const localParticipant = getLocalParticipant(APP.store.getState());
  2184. email = String(email).trim();
  2185. if (email === localParticipant.email) {
  2186. return;
  2187. }
  2188. const localId = localParticipant.id;
  2189. APP.store.dispatch(participantUpdated({
  2190. id: localId,
  2191. local: true,
  2192. email
  2193. }));
  2194. APP.settings.setEmail(email);
  2195. APP.UI.setUserEmail(localId, email);
  2196. sendData(commands.EMAIL, email);
  2197. },
  2198. /**
  2199. * Changes the avatar url for the local user
  2200. * @param url {string} the new url
  2201. */
  2202. changeLocalAvatarUrl(url = '') {
  2203. const { avatarURL, id } = getLocalParticipant(APP.store.getState());
  2204. url = String(url).trim();
  2205. if (url === avatarURL) {
  2206. return;
  2207. }
  2208. APP.store.dispatch(participantUpdated({
  2209. id,
  2210. local: true,
  2211. avatarURL: url
  2212. }));
  2213. APP.settings.setAvatarUrl(url);
  2214. APP.UI.setUserAvatarUrl(id, url);
  2215. sendData(commands.AVATAR_URL, url);
  2216. },
  2217. /**
  2218. * Sends a message via the data channel.
  2219. * @param {string} to the id of the endpoint that should receive the
  2220. * message. If "" - the message will be sent to all participants.
  2221. * @param {object} payload the payload of the message.
  2222. * @throws NetworkError or InvalidStateError or Error if the operation
  2223. * fails.
  2224. */
  2225. sendEndpointMessage(to, payload) {
  2226. room.sendEndpointMessage(to, payload);
  2227. },
  2228. /**
  2229. * Adds new listener.
  2230. * @param {String} eventName the name of the event
  2231. * @param {Function} listener the listener.
  2232. */
  2233. addListener(eventName, listener) {
  2234. eventEmitter.addListener(eventName, listener);
  2235. },
  2236. /**
  2237. * Removes listener.
  2238. * @param {String} eventName the name of the event that triggers the
  2239. * listener
  2240. * @param {Function} listener the listener.
  2241. */
  2242. removeListener(eventName, listener) {
  2243. eventEmitter.removeListener(eventName, listener);
  2244. },
  2245. /**
  2246. * Changes the display name for the local user
  2247. * @param nickname {string} the new display name
  2248. */
  2249. changeLocalDisplayName(nickname = '') {
  2250. const formattedNickname
  2251. = nickname.trim().substr(0, MAX_DISPLAY_NAME_LENGTH);
  2252. const { id, name } = getLocalParticipant(APP.store.getState());
  2253. if (formattedNickname === name) {
  2254. return;
  2255. }
  2256. APP.store.dispatch(participantUpdated({
  2257. id,
  2258. local: true,
  2259. name: formattedNickname
  2260. }));
  2261. APP.settings.setDisplayName(formattedNickname);
  2262. if (room) {
  2263. room.setDisplayName(formattedNickname);
  2264. APP.UI.changeDisplayName(id, formattedNickname);
  2265. }
  2266. },
  2267. /**
  2268. * Returns the desktop sharing source id or undefined if the desktop sharing
  2269. * is not active at the moment.
  2270. *
  2271. * @returns {string|undefined} - The source id. If the track is not desktop
  2272. * track or the source id is not available, undefined will be returned.
  2273. */
  2274. getDesktopSharingSourceId() {
  2275. return this.localVideo.sourceId;
  2276. },
  2277. /**
  2278. * Returns the desktop sharing source type or undefined if the desktop
  2279. * sharing is not active at the moment.
  2280. *
  2281. * @returns {'screen'|'window'|undefined} - The source type. If the track is
  2282. * not desktop track or the source type is not available, undefined will be
  2283. * returned.
  2284. */
  2285. getDesktopSharingSourceType() {
  2286. return this.localVideo.sourceType;
  2287. },
  2288. /**
  2289. * Sets the video muted status.
  2290. *
  2291. * @param {boolean} muted - New muted status.
  2292. */
  2293. setVideoMuteStatus(muted) {
  2294. APP.UI.setVideoMuted(this.getMyUserId(), muted);
  2295. APP.API.notifyVideoMutedStatusChanged(muted);
  2296. },
  2297. /**
  2298. * Sets the audio muted status.
  2299. *
  2300. * @param {boolean} muted - New muted status.
  2301. */
  2302. setAudioMuteStatus(muted) {
  2303. APP.UI.setAudioMuted(this.getMyUserId(), muted);
  2304. APP.API.notifyAudioMutedStatusChanged(muted);
  2305. }
  2306. };