您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

conference.js 90KB

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