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

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