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.

API.js 30KB

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