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

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