您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

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