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

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