You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

API.js 34KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109
  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 } 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. };
  317. transport.on('event', ({ data, name }) => {
  318. if (name && commands[name]) {
  319. commands[name](...data);
  320. return true;
  321. }
  322. return false;
  323. });
  324. transport.on('request', (request, callback) => {
  325. const { dispatch, getState } = APP.store;
  326. if (processExternalDeviceRequest(dispatch, getState, request, callback)) {
  327. return true;
  328. }
  329. const { name } = request;
  330. switch (name) {
  331. case 'capture-largevideo-screenshot' :
  332. APP.store.dispatch(captureLargeVideoScreenshot())
  333. .then(dataURL => {
  334. let error;
  335. if (!dataURL) {
  336. error = new Error('No large video found!');
  337. }
  338. callback({
  339. error,
  340. dataURL
  341. });
  342. });
  343. break;
  344. case 'invite': {
  345. const { invitees } = request;
  346. if (!Array.isArray(invitees) || invitees.length === 0) {
  347. callback({
  348. error: new Error('Unexpected format of invitees')
  349. });
  350. break;
  351. }
  352. // The store should be already available because API.init is called
  353. // on appWillMount action.
  354. APP.store.dispatch(
  355. invite(invitees, true))
  356. .then(failedInvitees => {
  357. let error;
  358. let result;
  359. if (failedInvitees.length) {
  360. error = new Error('One or more invites failed!');
  361. } else {
  362. result = true;
  363. }
  364. callback({
  365. error,
  366. result
  367. });
  368. });
  369. break;
  370. }
  371. case 'is-audio-muted':
  372. callback(APP.conference.isLocalAudioMuted());
  373. break;
  374. case 'is-video-muted':
  375. callback(APP.conference.isLocalVideoMuted());
  376. break;
  377. case 'is-audio-available':
  378. callback(audioAvailable);
  379. break;
  380. case 'is-video-available':
  381. callback(videoAvailable);
  382. break;
  383. case 'is-sharing-screen':
  384. callback(Boolean(APP.conference.isSharingScreen));
  385. break;
  386. case 'get-content-sharing-participants': {
  387. const tracks = getState()['features/base/tracks'];
  388. const sharingParticipantIds = tracks.filter(tr => tr.videoType === 'desktop').map(t => t.participantId);
  389. callback({
  390. sharingParticipantIds
  391. });
  392. break;
  393. }
  394. default:
  395. return false;
  396. }
  397. return true;
  398. });
  399. }
  400. /**
  401. * Check whether the API should be enabled or not.
  402. *
  403. * @returns {boolean}
  404. */
  405. function shouldBeEnabled() {
  406. return (
  407. typeof API_ID === 'number'
  408. // XXX Enable the API when a JSON Web Token (JWT) is specified in
  409. // the location/URL because then it is very likely that the Jitsi
  410. // Meet (Web) app is being used by an external/wrapping (Web) app
  411. // and, consequently, the latter will need to communicate with the
  412. // former. (The described logic is merely a heuristic though.)
  413. || parseJWTFromURLParams());
  414. }
  415. /**
  416. * Executes on toggle-share-screen command.
  417. *
  418. * @param {boolean} [enable] - Whether this toggle is to explicitly enable or
  419. * disable screensharing. If not defined, the application will automatically
  420. * attempt to toggle between enabled and disabled. This boolean is useful for
  421. * explicitly setting desired screensharing state.
  422. * @returns {void}
  423. */
  424. function toggleScreenSharing(enable) {
  425. if (JitsiMeetJS.isDesktopSharingEnabled()) {
  426. APP.conference.toggleScreenSharing(enable).catch(() => {
  427. logger.warn('Failed to toggle screen-sharing');
  428. });
  429. }
  430. }
  431. /**
  432. * Implements API class that communicates with external API class and provides
  433. * interface to access Jitsi Meet features by external applications that embed
  434. * Jitsi Meet.
  435. */
  436. class API {
  437. _enabled: boolean;
  438. /**
  439. * Initializes the API. Setups message event listeners that will receive
  440. * information from external applications that embed Jitsi Meet. It also
  441. * sends a message to the external application that API is initialized.
  442. *
  443. * @param {Object} options - Optional parameters.
  444. * @returns {void}
  445. */
  446. init() {
  447. if (!shouldBeEnabled()) {
  448. return;
  449. }
  450. /**
  451. * Current status (enabled/disabled) of API.
  452. *
  453. * @private
  454. * @type {boolean}
  455. */
  456. this._enabled = true;
  457. initCommands();
  458. }
  459. /**
  460. * Notify external application (if API is enabled) that the large video
  461. * visibility changed.
  462. *
  463. * @param {boolean} isHidden - True if the large video is hidden and false
  464. * otherwise.
  465. * @returns {void}
  466. */
  467. notifyLargeVideoVisibilityChanged(isHidden: boolean) {
  468. this._sendEvent({
  469. name: 'large-video-visibility-changed',
  470. isVisible: !isHidden
  471. });
  472. }
  473. /**
  474. * Notifies the external application (spot) that the local jitsi-participant
  475. * has a status update.
  476. *
  477. * @param {Object} event - The message to pass onto spot.
  478. * @returns {void}
  479. */
  480. sendProxyConnectionEvent(event: Object) {
  481. this._sendEvent({
  482. name: 'proxy-connection-event',
  483. ...event
  484. });
  485. }
  486. /**
  487. * Sends event to the external application.
  488. *
  489. * @param {Object} event - The event to be sent.
  490. * @returns {void}
  491. */
  492. _sendEvent(event: Object = {}) {
  493. if (this._enabled) {
  494. transport.sendEvent(event);
  495. }
  496. }
  497. /**
  498. * Notify external application (if API is enabled) that the chat state has been updated.
  499. *
  500. * @param {number} unreadCount - The unread messages counter.
  501. * @param {boolean} isOpen - True if the chat panel is open.
  502. * @returns {void}
  503. */
  504. notifyChatUpdated(unreadCount: number, isOpen: boolean) {
  505. this._sendEvent({
  506. name: 'chat-updated',
  507. unreadCount,
  508. isOpen
  509. });
  510. }
  511. /**
  512. * Notify external application (if API is enabled) that message was sent.
  513. *
  514. * @param {string} message - Message body.
  515. * @param {boolean} privateMessage - True if the message was a private message.
  516. * @returns {void}
  517. */
  518. notifySendingChatMessage(message: string, privateMessage: boolean) {
  519. this._sendEvent({
  520. name: 'outgoing-message',
  521. message,
  522. privateMessage
  523. });
  524. }
  525. /**
  526. * Notify external application that the video quality setting has changed.
  527. *
  528. * @param {number} videoQuality - The video quality. The number represents the maximum height of the video streams.
  529. * @returns {void}
  530. */
  531. notifyVideoQualityChanged(videoQuality: number) {
  532. this._sendEvent({
  533. name: 'video-quality-changed',
  534. videoQuality
  535. });
  536. }
  537. /**
  538. * Notify external application (if API is enabled) that message was
  539. * received.
  540. *
  541. * @param {Object} options - Object with the message properties.
  542. * @returns {void}
  543. */
  544. notifyReceivedChatMessage(
  545. { body, id, nick, privateMessage, ts }: {
  546. body: *, id: string, nick: string, privateMessage: boolean, ts: *
  547. } = {}) {
  548. if (APP.conference.isLocalId(id)) {
  549. return;
  550. }
  551. this._sendEvent({
  552. name: 'incoming-message',
  553. from: id,
  554. message: body,
  555. nick,
  556. privateMessage,
  557. stamp: ts
  558. });
  559. }
  560. /**
  561. * Notify external application (if API is enabled) that user joined the
  562. * conference.
  563. *
  564. * @param {string} id - User id.
  565. * @param {Object} props - The display name of the user.
  566. * @returns {void}
  567. */
  568. notifyUserJoined(id: string, props: Object) {
  569. this._sendEvent({
  570. name: 'participant-joined',
  571. id,
  572. ...props
  573. });
  574. }
  575. /**
  576. * Notify external application (if API is enabled) that user left the
  577. * conference.
  578. *
  579. * @param {string} id - User id.
  580. * @returns {void}
  581. */
  582. notifyUserLeft(id: string) {
  583. this._sendEvent({
  584. name: 'participant-left',
  585. id
  586. });
  587. }
  588. /**
  589. * Notify external application (if API is enabled) that the user role
  590. * has changed.
  591. *
  592. * @param {string} id - User id.
  593. * @param {string} role - The new user role.
  594. * @returns {void}
  595. */
  596. notifyUserRoleChanged(id: string, role: string) {
  597. this._sendEvent({
  598. name: 'participant-role-changed',
  599. id,
  600. role
  601. });
  602. }
  603. /**
  604. * Notify external application (if API is enabled) that user changed their
  605. * avatar.
  606. *
  607. * @param {string} id - User id.
  608. * @param {string} avatarURL - The new avatar URL of the participant.
  609. * @returns {void}
  610. */
  611. notifyAvatarChanged(id: string, avatarURL: string) {
  612. this._sendEvent({
  613. name: 'avatar-changed',
  614. avatarURL,
  615. id
  616. });
  617. }
  618. /**
  619. * Notify external application (if API is enabled) that user received
  620. * a text message through datachannels.
  621. *
  622. * @param {Object} data - The event data.
  623. * @returns {void}
  624. */
  625. notifyEndpointTextMessageReceived(data: Object) {
  626. this._sendEvent({
  627. name: 'endpoint-text-message-received',
  628. data
  629. });
  630. }
  631. /**
  632. * Notify external application (if API is enabled) that the list of sharing participants changed.
  633. *
  634. * @param {Object} data - The event data.
  635. * @returns {void}
  636. */
  637. notifySharingParticipantsChanged(data: Object) {
  638. this._sendEvent({
  639. name: 'content-sharing-participants-changed',
  640. data
  641. });
  642. }
  643. /**
  644. * Notify external application (if API is enabled) that the device list has
  645. * changed.
  646. *
  647. * @param {Object} devices - The new device list.
  648. * @returns {void}
  649. */
  650. notifyDeviceListChanged(devices: Object) {
  651. this._sendEvent({
  652. name: 'device-list-changed',
  653. devices
  654. });
  655. }
  656. /**
  657. * Notify external application (if API is enabled) that user changed their
  658. * nickname.
  659. *
  660. * @param {string} id - User id.
  661. * @param {string} displayname - User nickname.
  662. * @param {string} formattedDisplayName - The display name shown in Jitsi
  663. * meet's UI for the user.
  664. * @returns {void}
  665. */
  666. notifyDisplayNameChanged(
  667. id: string,
  668. { displayName, formattedDisplayName }: Object) {
  669. this._sendEvent({
  670. name: 'display-name-change',
  671. displayname: displayName,
  672. formattedDisplayName,
  673. id
  674. });
  675. }
  676. /**
  677. * Notify external application (if API is enabled) that user changed their
  678. * email.
  679. *
  680. * @param {string} id - User id.
  681. * @param {string} email - The new email of the participant.
  682. * @returns {void}
  683. */
  684. notifyEmailChanged(
  685. id: string,
  686. { email }: Object) {
  687. this._sendEvent({
  688. name: 'email-change',
  689. email,
  690. id
  691. });
  692. }
  693. /**
  694. * Notify external application (if API is enabled) that the an error has been logged.
  695. *
  696. * @param {string} logLevel - The message log level.
  697. * @param {Array} args - Array of strings composing the log message.
  698. * @returns {void}
  699. */
  700. notifyLog(logLevel: string, args: Array<string>) {
  701. this._sendEvent({
  702. name: 'log',
  703. logLevel,
  704. args
  705. });
  706. }
  707. /**
  708. * Notify external application (if API is enabled) that the conference has
  709. * been joined.
  710. *
  711. * @param {string} roomName - The room name.
  712. * @param {string} id - The id of the local user.
  713. * @param {Object} props - The display name and avatar URL of the local
  714. * user.
  715. * @returns {void}
  716. */
  717. notifyConferenceJoined(roomName: string, id: string, props: Object) {
  718. this._sendEvent({
  719. name: 'video-conference-joined',
  720. roomName,
  721. id,
  722. ...props
  723. });
  724. }
  725. /**
  726. * Notify external application (if API is enabled) that local user has left the conference.
  727. *
  728. * @param {string} roomName - User id.
  729. * @returns {void}
  730. */
  731. notifyConferenceLeft(roomName: string) {
  732. this._sendEvent({
  733. name: 'video-conference-left',
  734. roomName
  735. });
  736. }
  737. /**
  738. * Notify external application (if API is enabled) that we are ready to be
  739. * closed.
  740. *
  741. * @returns {void}
  742. */
  743. notifyReadyToClose() {
  744. this._sendEvent({ name: 'video-ready-to-close' });
  745. }
  746. /**
  747. * Notify external application (if API is enabled) that a suspend event in host computer.
  748. *
  749. * @returns {void}
  750. */
  751. notifySuspendDetected() {
  752. this._sendEvent({ name: 'suspend-detected' });
  753. }
  754. /**
  755. * Notify external application (if API is enabled) for audio muted status
  756. * changed.
  757. *
  758. * @param {boolean} muted - The new muted status.
  759. * @returns {void}
  760. */
  761. notifyAudioMutedStatusChanged(muted: boolean) {
  762. this._sendEvent({
  763. name: 'audio-mute-status-changed',
  764. muted
  765. });
  766. }
  767. /**
  768. * Notify external application (if API is enabled) for video muted status
  769. * changed.
  770. *
  771. * @param {boolean} muted - The new muted status.
  772. * @returns {void}
  773. */
  774. notifyVideoMutedStatusChanged(muted: boolean) {
  775. this._sendEvent({
  776. name: 'video-mute-status-changed',
  777. muted
  778. });
  779. }
  780. /**
  781. * Notify external application (if API is enabled) for audio availability
  782. * changed.
  783. *
  784. * @param {boolean} available - True if available and false otherwise.
  785. * @returns {void}
  786. */
  787. notifyAudioAvailabilityChanged(available: boolean) {
  788. audioAvailable = available;
  789. this._sendEvent({
  790. name: 'audio-availability-changed',
  791. available
  792. });
  793. }
  794. /**
  795. * Notify external application (if API is enabled) for video available
  796. * status changed.
  797. *
  798. * @param {boolean} available - True if available and false otherwise.
  799. * @returns {void}
  800. */
  801. notifyVideoAvailabilityChanged(available: boolean) {
  802. videoAvailable = available;
  803. this._sendEvent({
  804. name: 'video-availability-changed',
  805. available
  806. });
  807. }
  808. /**
  809. * Notify external application (if API is enabled) that the on stage
  810. * participant has changed.
  811. *
  812. * @param {string} id - User id of the new on stage participant.
  813. * @returns {void}
  814. */
  815. notifyOnStageParticipantChanged(id: string) {
  816. this._sendEvent({
  817. name: 'on-stage-participant-changed',
  818. id
  819. });
  820. }
  821. /**
  822. * Notify external application of an unexpected camera-related error having
  823. * occurred.
  824. *
  825. * @param {string} type - The type of the camera error.
  826. * @param {string} message - Additional information about the error.
  827. * @returns {void}
  828. */
  829. notifyOnCameraError(type: string, message: string) {
  830. this._sendEvent({
  831. name: 'camera-error',
  832. type,
  833. message
  834. });
  835. }
  836. /**
  837. * Notify external application of an unexpected mic-related error having
  838. * occurred.
  839. *
  840. * @param {string} type - The type of the mic error.
  841. * @param {string} message - Additional information about the error.
  842. * @returns {void}
  843. */
  844. notifyOnMicError(type: string, message: string) {
  845. this._sendEvent({
  846. name: 'mic-error',
  847. type,
  848. message
  849. });
  850. }
  851. /**
  852. * Notify external application (if API is enabled) that conference feedback
  853. * has been submitted. Intended to be used in conjunction with the
  854. * submit-feedback command to get notified if feedback was submitted.
  855. *
  856. * @param {string} error - A failure message, if any.
  857. * @returns {void}
  858. */
  859. notifyFeedbackSubmitted(error: string) {
  860. this._sendEvent({
  861. name: 'feedback-submitted',
  862. error
  863. });
  864. }
  865. /**
  866. * Notify external application (if API is enabled) that the feedback prompt
  867. * has been displayed.
  868. *
  869. * @returns {void}
  870. */
  871. notifyFeedbackPromptDisplayed() {
  872. this._sendEvent({ name: 'feedback-prompt-displayed' });
  873. }
  874. /**
  875. * Notify external application (if API is enabled) that the display
  876. * configuration of the filmstrip has been changed.
  877. *
  878. * @param {boolean} visible - Whether or not the filmstrip has been set to
  879. * be displayed or hidden.
  880. * @returns {void}
  881. */
  882. notifyFilmstripDisplayChanged(visible: boolean) {
  883. this._sendEvent({
  884. name: 'filmstrip-display-changed',
  885. visible
  886. });
  887. }
  888. /**
  889. * Notify external application of a participant, remote or local, being
  890. * removed from the conference by another participant.
  891. *
  892. * @param {string} kicked - The ID of the participant removed from the
  893. * conference.
  894. * @param {string} kicker - The ID of the participant that removed the
  895. * other participant.
  896. * @returns {void}
  897. */
  898. notifyKickedOut(kicked: Object, kicker: Object) {
  899. this._sendEvent({
  900. name: 'participant-kicked-out',
  901. kicked,
  902. kicker
  903. });
  904. }
  905. /**
  906. * Notify external application of the current meeting requiring a password
  907. * to join.
  908. *
  909. * @returns {void}
  910. */
  911. notifyOnPasswordRequired() {
  912. this._sendEvent({ name: 'password-required' });
  913. }
  914. /**
  915. * Notify external application (if API is enabled) that the screen sharing
  916. * has been turned on/off.
  917. *
  918. * @param {boolean} on - True if screen sharing is enabled.
  919. * @param {Object} details - Additional information about the screen
  920. * sharing.
  921. * @param {string} details.sourceType - Type of device or window the screen
  922. * share is capturing.
  923. * @returns {void}
  924. */
  925. notifyScreenSharingStatusChanged(on: boolean, details: Object) {
  926. this._sendEvent({
  927. name: 'screen-sharing-status-changed',
  928. on,
  929. details
  930. });
  931. }
  932. /**
  933. * Notify external application (if API is enabled) that the dominant speaker
  934. * has been turned on/off.
  935. *
  936. * @param {string} id - Id of the dominant participant.
  937. * @returns {void}
  938. */
  939. notifyDominantSpeakerChanged(id: string) {
  940. this._sendEvent({
  941. name: 'dominant-speaker-changed',
  942. id
  943. });
  944. }
  945. /**
  946. * Notify external application (if API is enabled) that the conference
  947. * changed their subject.
  948. *
  949. * @param {string} subject - Conference subject.
  950. * @returns {void}
  951. */
  952. notifySubjectChanged(subject: string) {
  953. this._sendEvent({
  954. name: 'subject-change',
  955. subject
  956. });
  957. }
  958. /**
  959. * Notify external application (if API is enabled) that tile view has been
  960. * entered or exited.
  961. *
  962. * @param {string} enabled - True if tile view is currently displayed, false
  963. * otherwise.
  964. * @returns {void}
  965. */
  966. notifyTileViewChanged(enabled: boolean) {
  967. this._sendEvent({
  968. name: 'tile-view-changed',
  969. enabled
  970. });
  971. }
  972. /**
  973. * Notify external application (if API is enabled) that the localStorage has changed.
  974. *
  975. * @param {string} localStorageContent - The new localStorageContent.
  976. * @returns {void}
  977. */
  978. notifyLocalStorageChanged(localStorageContent: string) {
  979. this._sendEvent({
  980. name: 'local-storage-changed',
  981. localStorageContent
  982. });
  983. }
  984. /**
  985. * Notify external application (if API is enabled) that user updated their hand raised.
  986. *
  987. * @param {string} id - User id.
  988. * @param {boolean} handRaised - Whether user has raised hand.
  989. * @returns {void}
  990. */
  991. notifyRaiseHandUpdated(id: string, handRaised: boolean) {
  992. this._sendEvent({
  993. name: 'raise-hand-updated',
  994. handRaised,
  995. id
  996. });
  997. }
  998. /**
  999. * Disposes the allocated resources.
  1000. *
  1001. * @returns {void}
  1002. */
  1003. dispose() {
  1004. if (this._enabled) {
  1005. this._enabled = false;
  1006. }
  1007. }
  1008. }
  1009. export default new API();