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

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