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 32KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057
  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. * Notify external application (if API is enabled) that the localStorage has changed.
  935. *
  936. * @param {string} localStorageContent - The new localStorageContent.
  937. * @returns {void}
  938. */
  939. notifyLocalStorageChanged(localStorageContent: string) {
  940. this._sendEvent({
  941. name: 'local-storage-changed',
  942. localStorageContent
  943. });
  944. }
  945. /**
  946. * Disposes the allocated resources.
  947. *
  948. * @returns {void}
  949. */
  950. dispose() {
  951. if (this._enabled) {
  952. this._enabled = false;
  953. APP.conference.removeListener(
  954. JitsiMeetConferenceEvents.DESKTOP_SHARING_ENABLED_CHANGED,
  955. onDesktopSharingEnabledChanged);
  956. }
  957. }
  958. }
  959. export default new API();