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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094
  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 message was sent.
  499. *
  500. * @param {string} message - Message body.
  501. * @param {boolean} privateMessage - True if the message was a private message.
  502. * @returns {void}
  503. */
  504. notifySendingChatMessage(message: string, privateMessage: boolean) {
  505. this._sendEvent({
  506. name: 'outgoing-message',
  507. message,
  508. privateMessage
  509. });
  510. }
  511. /**
  512. * Notify external application that the video quality setting has changed.
  513. *
  514. * @param {number} videoQuality - The video quality. The number represents the maximum height of the video streams.
  515. * @returns {void}
  516. */
  517. notifyVideoQualityChanged(videoQuality: number) {
  518. this._sendEvent({
  519. name: 'video-quality-changed',
  520. videoQuality
  521. });
  522. }
  523. /**
  524. * Notify external application (if API is enabled) that message was
  525. * received.
  526. *
  527. * @param {Object} options - Object with the message properties.
  528. * @returns {void}
  529. */
  530. notifyReceivedChatMessage(
  531. { body, id, nick, privateMessage, ts }: {
  532. body: *, id: string, nick: string, privateMessage: boolean, ts: *
  533. } = {}) {
  534. if (APP.conference.isLocalId(id)) {
  535. return;
  536. }
  537. this._sendEvent({
  538. name: 'incoming-message',
  539. from: id,
  540. message: body,
  541. nick,
  542. privateMessage,
  543. stamp: ts
  544. });
  545. }
  546. /**
  547. * Notify external application (if API is enabled) that user joined the
  548. * conference.
  549. *
  550. * @param {string} id - User id.
  551. * @param {Object} props - The display name of the user.
  552. * @returns {void}
  553. */
  554. notifyUserJoined(id: string, props: Object) {
  555. this._sendEvent({
  556. name: 'participant-joined',
  557. id,
  558. ...props
  559. });
  560. }
  561. /**
  562. * Notify external application (if API is enabled) that user left the
  563. * conference.
  564. *
  565. * @param {string} id - User id.
  566. * @returns {void}
  567. */
  568. notifyUserLeft(id: string) {
  569. this._sendEvent({
  570. name: 'participant-left',
  571. id
  572. });
  573. }
  574. /**
  575. * Notify external application (if API is enabled) that the user role
  576. * has changed.
  577. *
  578. * @param {string} id - User id.
  579. * @param {string} role - The new user role.
  580. * @returns {void}
  581. */
  582. notifyUserRoleChanged(id: string, role: string) {
  583. this._sendEvent({
  584. name: 'participant-role-changed',
  585. id,
  586. role
  587. });
  588. }
  589. /**
  590. * Notify external application (if API is enabled) that user changed their
  591. * avatar.
  592. *
  593. * @param {string} id - User id.
  594. * @param {string} avatarURL - The new avatar URL of the participant.
  595. * @returns {void}
  596. */
  597. notifyAvatarChanged(id: string, avatarURL: string) {
  598. this._sendEvent({
  599. name: 'avatar-changed',
  600. avatarURL,
  601. id
  602. });
  603. }
  604. /**
  605. * Notify external application (if API is enabled) that user received
  606. * a text message through datachannels.
  607. *
  608. * @param {Object} data - The event data.
  609. * @returns {void}
  610. */
  611. notifyEndpointTextMessageReceived(data: Object) {
  612. this._sendEvent({
  613. name: 'endpoint-text-message-received',
  614. data
  615. });
  616. }
  617. /**
  618. * Notify external application (if API is enabled) that the list of sharing participants changed.
  619. *
  620. * @param {Object} data - The event data.
  621. * @returns {void}
  622. */
  623. notifySharingParticipantsChanged(data: Object) {
  624. this._sendEvent({
  625. name: 'content-sharing-participants-changed',
  626. data
  627. });
  628. }
  629. /**
  630. * Notify external application (if API is enabled) that the device list has
  631. * changed.
  632. *
  633. * @param {Object} devices - The new device list.
  634. * @returns {void}
  635. */
  636. notifyDeviceListChanged(devices: Object) {
  637. this._sendEvent({
  638. name: 'device-list-changed',
  639. devices
  640. });
  641. }
  642. /**
  643. * Notify external application (if API is enabled) that user changed their
  644. * nickname.
  645. *
  646. * @param {string} id - User id.
  647. * @param {string} displayname - User nickname.
  648. * @param {string} formattedDisplayName - The display name shown in Jitsi
  649. * meet's UI for the user.
  650. * @returns {void}
  651. */
  652. notifyDisplayNameChanged(
  653. id: string,
  654. { displayName, formattedDisplayName }: Object) {
  655. this._sendEvent({
  656. name: 'display-name-change',
  657. displayname: displayName,
  658. formattedDisplayName,
  659. id
  660. });
  661. }
  662. /**
  663. * Notify external application (if API is enabled) that user changed their
  664. * email.
  665. *
  666. * @param {string} id - User id.
  667. * @param {string} email - The new email of the participant.
  668. * @returns {void}
  669. */
  670. notifyEmailChanged(
  671. id: string,
  672. { email }: Object) {
  673. this._sendEvent({
  674. name: 'email-change',
  675. email,
  676. id
  677. });
  678. }
  679. /**
  680. * Notify external application (if API is enabled) that the an error has been logged.
  681. *
  682. * @param {string} logLevel - The message log level.
  683. * @param {Array} args - Array of strings composing the log message.
  684. * @returns {void}
  685. */
  686. notifyLog(logLevel: string, args: Array<string>) {
  687. this._sendEvent({
  688. name: 'log',
  689. logLevel,
  690. args
  691. });
  692. }
  693. /**
  694. * Notify external application (if API is enabled) that the conference has
  695. * been joined.
  696. *
  697. * @param {string} roomName - The room name.
  698. * @param {string} id - The id of the local user.
  699. * @param {Object} props - The display name and avatar URL of the local
  700. * user.
  701. * @returns {void}
  702. */
  703. notifyConferenceJoined(roomName: string, id: string, props: Object) {
  704. this._sendEvent({
  705. name: 'video-conference-joined',
  706. roomName,
  707. id,
  708. ...props
  709. });
  710. }
  711. /**
  712. * Notify external application (if API is enabled) that local user has left the conference.
  713. *
  714. * @param {string} roomName - User id.
  715. * @returns {void}
  716. */
  717. notifyConferenceLeft(roomName: string) {
  718. this._sendEvent({
  719. name: 'video-conference-left',
  720. roomName
  721. });
  722. }
  723. /**
  724. * Notify external application (if API is enabled) that we are ready to be
  725. * closed.
  726. *
  727. * @returns {void}
  728. */
  729. notifyReadyToClose() {
  730. this._sendEvent({ name: 'video-ready-to-close' });
  731. }
  732. /**
  733. * Notify external application (if API is enabled) that a suspend event in host computer.
  734. *
  735. * @returns {void}
  736. */
  737. notifySuspendDetected() {
  738. this._sendEvent({ name: 'suspend-detected' });
  739. }
  740. /**
  741. * Notify external application (if API is enabled) for audio muted status
  742. * changed.
  743. *
  744. * @param {boolean} muted - The new muted status.
  745. * @returns {void}
  746. */
  747. notifyAudioMutedStatusChanged(muted: boolean) {
  748. this._sendEvent({
  749. name: 'audio-mute-status-changed',
  750. muted
  751. });
  752. }
  753. /**
  754. * Notify external application (if API is enabled) for video muted status
  755. * changed.
  756. *
  757. * @param {boolean} muted - The new muted status.
  758. * @returns {void}
  759. */
  760. notifyVideoMutedStatusChanged(muted: boolean) {
  761. this._sendEvent({
  762. name: 'video-mute-status-changed',
  763. muted
  764. });
  765. }
  766. /**
  767. * Notify external application (if API is enabled) for audio availability
  768. * changed.
  769. *
  770. * @param {boolean} available - True if available and false otherwise.
  771. * @returns {void}
  772. */
  773. notifyAudioAvailabilityChanged(available: boolean) {
  774. audioAvailable = available;
  775. this._sendEvent({
  776. name: 'audio-availability-changed',
  777. available
  778. });
  779. }
  780. /**
  781. * Notify external application (if API is enabled) for video available
  782. * status changed.
  783. *
  784. * @param {boolean} available - True if available and false otherwise.
  785. * @returns {void}
  786. */
  787. notifyVideoAvailabilityChanged(available: boolean) {
  788. videoAvailable = available;
  789. this._sendEvent({
  790. name: 'video-availability-changed',
  791. available
  792. });
  793. }
  794. /**
  795. * Notify external application (if API is enabled) that the on stage
  796. * participant has changed.
  797. *
  798. * @param {string} id - User id of the new on stage participant.
  799. * @returns {void}
  800. */
  801. notifyOnStageParticipantChanged(id: string) {
  802. this._sendEvent({
  803. name: 'on-stage-participant-changed',
  804. id
  805. });
  806. }
  807. /**
  808. * Notify external application of an unexpected camera-related error having
  809. * occurred.
  810. *
  811. * @param {string} type - The type of the camera error.
  812. * @param {string} message - Additional information about the error.
  813. * @returns {void}
  814. */
  815. notifyOnCameraError(type: string, message: string) {
  816. this._sendEvent({
  817. name: 'camera-error',
  818. type,
  819. message
  820. });
  821. }
  822. /**
  823. * Notify external application of an unexpected mic-related error having
  824. * occurred.
  825. *
  826. * @param {string} type - The type of the mic error.
  827. * @param {string} message - Additional information about the error.
  828. * @returns {void}
  829. */
  830. notifyOnMicError(type: string, message: string) {
  831. this._sendEvent({
  832. name: 'mic-error',
  833. type,
  834. message
  835. });
  836. }
  837. /**
  838. * Notify external application (if API is enabled) that conference feedback
  839. * has been submitted. Intended to be used in conjunction with the
  840. * submit-feedback command to get notified if feedback was submitted.
  841. *
  842. * @param {string} error - A failure message, if any.
  843. * @returns {void}
  844. */
  845. notifyFeedbackSubmitted(error: string) {
  846. this._sendEvent({
  847. name: 'feedback-submitted',
  848. error
  849. });
  850. }
  851. /**
  852. * Notify external application (if API is enabled) that the feedback prompt
  853. * has been displayed.
  854. *
  855. * @returns {void}
  856. */
  857. notifyFeedbackPromptDisplayed() {
  858. this._sendEvent({ name: 'feedback-prompt-displayed' });
  859. }
  860. /**
  861. * Notify external application (if API is enabled) that the display
  862. * configuration of the filmstrip has been changed.
  863. *
  864. * @param {boolean} visible - Whether or not the filmstrip has been set to
  865. * be displayed or hidden.
  866. * @returns {void}
  867. */
  868. notifyFilmstripDisplayChanged(visible: boolean) {
  869. this._sendEvent({
  870. name: 'filmstrip-display-changed',
  871. visible
  872. });
  873. }
  874. /**
  875. * Notify external application of a participant, remote or local, being
  876. * removed from the conference by another participant.
  877. *
  878. * @param {string} kicked - The ID of the participant removed from the
  879. * conference.
  880. * @param {string} kicker - The ID of the participant that removed the
  881. * other participant.
  882. * @returns {void}
  883. */
  884. notifyKickedOut(kicked: Object, kicker: Object) {
  885. this._sendEvent({
  886. name: 'participant-kicked-out',
  887. kicked,
  888. kicker
  889. });
  890. }
  891. /**
  892. * Notify external application of the current meeting requiring a password
  893. * to join.
  894. *
  895. * @returns {void}
  896. */
  897. notifyOnPasswordRequired() {
  898. this._sendEvent({ name: 'password-required' });
  899. }
  900. /**
  901. * Notify external application (if API is enabled) that the screen sharing
  902. * has been turned on/off.
  903. *
  904. * @param {boolean} on - True if screen sharing is enabled.
  905. * @param {Object} details - Additional information about the screen
  906. * sharing.
  907. * @param {string} details.sourceType - Type of device or window the screen
  908. * share is capturing.
  909. * @returns {void}
  910. */
  911. notifyScreenSharingStatusChanged(on: boolean, details: Object) {
  912. this._sendEvent({
  913. name: 'screen-sharing-status-changed',
  914. on,
  915. details
  916. });
  917. }
  918. /**
  919. * Notify external application (if API is enabled) that the dominant speaker
  920. * has been turned on/off.
  921. *
  922. * @param {string} id - Id of the dominant participant.
  923. * @returns {void}
  924. */
  925. notifyDominantSpeakerChanged(id: string) {
  926. this._sendEvent({
  927. name: 'dominant-speaker-changed',
  928. id
  929. });
  930. }
  931. /**
  932. * Notify external application (if API is enabled) that the conference
  933. * changed their subject.
  934. *
  935. * @param {string} subject - Conference subject.
  936. * @returns {void}
  937. */
  938. notifySubjectChanged(subject: string) {
  939. this._sendEvent({
  940. name: 'subject-change',
  941. subject
  942. });
  943. }
  944. /**
  945. * Notify external application (if API is enabled) that tile view has been
  946. * entered or exited.
  947. *
  948. * @param {string} enabled - True if tile view is currently displayed, false
  949. * otherwise.
  950. * @returns {void}
  951. */
  952. notifyTileViewChanged(enabled: boolean) {
  953. this._sendEvent({
  954. name: 'tile-view-changed',
  955. enabled
  956. });
  957. }
  958. /**
  959. * Notify external application (if API is enabled) that the localStorage has changed.
  960. *
  961. * @param {string} localStorageContent - The new localStorageContent.
  962. * @returns {void}
  963. */
  964. notifyLocalStorageChanged(localStorageContent: string) {
  965. this._sendEvent({
  966. name: 'local-storage-changed',
  967. localStorageContent
  968. });
  969. }
  970. /**
  971. * Notify external application (if API is enabled) that user updated their hand raised.
  972. *
  973. * @param {string} id - User id.
  974. * @param {boolean} handRaised - Whether user has raised hand.
  975. * @returns {void}
  976. */
  977. notifyRaiseHandUpdated(id: string, handRaised: boolean) {
  978. this._sendEvent({
  979. name: 'raise-hand-updated',
  980. handRaised,
  981. id
  982. });
  983. }
  984. /**
  985. * Disposes the allocated resources.
  986. *
  987. * @returns {void}
  988. */
  989. dispose() {
  990. if (this._enabled) {
  991. this._enabled = false;
  992. }
  993. }
  994. }
  995. export default new API();