選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

API.js 37KB

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