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

conference.js 90KB

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