Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

conference.js 90KB

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