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

API.js 31KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044
  1. // @flow
  2. import Logger from 'jitsi-meet-logger';
  3. import * as JitsiMeetConferenceEvents from '../../ConferenceEvents';
  4. import {
  5. createApiEvent,
  6. sendAnalytics
  7. } from '../../react/features/analytics';
  8. import {
  9. getCurrentConference,
  10. sendTones,
  11. setPassword,
  12. setSubject
  13. } from '../../react/features/base/conference';
  14. import { parseJWTFromURLParams } from '../../react/features/base/jwt';
  15. import { JitsiRecordingConstants } from '../../react/features/base/lib-jitsi-meet';
  16. import { pinParticipant } from '../../react/features/base/participants';
  17. import {
  18. processExternalDeviceRequest
  19. } from '../../react/features/device-selection/functions';
  20. import { isEnabled as isDropboxEnabled } from '../../react/features/dropbox';
  21. import { toggleE2EE } from '../../react/features/e2ee/actions';
  22. import { invite } from '../../react/features/invite';
  23. import {
  24. captureLargeVideoScreenshot,
  25. resizeLargeVideo,
  26. selectParticipantInLargeVideo
  27. } from '../../react/features/large-video/actions';
  28. import { toggleLobbyMode } from '../../react/features/lobby/actions.web';
  29. import { RECORDING_TYPES } from '../../react/features/recording/constants';
  30. import { getActiveSession } from '../../react/features/recording/functions';
  31. import { muteAllParticipants } from '../../react/features/remote-video-menu/actions';
  32. import { toggleTileView } from '../../react/features/video-layout';
  33. import { setVideoQuality } from '../../react/features/video-quality';
  34. import { getJitsiMeetTransport } from '../transport';
  35. import { API_ID, ENDPOINT_TEXT_MESSAGE_NAME } from './constants';
  36. const logger = Logger.getLogger(__filename);
  37. declare var APP: Object;
  38. /**
  39. * List of the available commands.
  40. */
  41. let commands = {};
  42. /**
  43. * The state of screen sharing(started/stopped) before the screen sharing is
  44. * enabled and initialized.
  45. * NOTE: This flag help us to cache the state and use it if toggle-share-screen
  46. * was received before the initialization.
  47. */
  48. let initialScreenSharingState = false;
  49. /**
  50. * The transport instance used for communication with external apps.
  51. *
  52. * @type {Transport}
  53. */
  54. const transport = getJitsiMeetTransport();
  55. /**
  56. * The current audio availability.
  57. *
  58. * @type {boolean}
  59. */
  60. let audioAvailable = true;
  61. /**
  62. * The current video availability.
  63. *
  64. * @type {boolean}
  65. */
  66. let videoAvailable = true;
  67. /**
  68. * Initializes supported commands.
  69. *
  70. * @returns {void}
  71. */
  72. function initCommands() {
  73. commands = {
  74. 'display-name': displayName => {
  75. sendAnalytics(createApiEvent('display.name.changed'));
  76. APP.conference.changeLocalDisplayName(displayName);
  77. },
  78. 'mute-everyone': () => {
  79. sendAnalytics(createApiEvent('muted-everyone'));
  80. const participants = APP.store.getState()['features/base/participants'];
  81. const localIds = participants
  82. .filter(participant => participant.local)
  83. .filter(participant => participant.role === 'moderator')
  84. .map(participant => participant.id);
  85. APP.store.dispatch(muteAllParticipants(localIds));
  86. },
  87. 'toggle-lobby': isLobbyEnabled => {
  88. APP.store.dispatch(toggleLobbyMode(isLobbyEnabled));
  89. },
  90. 'password': password => {
  91. const { conference, passwordRequired }
  92. = APP.store.getState()['features/base/conference'];
  93. if (passwordRequired) {
  94. sendAnalytics(createApiEvent('submit.password'));
  95. APP.store.dispatch(setPassword(
  96. passwordRequired,
  97. passwordRequired.join,
  98. password
  99. ));
  100. } else {
  101. sendAnalytics(createApiEvent('password.changed'));
  102. APP.store.dispatch(setPassword(
  103. conference,
  104. conference.lock,
  105. password
  106. ));
  107. }
  108. },
  109. 'pin-participant': id => {
  110. logger.debug('Pin participant command received');
  111. sendAnalytics(createApiEvent('participant.pinned'));
  112. APP.store.dispatch(pinParticipant(id));
  113. },
  114. 'proxy-connection-event': event => {
  115. APP.conference.onProxyConnectionEvent(event);
  116. },
  117. 'resize-large-video': (width, height) => {
  118. logger.debug('Resize large video command received');
  119. sendAnalytics(createApiEvent('largevideo.resized'));
  120. APP.store.dispatch(resizeLargeVideo(width, height));
  121. },
  122. 'send-tones': (options = {}) => {
  123. const { duration, tones, pause } = options;
  124. APP.store.dispatch(sendTones(tones, duration, pause));
  125. },
  126. 'set-large-video-participant': participantId => {
  127. logger.debug('Set large video participant command received');
  128. sendAnalytics(createApiEvent('largevideo.participant.set'));
  129. APP.store.dispatch(selectParticipantInLargeVideo(participantId));
  130. },
  131. 'subject': subject => {
  132. sendAnalytics(createApiEvent('subject.changed'));
  133. APP.store.dispatch(setSubject(subject));
  134. },
  135. 'submit-feedback': feedback => {
  136. sendAnalytics(createApiEvent('submit.feedback'));
  137. APP.conference.submitFeedback(feedback.score, feedback.message);
  138. },
  139. 'toggle-audio': () => {
  140. sendAnalytics(createApiEvent('toggle-audio'));
  141. logger.log('Audio toggle: API command received');
  142. APP.conference.toggleAudioMuted(false /* no UI */);
  143. },
  144. 'toggle-video': () => {
  145. sendAnalytics(createApiEvent('toggle-video'));
  146. logger.log('Video toggle: API command received');
  147. APP.conference.toggleVideoMuted(false /* no UI */);
  148. },
  149. 'toggle-film-strip': () => {
  150. sendAnalytics(createApiEvent('film.strip.toggled'));
  151. APP.UI.toggleFilmstrip();
  152. },
  153. 'toggle-chat': () => {
  154. sendAnalytics(createApiEvent('chat.toggled'));
  155. APP.UI.toggleChat();
  156. },
  157. /**
  158. * Callback to invoke when the "toggle-share-screen" command is received.
  159. *
  160. * @param {Object} options - Additional details of how to perform
  161. * the action. Note this parameter is undocumented and experimental.
  162. * @param {boolean} options.enable - Whether trying to enable screen
  163. * sharing or to turn it off.
  164. * @returns {void}
  165. */
  166. 'toggle-share-screen': (options = {}) => {
  167. sendAnalytics(createApiEvent('screen.sharing.toggled'));
  168. toggleScreenSharing(options.enable);
  169. },
  170. 'toggle-tile-view': () => {
  171. sendAnalytics(createApiEvent('tile-view.toggled'));
  172. APP.store.dispatch(toggleTileView());
  173. },
  174. 'video-hangup': (showFeedbackDialog = true) => {
  175. sendAnalytics(createApiEvent('video.hangup'));
  176. APP.conference.hangup(showFeedbackDialog);
  177. },
  178. 'email': email => {
  179. sendAnalytics(createApiEvent('email.changed'));
  180. APP.conference.changeLocalEmail(email);
  181. },
  182. 'avatar-url': avatarUrl => {
  183. sendAnalytics(createApiEvent('avatar.url.changed'));
  184. APP.conference.changeLocalAvatarUrl(avatarUrl);
  185. },
  186. 'send-endpoint-text-message': (to, text) => {
  187. logger.debug('Send endpoint message command received');
  188. try {
  189. APP.conference.sendEndpointMessage(to, {
  190. name: ENDPOINT_TEXT_MESSAGE_NAME,
  191. text
  192. });
  193. } catch (err) {
  194. logger.error('Failed sending endpoint text message', err);
  195. }
  196. },
  197. 'toggle-e2ee': enabled => {
  198. logger.debug('Toggle E2EE key command received');
  199. APP.store.dispatch(toggleE2EE(enabled));
  200. },
  201. 'set-video-quality': frameHeight => {
  202. logger.debug('Set video quality command received');
  203. sendAnalytics(createApiEvent('set.video.quality'));
  204. APP.store.dispatch(setVideoQuality(frameHeight));
  205. },
  206. /**
  207. * Starts a file recording or streaming depending on the passed on params.
  208. * For youtube streams, `youtubeStreamKey` must be passed on. `youtubeBroadcastID` is optional.
  209. * For dropbox recording, recording `mode` should be `file` and a dropbox oauth2 token must be provided.
  210. * For file recording, recording `mode` should be `file` and optionally `shouldShare` could be passed on.
  211. * No other params should be passed.
  212. *
  213. * @param { string } arg.mode - Recording mode, either `file` or `stream`.
  214. * @param { string } arg.dropboxToken - Dropbox oauth2 token.
  215. * @param { boolean } arg.shouldShare - Whether the recording should be shared with the participants or not.
  216. * Only applies to certain jitsi meet deploys.
  217. * @param { string } arg.youtubeStreamKey - The youtube stream key.
  218. * @param { string } arg.youtubeBroadcastID - The youtube broacast ID.
  219. * @returns {void}
  220. */
  221. 'start-recording': ({ mode, dropboxToken, shouldShare, youtubeStreamKey, youtubeBroadcastID }) => {
  222. const state = APP.store.getState();
  223. const conference = getCurrentConference(state);
  224. if (!conference) {
  225. logger.error('Conference is not defined');
  226. return;
  227. }
  228. if (dropboxToken && !isDropboxEnabled(state)) {
  229. logger.error('Failed starting recording: dropbox is not enabled on this deployment');
  230. return;
  231. }
  232. if (mode === JitsiRecordingConstants.mode.STREAM && !youtubeStreamKey) {
  233. logger.error('Failed starting recording: missing youtube stream key');
  234. return;
  235. }
  236. let recordingConfig;
  237. if (mode === JitsiRecordingConstants.mode.FILE) {
  238. if (dropboxToken) {
  239. recordingConfig = {
  240. mode: JitsiRecordingConstants.mode.FILE,
  241. appData: JSON.stringify({
  242. 'file_recording_metadata': {
  243. 'upload_credentials': {
  244. 'service_name': RECORDING_TYPES.DROPBOX,
  245. 'token': dropboxToken
  246. }
  247. }
  248. })
  249. };
  250. } else {
  251. recordingConfig = {
  252. mode: JitsiRecordingConstants.mode.FILE,
  253. appData: JSON.stringify({
  254. 'file_recording_metadata': {
  255. 'share': shouldShare
  256. }
  257. })
  258. };
  259. }
  260. } else if (mode === JitsiRecordingConstants.mode.STREAM) {
  261. recordingConfig = {
  262. broadcastId: youtubeBroadcastID,
  263. mode: JitsiRecordingConstants.mode.STREAM,
  264. streamId: youtubeStreamKey
  265. };
  266. } else {
  267. logger.error('Invalid recording mode provided');
  268. return;
  269. }
  270. conference.startRecording(recordingConfig);
  271. },
  272. /**
  273. * Stops a recording or streaming in progress.
  274. *
  275. * @param {string} mode - `file` or `stream`.
  276. * @returns {void}
  277. */
  278. 'stop-recording': mode => {
  279. const state = APP.store.getState();
  280. const conference = getCurrentConference(state);
  281. if (!conference) {
  282. logger.error('Conference is not defined');
  283. return;
  284. }
  285. if (![ JitsiRecordingConstants.mode.FILE, JitsiRecordingConstants.mode.STREAM ].includes(mode)) {
  286. logger.error('Invalid recording mode provided!');
  287. return;
  288. }
  289. const activeSession = getActiveSession(state, mode);
  290. if (activeSession && activeSession.id) {
  291. conference.stopRecording(activeSession.id);
  292. } else {
  293. logger.error('No recording or streaming session found');
  294. }
  295. }
  296. };
  297. transport.on('event', ({ data, name }) => {
  298. if (name && commands[name]) {
  299. commands[name](...data);
  300. return true;
  301. }
  302. return false;
  303. });
  304. transport.on('request', (request, callback) => {
  305. const { dispatch, getState } = APP.store;
  306. if (processExternalDeviceRequest(dispatch, getState, request, callback)) {
  307. return true;
  308. }
  309. const { name } = request;
  310. switch (name) {
  311. case 'capture-largevideo-screenshot' :
  312. APP.store.dispatch(captureLargeVideoScreenshot())
  313. .then(dataURL => {
  314. let error;
  315. if (!dataURL) {
  316. error = new Error('No large video found!');
  317. }
  318. callback({
  319. error,
  320. dataURL
  321. });
  322. });
  323. break;
  324. case 'invite': {
  325. const { invitees } = request;
  326. if (!Array.isArray(invitees) || invitees.length === 0) {
  327. callback({
  328. error: new Error('Unexpected format of invitees')
  329. });
  330. break;
  331. }
  332. // The store should be already available because API.init is called
  333. // on appWillMount action.
  334. APP.store.dispatch(
  335. invite(invitees, true))
  336. .then(failedInvitees => {
  337. let error;
  338. let result;
  339. if (failedInvitees.length) {
  340. error = new Error('One or more invites failed!');
  341. } else {
  342. result = true;
  343. }
  344. callback({
  345. error,
  346. result
  347. });
  348. });
  349. break;
  350. }
  351. case 'is-audio-muted':
  352. callback(APP.conference.isLocalAudioMuted());
  353. break;
  354. case 'is-video-muted':
  355. callback(APP.conference.isLocalVideoMuted());
  356. break;
  357. case 'is-audio-available':
  358. callback(audioAvailable);
  359. break;
  360. case 'is-video-available':
  361. callback(videoAvailable);
  362. break;
  363. case 'is-sharing-screen':
  364. callback(Boolean(APP.conference.isSharingScreen));
  365. break;
  366. default:
  367. return false;
  368. }
  369. return true;
  370. });
  371. }
  372. /**
  373. * Listens for desktop/screen sharing enabled events and toggles the screen
  374. * sharing if needed.
  375. *
  376. * @param {boolean} enabled - Current screen sharing enabled status.
  377. * @returns {void}
  378. */
  379. function onDesktopSharingEnabledChanged(enabled = false) {
  380. if (enabled && initialScreenSharingState) {
  381. toggleScreenSharing();
  382. }
  383. }
  384. /**
  385. * Check whether the API should be enabled or not.
  386. *
  387. * @returns {boolean}
  388. */
  389. function shouldBeEnabled() {
  390. return (
  391. typeof API_ID === 'number'
  392. // XXX Enable the API when a JSON Web Token (JWT) is specified in
  393. // the location/URL because then it is very likely that the Jitsi
  394. // Meet (Web) app is being used by an external/wrapping (Web) app
  395. // and, consequently, the latter will need to communicate with the
  396. // former. (The described logic is merely a heuristic though.)
  397. || parseJWTFromURLParams());
  398. }
  399. /**
  400. * Executes on toggle-share-screen command.
  401. *
  402. * @param {boolean} [enable] - Whether this toggle is to explicitly enable or
  403. * disable screensharing. If not defined, the application will automatically
  404. * attempt to toggle between enabled and disabled. This boolean is useful for
  405. * explicitly setting desired screensharing state.
  406. * @returns {void}
  407. */
  408. function toggleScreenSharing(enable) {
  409. if (APP.conference.isDesktopSharingEnabled) {
  410. // eslint-disable-next-line no-empty-function
  411. APP.conference.toggleScreenSharing(enable).catch(() => {});
  412. } else {
  413. initialScreenSharingState = !initialScreenSharingState;
  414. }
  415. }
  416. /**
  417. * Implements API class that communicates with external API class and provides
  418. * interface to access Jitsi Meet features by external applications that embed
  419. * Jitsi Meet.
  420. */
  421. class API {
  422. _enabled: boolean;
  423. /**
  424. * Initializes the API. Setups message event listeners that will receive
  425. * information from external applications that embed Jitsi Meet. It also
  426. * sends a message to the external application that API is initialized.
  427. *
  428. * @param {Object} options - Optional parameters.
  429. * @returns {void}
  430. */
  431. init() {
  432. if (!shouldBeEnabled()) {
  433. return;
  434. }
  435. /**
  436. * Current status (enabled/disabled) of API.
  437. *
  438. * @private
  439. * @type {boolean}
  440. */
  441. this._enabled = true;
  442. APP.conference.addListener(
  443. JitsiMeetConferenceEvents.DESKTOP_SHARING_ENABLED_CHANGED,
  444. onDesktopSharingEnabledChanged);
  445. initCommands();
  446. }
  447. /**
  448. * Notify external application (if API is enabled) that the large video
  449. * visibility changed.
  450. *
  451. * @param {boolean} isHidden - True if the large video is hidden and false
  452. * otherwise.
  453. * @returns {void}
  454. */
  455. notifyLargeVideoVisibilityChanged(isHidden: boolean) {
  456. this._sendEvent({
  457. name: 'large-video-visibility-changed',
  458. isVisible: !isHidden
  459. });
  460. }
  461. /**
  462. * Notifies the external application (spot) that the local jitsi-participant
  463. * has a status update.
  464. *
  465. * @param {Object} event - The message to pass onto spot.
  466. * @returns {void}
  467. */
  468. sendProxyConnectionEvent(event: Object) {
  469. this._sendEvent({
  470. name: 'proxy-connection-event',
  471. ...event
  472. });
  473. }
  474. /**
  475. * Sends event to the external application.
  476. *
  477. * @param {Object} event - The event to be sent.
  478. * @returns {void}
  479. */
  480. _sendEvent(event: Object = {}) {
  481. if (this._enabled) {
  482. transport.sendEvent(event);
  483. }
  484. }
  485. /**
  486. * Notify external application (if API is enabled) that message was sent.
  487. *
  488. * @param {string} message - Message body.
  489. * @param {boolean} privateMessage - True if the message was a private message.
  490. * @returns {void}
  491. */
  492. notifySendingChatMessage(message: string, privateMessage: boolean) {
  493. this._sendEvent({
  494. name: 'outgoing-message',
  495. message,
  496. privateMessage
  497. });
  498. }
  499. /**
  500. * Notify external application that the video quality setting has changed.
  501. *
  502. * @param {number} videoQuality - The video quality. The number represents the maximum height of the video streams.
  503. * @returns {void}
  504. */
  505. notifyVideoQualityChanged(videoQuality: number) {
  506. this._sendEvent({
  507. name: 'video-quality-changed',
  508. videoQuality
  509. });
  510. }
  511. /**
  512. * Notify external application (if API is enabled) that message was
  513. * received.
  514. *
  515. * @param {Object} options - Object with the message properties.
  516. * @returns {void}
  517. */
  518. notifyReceivedChatMessage(
  519. { body, id, nick, ts }: {
  520. body: *, id: string, nick: string, ts: *
  521. } = {}) {
  522. if (APP.conference.isLocalId(id)) {
  523. return;
  524. }
  525. this._sendEvent({
  526. name: 'incoming-message',
  527. from: id,
  528. message: body,
  529. nick,
  530. stamp: ts
  531. });
  532. }
  533. /**
  534. * Notify external application (if API is enabled) that user joined the
  535. * conference.
  536. *
  537. * @param {string} id - User id.
  538. * @param {Object} props - The display name of the user.
  539. * @returns {void}
  540. */
  541. notifyUserJoined(id: string, props: Object) {
  542. this._sendEvent({
  543. name: 'participant-joined',
  544. id,
  545. ...props
  546. });
  547. }
  548. /**
  549. * Notify external application (if API is enabled) that user left the
  550. * conference.
  551. *
  552. * @param {string} id - User id.
  553. * @returns {void}
  554. */
  555. notifyUserLeft(id: string) {
  556. this._sendEvent({
  557. name: 'participant-left',
  558. id
  559. });
  560. }
  561. /**
  562. * Notify external application (if API is enabled) that the user role
  563. * has changed.
  564. *
  565. * @param {string} id - User id.
  566. * @param {string} role - The new user role.
  567. * @returns {void}
  568. */
  569. notifyUserRoleChanged(id: string, role: string) {
  570. this._sendEvent({
  571. name: 'participant-role-changed',
  572. id,
  573. role
  574. });
  575. }
  576. /**
  577. * Notify external application (if API is enabled) that user changed their
  578. * avatar.
  579. *
  580. * @param {string} id - User id.
  581. * @param {string} avatarURL - The new avatar URL of the participant.
  582. * @returns {void}
  583. */
  584. notifyAvatarChanged(id: string, avatarURL: string) {
  585. this._sendEvent({
  586. name: 'avatar-changed',
  587. avatarURL,
  588. id
  589. });
  590. }
  591. /**
  592. * Notify external application (if API is enabled) that user received
  593. * a text message through datachannels.
  594. *
  595. * @param {Object} data - The event data.
  596. * @returns {void}
  597. */
  598. notifyEndpointTextMessageReceived(data: Object) {
  599. this._sendEvent({
  600. name: 'endpoint-text-message-received',
  601. data
  602. });
  603. }
  604. /**
  605. * Notify external application (if API is enabled) that the device list has
  606. * changed.
  607. *
  608. * @param {Object} devices - The new device list.
  609. * @returns {void}
  610. */
  611. notifyDeviceListChanged(devices: Object) {
  612. this._sendEvent({
  613. name: 'device-list-changed',
  614. devices
  615. });
  616. }
  617. /**
  618. * Notify external application (if API is enabled) that user changed their
  619. * nickname.
  620. *
  621. * @param {string} id - User id.
  622. * @param {string} displayname - User nickname.
  623. * @param {string} formattedDisplayName - The display name shown in Jitsi
  624. * meet's UI for the user.
  625. * @returns {void}
  626. */
  627. notifyDisplayNameChanged(
  628. id: string,
  629. { displayName, formattedDisplayName }: Object) {
  630. this._sendEvent({
  631. name: 'display-name-change',
  632. displayname: displayName,
  633. formattedDisplayName,
  634. id
  635. });
  636. }
  637. /**
  638. * Notify external application (if API is enabled) that user changed their
  639. * email.
  640. *
  641. * @param {string} id - User id.
  642. * @param {string} email - The new email of the participant.
  643. * @returns {void}
  644. */
  645. notifyEmailChanged(
  646. id: string,
  647. { email }: Object) {
  648. this._sendEvent({
  649. name: 'email-change',
  650. email,
  651. id
  652. });
  653. }
  654. /**
  655. * Notify external application (if API is enabled) that the an error has been logged.
  656. *
  657. * @param {string} logLevel - The message log level.
  658. * @param {Array} args - Array of strings composing the log message.
  659. * @returns {void}
  660. */
  661. notifyLog(logLevel: string, args: Array<string>) {
  662. this._sendEvent({
  663. name: 'log',
  664. logLevel,
  665. args
  666. });
  667. }
  668. /**
  669. * Notify external application (if API is enabled) that the conference has
  670. * been joined.
  671. *
  672. * @param {string} roomName - The room name.
  673. * @param {string} id - The id of the local user.
  674. * @param {Object} props - The display name and avatar URL of the local
  675. * user.
  676. * @returns {void}
  677. */
  678. notifyConferenceJoined(roomName: string, id: string, props: Object) {
  679. this._sendEvent({
  680. name: 'video-conference-joined',
  681. roomName,
  682. id,
  683. ...props
  684. });
  685. }
  686. /**
  687. * Notify external application (if API is enabled) that local user has left the conference.
  688. *
  689. * @param {string} roomName - User id.
  690. * @returns {void}
  691. */
  692. notifyConferenceLeft(roomName: string) {
  693. this._sendEvent({
  694. name: 'video-conference-left',
  695. roomName
  696. });
  697. }
  698. /**
  699. * Notify external application (if API is enabled) that we are ready to be
  700. * closed.
  701. *
  702. * @returns {void}
  703. */
  704. notifyReadyToClose() {
  705. this._sendEvent({ name: 'video-ready-to-close' });
  706. }
  707. /**
  708. * Notify external application (if API is enabled) that a suspend event in host computer.
  709. *
  710. * @returns {void}
  711. */
  712. notifySuspendDetected() {
  713. this._sendEvent({ name: 'suspend-detected' });
  714. }
  715. /**
  716. * Notify external application (if API is enabled) for audio muted status
  717. * changed.
  718. *
  719. * @param {boolean} muted - The new muted status.
  720. * @returns {void}
  721. */
  722. notifyAudioMutedStatusChanged(muted: boolean) {
  723. this._sendEvent({
  724. name: 'audio-mute-status-changed',
  725. muted
  726. });
  727. }
  728. /**
  729. * Notify external application (if API is enabled) for video muted status
  730. * changed.
  731. *
  732. * @param {boolean} muted - The new muted status.
  733. * @returns {void}
  734. */
  735. notifyVideoMutedStatusChanged(muted: boolean) {
  736. this._sendEvent({
  737. name: 'video-mute-status-changed',
  738. muted
  739. });
  740. }
  741. /**
  742. * Notify external application (if API is enabled) for audio availability
  743. * changed.
  744. *
  745. * @param {boolean} available - True if available and false otherwise.
  746. * @returns {void}
  747. */
  748. notifyAudioAvailabilityChanged(available: boolean) {
  749. audioAvailable = available;
  750. this._sendEvent({
  751. name: 'audio-availability-changed',
  752. available
  753. });
  754. }
  755. /**
  756. * Notify external application (if API is enabled) for video available
  757. * status changed.
  758. *
  759. * @param {boolean} available - True if available and false otherwise.
  760. * @returns {void}
  761. */
  762. notifyVideoAvailabilityChanged(available: boolean) {
  763. videoAvailable = available;
  764. this._sendEvent({
  765. name: 'video-availability-changed',
  766. available
  767. });
  768. }
  769. /**
  770. * Notify external application (if API is enabled) that the on stage
  771. * participant has changed.
  772. *
  773. * @param {string} id - User id of the new on stage participant.
  774. * @returns {void}
  775. */
  776. notifyOnStageParticipantChanged(id: string) {
  777. this._sendEvent({
  778. name: 'on-stage-participant-changed',
  779. id
  780. });
  781. }
  782. /**
  783. * Notify external application of an unexpected camera-related error having
  784. * occurred.
  785. *
  786. * @param {string} type - The type of the camera error.
  787. * @param {string} message - Additional information about the error.
  788. * @returns {void}
  789. */
  790. notifyOnCameraError(type: string, message: string) {
  791. this._sendEvent({
  792. name: 'camera-error',
  793. type,
  794. message
  795. });
  796. }
  797. /**
  798. * Notify external application of an unexpected mic-related error having
  799. * occurred.
  800. *
  801. * @param {string} type - The type of the mic error.
  802. * @param {string} message - Additional information about the error.
  803. * @returns {void}
  804. */
  805. notifyOnMicError(type: string, message: string) {
  806. this._sendEvent({
  807. name: 'mic-error',
  808. type,
  809. message
  810. });
  811. }
  812. /**
  813. * Notify external application (if API is enabled) that conference feedback
  814. * has been submitted. Intended to be used in conjunction with the
  815. * submit-feedback command to get notified if feedback was submitted.
  816. *
  817. * @param {string} error - A failure message, if any.
  818. * @returns {void}
  819. */
  820. notifyFeedbackSubmitted(error: string) {
  821. this._sendEvent({
  822. name: 'feedback-submitted',
  823. error
  824. });
  825. }
  826. /**
  827. * Notify external application (if API is enabled) that the feedback prompt
  828. * has been displayed.
  829. *
  830. * @returns {void}
  831. */
  832. notifyFeedbackPromptDisplayed() {
  833. this._sendEvent({ name: 'feedback-prompt-displayed' });
  834. }
  835. /**
  836. * Notify external application (if API is enabled) that the display
  837. * configuration of the filmstrip has been changed.
  838. *
  839. * @param {boolean} visible - Whether or not the filmstrip has been set to
  840. * be displayed or hidden.
  841. * @returns {void}
  842. */
  843. notifyFilmstripDisplayChanged(visible: boolean) {
  844. this._sendEvent({
  845. name: 'filmstrip-display-changed',
  846. visible
  847. });
  848. }
  849. /**
  850. * Notify external application of a participant, remote or local, being
  851. * removed from the conference by another participant.
  852. *
  853. * @param {string} kicked - The ID of the participant removed from the
  854. * conference.
  855. * @param {string} kicker - The ID of the participant that removed the
  856. * other participant.
  857. * @returns {void}
  858. */
  859. notifyKickedOut(kicked: Object, kicker: Object) {
  860. this._sendEvent({
  861. name: 'participant-kicked-out',
  862. kicked,
  863. kicker
  864. });
  865. }
  866. /**
  867. * Notify external application of the current meeting requiring a password
  868. * to join.
  869. *
  870. * @returns {void}
  871. */
  872. notifyOnPasswordRequired() {
  873. this._sendEvent({ name: 'password-required' });
  874. }
  875. /**
  876. * Notify external application (if API is enabled) that the screen sharing
  877. * has been turned on/off.
  878. *
  879. * @param {boolean} on - True if screen sharing is enabled.
  880. * @param {Object} details - Additional information about the screen
  881. * sharing.
  882. * @param {string} details.sourceType - Type of device or window the screen
  883. * share is capturing.
  884. * @returns {void}
  885. */
  886. notifyScreenSharingStatusChanged(on: boolean, details: Object) {
  887. this._sendEvent({
  888. name: 'screen-sharing-status-changed',
  889. on,
  890. details
  891. });
  892. }
  893. /**
  894. * Notify external application (if API is enabled) that the dominant speaker
  895. * has been turned on/off.
  896. *
  897. * @param {string} id - Id of the dominant participant.
  898. * @returns {void}
  899. */
  900. notifyDominantSpeakerChanged(id: string) {
  901. this._sendEvent({
  902. name: 'dominant-speaker-changed',
  903. id
  904. });
  905. }
  906. /**
  907. * Notify external application (if API is enabled) that the conference
  908. * changed their subject.
  909. *
  910. * @param {string} subject - Conference subject.
  911. * @returns {void}
  912. */
  913. notifySubjectChanged(subject: string) {
  914. this._sendEvent({
  915. name: 'subject-change',
  916. subject
  917. });
  918. }
  919. /**
  920. * Notify external application (if API is enabled) that tile view has been
  921. * entered or exited.
  922. *
  923. * @param {string} enabled - True if tile view is currently displayed, false
  924. * otherwise.
  925. * @returns {void}
  926. */
  927. notifyTileViewChanged(enabled: boolean) {
  928. this._sendEvent({
  929. name: 'tile-view-changed',
  930. enabled
  931. });
  932. }
  933. /**
  934. * Disposes the allocated resources.
  935. *
  936. * @returns {void}
  937. */
  938. dispose() {
  939. if (this._enabled) {
  940. this._enabled = false;
  941. APP.conference.removeListener(
  942. JitsiMeetConferenceEvents.DESKTOP_SHARING_ENABLED_CHANGED,
  943. onDesktopSharingEnabledChanged);
  944. }
  945. }
  946. }
  947. export default new API();