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

conference.js 90KB

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