Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

API.js 66KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048
  1. // @flow
  2. import Logger from '@jitsi/logger';
  3. import { createApiEvent } from '../../react/features/analytics/AnalyticsEvents';
  4. import { sendAnalytics } from '../../react/features/analytics/functions';
  5. import {
  6. approveParticipantAudio,
  7. approveParticipantVideo,
  8. rejectParticipantAudio,
  9. rejectParticipantVideo,
  10. requestDisableAudioModeration,
  11. requestDisableVideoModeration,
  12. requestEnableAudioModeration,
  13. requestEnableVideoModeration
  14. } from '../../react/features/av-moderation/actions';
  15. import { isEnabledFromState } from '../../react/features/av-moderation/functions';
  16. import {
  17. endConference,
  18. sendTones,
  19. setFollowMe,
  20. setLocalSubject,
  21. setPassword,
  22. setSubject
  23. } from '../../react/features/base/conference/actions';
  24. import { getCurrentConference } from '../../react/features/base/conference/functions';
  25. import { overwriteConfig } from '../../react/features/base/config/actions';
  26. import { getWhitelistedJSON } from '../../react/features/base/config/functions.any';
  27. import { toggleDialog } from '../../react/features/base/dialog/actions';
  28. import { isSupportedBrowser } from '../../react/features/base/environment/environment';
  29. import { parseJWTFromURLParams } from '../../react/features/base/jwt/functions';
  30. import JitsiMeetJS, { JitsiRecordingConstants } from '../../react/features/base/lib-jitsi-meet';
  31. import { MEDIA_TYPE, VIDEO_TYPE } from '../../react/features/base/media/constants';
  32. import {
  33. grantModerator,
  34. kickParticipant,
  35. overwriteParticipantsNames,
  36. pinParticipant,
  37. raiseHand
  38. } from '../../react/features/base/participants/actions';
  39. import { LOCAL_PARTICIPANT_DEFAULT_ID } from '../../react/features/base/participants/constants';
  40. import {
  41. getLocalParticipant,
  42. getParticipantById,
  43. getScreenshareParticipantIds,
  44. getVirtualScreenshareParticipantByOwnerId,
  45. hasRaisedHand,
  46. isLocalParticipantModerator,
  47. isParticipantModerator
  48. } from '../../react/features/base/participants/functions';
  49. import { updateSettings } from '../../react/features/base/settings/actions';
  50. import { getDisplayName } from '../../react/features/base/settings/functions.web';
  51. import { toggleCamera } from '../../react/features/base/tracks/actions.any';
  52. import { isToggleCameraEnabled } from '../../react/features/base/tracks/functions';
  53. import {
  54. autoAssignToBreakoutRooms,
  55. closeBreakoutRoom,
  56. createBreakoutRoom,
  57. moveToRoom,
  58. removeBreakoutRoom,
  59. sendParticipantToRoom
  60. } from '../../react/features/breakout-rooms/actions';
  61. import { getBreakoutRooms, getRoomsInfo } from '../../react/features/breakout-rooms/functions';
  62. import {
  63. sendMessage,
  64. setPrivateMessageRecipient,
  65. toggleChat
  66. } from '../../react/features/chat/actions';
  67. import { openChat } from '../../react/features/chat/actions.web';
  68. import {
  69. processExternalDeviceRequest
  70. } from '../../react/features/device-selection/functions';
  71. import { appendSuffix } from '../../react/features/display-name/functions';
  72. import { isEnabled as isDropboxEnabled } from '../../react/features/dropbox/functions';
  73. import { setMediaEncryptionKey, toggleE2EE } from '../../react/features/e2ee/actions';
  74. import {
  75. addStageParticipant,
  76. resizeFilmStrip,
  77. setVolume,
  78. togglePinStageParticipant
  79. } from '../../react/features/filmstrip/actions.web';
  80. import { getPinnedActiveParticipants, isStageFilmstripAvailable } from '../../react/features/filmstrip/functions.web';
  81. import { invite } from '../../react/features/invite/actions.any';
  82. import {
  83. selectParticipantInLargeVideo
  84. } from '../../react/features/large-video/actions.any';
  85. import {
  86. captureLargeVideoScreenshot,
  87. resizeLargeVideo
  88. } from '../../react/features/large-video/actions.web';
  89. import { answerKnockingParticipant, toggleLobbyMode } from '../../react/features/lobby/actions';
  90. import { setNoiseSuppressionEnabled } from '../../react/features/noise-suppression/actions';
  91. import { hideNotification, showNotification } from '../../react/features/notifications/actions';
  92. import { NOTIFICATION_TIMEOUT_TYPE, NOTIFICATION_TYPE } from '../../react/features/notifications/constants';
  93. import {
  94. close as closeParticipantsPane,
  95. open as openParticipantsPane
  96. } from '../../react/features/participants-pane/actions';
  97. import { getParticipantsPaneOpen, isForceMuted } from '../../react/features/participants-pane/functions';
  98. import { startLocalVideoRecording, stopLocalVideoRecording } from '../../react/features/recording/actions.any';
  99. import { RECORDING_TYPES } from '../../react/features/recording/constants';
  100. import { getActiveSession, supportsLocalRecording } from '../../react/features/recording/functions';
  101. import { startAudioScreenShareFlow, startScreenShareFlow } from '../../react/features/screen-share/actions';
  102. import { isScreenAudioSupported } from '../../react/features/screen-share/functions';
  103. import { toggleScreenshotCaptureSummary } from '../../react/features/screenshot-capture/actions';
  104. import { isScreenshotCaptureEnabled } from '../../react/features/screenshot-capture/functions';
  105. import SettingsDialog from '../../react/features/settings/components/web/SettingsDialog';
  106. import { SETTINGS_TABS } from '../../react/features/settings/constants';
  107. import { playSharedVideo, stopSharedVideo } from '../../react/features/shared-video/actions.any';
  108. import { extractYoutubeIdOrURL } from '../../react/features/shared-video/functions';
  109. import { setRequestingSubtitles, toggleRequestingSubtitles } from '../../react/features/subtitles/actions';
  110. import { isAudioMuteButtonDisabled } from '../../react/features/toolbox/functions';
  111. import { setTileView, toggleTileView } from '../../react/features/video-layout/actions.any';
  112. import { muteAllParticipants } from '../../react/features/video-menu/actions';
  113. import { setVideoQuality } from '../../react/features/video-quality/actions';
  114. import { toggleWhiteboard } from '../../react/features/whiteboard/actions.any';
  115. import { WhiteboardStatus } from '../../react/features/whiteboard/types';
  116. import { getJitsiMeetTransport } from '../transport';
  117. import {
  118. API_ID,
  119. ASSUMED_BANDWIDTH_BPS,
  120. ENDPOINT_TEXT_MESSAGE_NAME
  121. } from './constants';
  122. const logger = Logger.getLogger(__filename);
  123. declare var APP: Object;
  124. /**
  125. * List of the available commands.
  126. */
  127. let commands = {};
  128. /**
  129. * The transport instance used for communication with external apps.
  130. *
  131. * @type {Transport}
  132. */
  133. const transport = getJitsiMeetTransport();
  134. /**
  135. * The current audio availability.
  136. *
  137. * @type {boolean}
  138. */
  139. let audioAvailable = true;
  140. /**
  141. * The current video availability.
  142. *
  143. * @type {boolean}
  144. */
  145. let videoAvailable = true;
  146. /**
  147. * Initializes supported commands.
  148. *
  149. * @returns {void}
  150. */
  151. function initCommands() {
  152. commands = {
  153. 'add-breakout-room': name => {
  154. if (!isLocalParticipantModerator(APP.store.getState())) {
  155. logger.error('Missing moderator rights to add breakout rooms');
  156. return;
  157. }
  158. APP.store.dispatch(createBreakoutRoom(name));
  159. },
  160. 'answer-knocking-participant': (id, approved) => {
  161. APP.store.dispatch(answerKnockingParticipant(id, approved));
  162. },
  163. 'approve-video': participantId => {
  164. if (!isLocalParticipantModerator(APP.store.getState())) {
  165. return;
  166. }
  167. APP.store.dispatch(approveParticipantVideo(participantId));
  168. },
  169. 'ask-to-unmute': participantId => {
  170. if (!isLocalParticipantModerator(APP.store.getState())) {
  171. return;
  172. }
  173. APP.store.dispatch(approveParticipantAudio(participantId));
  174. },
  175. 'auto-assign-to-breakout-rooms': () => {
  176. if (!isLocalParticipantModerator(APP.store.getState())) {
  177. logger.error('Missing moderator rights to auto-assign participants to breakout rooms');
  178. return;
  179. }
  180. APP.store.dispatch(autoAssignToBreakoutRooms());
  181. },
  182. 'grant-moderator': participantId => {
  183. if (!isLocalParticipantModerator(APP.store.getState())) {
  184. logger.error('Missing moderator rights to grant moderator right to another participant');
  185. return;
  186. }
  187. APP.store.dispatch(grantModerator(participantId));
  188. },
  189. 'display-name': displayName => {
  190. sendAnalytics(createApiEvent('display.name.changed'));
  191. APP.conference.changeLocalDisplayName(displayName);
  192. },
  193. 'local-subject': localSubject => {
  194. sendAnalytics(createApiEvent('local.subject.changed'));
  195. APP.store.dispatch(setLocalSubject(localSubject));
  196. },
  197. 'mute-everyone': mediaType => {
  198. const muteMediaType = mediaType ? mediaType : MEDIA_TYPE.AUDIO;
  199. sendAnalytics(createApiEvent('muted-everyone'));
  200. const localParticipant = getLocalParticipant(APP.store.getState());
  201. const exclude = [];
  202. if (localParticipant && isParticipantModerator(localParticipant)) {
  203. exclude.push(localParticipant.id);
  204. }
  205. APP.store.dispatch(muteAllParticipants(exclude, muteMediaType));
  206. },
  207. 'toggle-lobby': isLobbyEnabled => {
  208. APP.store.dispatch(toggleLobbyMode(isLobbyEnabled));
  209. },
  210. 'password': password => {
  211. const { conference, passwordRequired }
  212. = APP.store.getState()['features/base/conference'];
  213. if (passwordRequired) {
  214. sendAnalytics(createApiEvent('submit.password'));
  215. APP.store.dispatch(setPassword(
  216. passwordRequired,
  217. passwordRequired.join,
  218. password
  219. ));
  220. } else {
  221. sendAnalytics(createApiEvent('password.changed'));
  222. APP.store.dispatch(setPassword(
  223. conference,
  224. conference.lock,
  225. password
  226. ));
  227. }
  228. },
  229. 'pin-participant': (id, videoType) => {
  230. logger.debug('Pin participant command received');
  231. const state = APP.store.getState();
  232. // if id not provided, unpin everybody.
  233. if (!id) {
  234. if (isStageFilmstripAvailable(state)) {
  235. const pinnedParticipants = getPinnedActiveParticipants(state);
  236. pinnedParticipants?.forEach(p => {
  237. APP.store.dispatch(togglePinStageParticipant(p.participantId));
  238. });
  239. } else {
  240. APP.store.dispatch(pinParticipant());
  241. }
  242. return;
  243. }
  244. const participant = videoType === VIDEO_TYPE.DESKTOP
  245. ? getVirtualScreenshareParticipantByOwnerId(state, id) : getParticipantById(state, id);
  246. if (!participant) {
  247. logger.warn('Trying to pin a non-existing participant with pin-participant command.');
  248. return;
  249. }
  250. sendAnalytics(createApiEvent('participant.pinned'));
  251. const participantId = participant.id;
  252. if (isStageFilmstripAvailable(state)) {
  253. APP.store.dispatch(addStageParticipant(participantId, true));
  254. } else {
  255. APP.store.dispatch(pinParticipant(participantId));
  256. }
  257. },
  258. 'proxy-connection-event': event => {
  259. APP.conference.onProxyConnectionEvent(event);
  260. },
  261. 'reject-participant': (participantId, mediaType) => {
  262. if (!isLocalParticipantModerator(APP.store.getState())) {
  263. return;
  264. }
  265. const reject = mediaType === MEDIA_TYPE.VIDEO ? rejectParticipantVideo : rejectParticipantAudio;
  266. APP.store.dispatch(reject(participantId));
  267. },
  268. 'remove-breakout-room': breakoutRoomJid => {
  269. if (!isLocalParticipantModerator(APP.store.getState())) {
  270. logger.error('Missing moderator rights to remove breakout rooms');
  271. return;
  272. }
  273. APP.store.dispatch(removeBreakoutRoom(breakoutRoomJid));
  274. },
  275. 'resize-large-video': (width, height) => {
  276. logger.debug('Resize large video command received');
  277. sendAnalytics(createApiEvent('largevideo.resized'));
  278. APP.store.dispatch(resizeLargeVideo(width, height));
  279. },
  280. 'send-tones': (options = {}) => {
  281. const { duration, tones, pause } = options;
  282. APP.store.dispatch(sendTones(tones, duration, pause));
  283. },
  284. 'set-assumed-bandwidth-bps': value => {
  285. logger.debug('Set assumed bandwidth bps command received', value);
  286. if (typeof value !== 'number' || isNaN(value)) {
  287. logger.error('Assumed bandwidth bps must be a number.');
  288. return;
  289. }
  290. const { conference } = APP.store.getState()['features/base/conference'];
  291. if (conference) {
  292. conference.setAssumedBandwidthBps(value < ASSUMED_BANDWIDTH_BPS
  293. ? ASSUMED_BANDWIDTH_BPS
  294. : value);
  295. }
  296. },
  297. 'set-follow-me': value => {
  298. logger.debug('Set follow me command received');
  299. if (value) {
  300. sendAnalytics(createApiEvent('follow.me.set'));
  301. } else {
  302. sendAnalytics(createApiEvent('follow.me.unset'));
  303. }
  304. APP.store.dispatch(setFollowMe(value));
  305. },
  306. 'set-large-video-participant': (participantId, videoType) => {
  307. logger.debug('Set large video participant command received');
  308. if (!participantId) {
  309. sendAnalytics(createApiEvent('largevideo.participant.set'));
  310. APP.store.dispatch(selectParticipantInLargeVideo());
  311. return;
  312. }
  313. const state = APP.store.getState();
  314. const participant = videoType === VIDEO_TYPE.DESKTOP
  315. ? getVirtualScreenshareParticipantByOwnerId(state, participantId)
  316. : getParticipantById(state, participantId);
  317. if (!participant) {
  318. logger.warn('Trying to select a non-existing participant with set-large-video-participant command.');
  319. return;
  320. }
  321. sendAnalytics(createApiEvent('largevideo.participant.set'));
  322. APP.store.dispatch(selectParticipantInLargeVideo(participant.id));
  323. },
  324. 'set-participant-volume': (participantId, volume) => {
  325. APP.store.dispatch(setVolume(participantId, volume));
  326. },
  327. 'subject': subject => {
  328. sendAnalytics(createApiEvent('subject.changed'));
  329. APP.store.dispatch(setSubject(subject));
  330. },
  331. 'submit-feedback': feedback => {
  332. sendAnalytics(createApiEvent('submit.feedback'));
  333. APP.conference.submitFeedback(feedback.score, feedback.message);
  334. },
  335. 'toggle-audio': () => {
  336. sendAnalytics(createApiEvent('toggle-audio'));
  337. logger.log('Audio toggle: API command received');
  338. APP.conference.toggleAudioMuted(false /* no UI */);
  339. },
  340. 'toggle-video': () => {
  341. sendAnalytics(createApiEvent('toggle-video'));
  342. logger.log('Video toggle: API command received');
  343. APP.conference.toggleVideoMuted(false /* no UI */, true /* ensure track */);
  344. },
  345. 'toggle-film-strip': () => {
  346. sendAnalytics(createApiEvent('film.strip.toggled'));
  347. APP.UI.toggleFilmstrip();
  348. },
  349. /*
  350. * @param {Object} options - Additional details of how to perform
  351. * the action.
  352. * @param {number} options.width - width value for film strip.
  353. */
  354. 'resize-film-strip': (options = {}) => {
  355. sendAnalytics(createApiEvent('film.strip.resize'));
  356. APP.store.dispatch(resizeFilmStrip(options.width));
  357. },
  358. 'toggle-camera': () => {
  359. if (!isToggleCameraEnabled(APP.store.getState())) {
  360. return;
  361. }
  362. APP.store.dispatch(toggleCamera());
  363. },
  364. 'toggle-camera-mirror': () => {
  365. const state = APP.store.getState();
  366. const { localFlipX: currentFlipX } = state['features/base/settings'];
  367. APP.store.dispatch(updateSettings({ localFlipX: !currentFlipX }));
  368. },
  369. 'toggle-chat': () => {
  370. sendAnalytics(createApiEvent('chat.toggled'));
  371. APP.store.dispatch(toggleChat());
  372. },
  373. 'toggle-moderation': (enabled, mediaType) => {
  374. const state = APP.store.getState();
  375. if (!isLocalParticipantModerator(state)) {
  376. return;
  377. }
  378. const enable = mediaType === MEDIA_TYPE.VIDEO
  379. ? requestEnableVideoModeration : requestEnableAudioModeration;
  380. const disable = mediaType === MEDIA_TYPE.VIDEO
  381. ? requestDisableVideoModeration : requestDisableAudioModeration;
  382. if (enabled) {
  383. APP.store.dispatch(enable());
  384. } else {
  385. APP.store.dispatch(disable());
  386. }
  387. },
  388. 'toggle-participants-pane': enabled => {
  389. const toggleParticipantsPane = enabled
  390. ? openParticipantsPane : closeParticipantsPane;
  391. APP.store.dispatch(toggleParticipantsPane());
  392. },
  393. 'toggle-raise-hand': () => {
  394. const localParticipant = getLocalParticipant(APP.store.getState());
  395. if (!localParticipant) {
  396. return;
  397. }
  398. const raisedHand = hasRaisedHand(localParticipant);
  399. sendAnalytics(createApiEvent('raise-hand.toggled'));
  400. APP.store.dispatch(raiseHand(!raisedHand));
  401. },
  402. 'toggle-share-audio': () => {
  403. sendAnalytics(createApiEvent('audio.screen.sharing.toggled'));
  404. if (isScreenAudioSupported()) {
  405. APP.store.dispatch(startAudioScreenShareFlow());
  406. return;
  407. }
  408. logger.error('Audio screen sharing is not supported by the current platform!');
  409. },
  410. /**
  411. * Callback to invoke when the "toggle-share-screen" command is received.
  412. *
  413. * @param {Object} options - Additional details of how to perform
  414. * the action. Note this parameter is undocumented and experimental.
  415. * @param {boolean} options.enable - Whether trying to enable screen
  416. * sharing or to turn it off.
  417. * @returns {void}
  418. */
  419. 'toggle-share-screen': (options = {}) => {
  420. sendAnalytics(createApiEvent('screen.sharing.toggled'));
  421. toggleScreenSharing(options.enable);
  422. },
  423. 'set-noise-suppression-enabled': (options = {}) => {
  424. APP.store.dispatch(setNoiseSuppressionEnabled(options.enabled));
  425. },
  426. 'toggle-subtitles': () => {
  427. APP.store.dispatch(toggleRequestingSubtitles());
  428. },
  429. 'set-subtitles': enabled => {
  430. APP.store.dispatch(setRequestingSubtitles(enabled));
  431. },
  432. 'toggle-tile-view': () => {
  433. sendAnalytics(createApiEvent('tile-view.toggled'));
  434. APP.store.dispatch(toggleTileView());
  435. },
  436. 'set-tile-view': enabled => {
  437. APP.store.dispatch(setTileView(enabled));
  438. },
  439. 'video-hangup': (showFeedbackDialog = true) => {
  440. sendAnalytics(createApiEvent('video.hangup'));
  441. APP.conference.hangup(showFeedbackDialog);
  442. },
  443. 'email': email => {
  444. sendAnalytics(createApiEvent('email.changed'));
  445. APP.conference.changeLocalEmail(email);
  446. },
  447. 'avatar-url': avatarUrl => {
  448. sendAnalytics(createApiEvent('avatar.url.changed'));
  449. APP.conference.changeLocalAvatarUrl(avatarUrl);
  450. },
  451. 'send-chat-message': (message, to, ignorePrivacy = false) => {
  452. logger.debug('Send chat message command received');
  453. if (to) {
  454. const participant = getParticipantById(APP.store.getState(), to);
  455. if (participant) {
  456. APP.store.dispatch(setPrivateMessageRecipient(participant));
  457. } else {
  458. logger.error(`Participant with id ${to} not found!`);
  459. return;
  460. }
  461. } else {
  462. APP.store.dispatch(setPrivateMessageRecipient());
  463. }
  464. APP.store.dispatch(sendMessage(message, ignorePrivacy));
  465. },
  466. 'send-endpoint-text-message': (to, text) => {
  467. logger.debug('Send endpoint message command received');
  468. try {
  469. APP.conference.sendEndpointMessage(to, {
  470. name: ENDPOINT_TEXT_MESSAGE_NAME,
  471. text
  472. });
  473. } catch (err) {
  474. logger.error('Failed sending endpoint text message', err);
  475. }
  476. },
  477. 'overwrite-names': participantList => {
  478. logger.debug('Overwrite names command received');
  479. APP.store.dispatch(overwriteParticipantsNames(participantList));
  480. },
  481. 'toggle-e2ee': enabled => {
  482. logger.debug('Toggle E2EE key command received');
  483. APP.store.dispatch(toggleE2EE(enabled));
  484. },
  485. 'set-media-encryption-key': keyInfo => {
  486. APP.store.dispatch(setMediaEncryptionKey(JSON.parse(keyInfo)));
  487. },
  488. 'set-video-quality': frameHeight => {
  489. logger.debug('Set video quality command received');
  490. sendAnalytics(createApiEvent('set.video.quality'));
  491. APP.store.dispatch(setVideoQuality(frameHeight));
  492. },
  493. 'start-share-video': url => {
  494. logger.debug('Share video command received');
  495. sendAnalytics(createApiEvent('share.video.start'));
  496. const id = extractYoutubeIdOrURL(url);
  497. if (id) {
  498. APP.store.dispatch(playSharedVideo(id));
  499. }
  500. },
  501. 'stop-share-video': () => {
  502. logger.debug('Share video command received');
  503. sendAnalytics(createApiEvent('share.video.stop'));
  504. APP.store.dispatch(stopSharedVideo());
  505. },
  506. /**
  507. * Shows a custom in-meeting notification.
  508. *
  509. * @param { string } arg.title - Notification title.
  510. * @param { string } arg.description - Notification description.
  511. * @param { string } arg.uid - Optional unique identifier for the notification.
  512. * @param { string } arg.type - Notification type, either `error`, `info`, `normal`, `success` or `warning`.
  513. * Defaults to "normal" if not provided.
  514. * @param { string } arg.timeout - Timeout type, either `short`, `medium`, `long` or `sticky`.
  515. * Defaults to "short" if not provided.
  516. * @returns {void}
  517. */
  518. 'show-notification': ({
  519. title,
  520. description,
  521. uid,
  522. type = NOTIFICATION_TYPE.NORMAL,
  523. timeout = NOTIFICATION_TIMEOUT_TYPE.SHORT
  524. }) => {
  525. const validTypes = Object.values(NOTIFICATION_TYPE);
  526. const validTimeouts = Object.values(NOTIFICATION_TIMEOUT_TYPE);
  527. if (!validTypes.includes(type)) {
  528. logger.error(`Invalid notification type "${type}". Expecting one of ${validTypes}`);
  529. return;
  530. }
  531. if (!validTimeouts.includes(timeout)) {
  532. logger.error(`Invalid notification timeout "${timeout}". Expecting one of ${validTimeouts}`);
  533. return;
  534. }
  535. APP.store.dispatch(showNotification({
  536. uid,
  537. title,
  538. description,
  539. appearance: type
  540. }, timeout));
  541. },
  542. /**
  543. * Removes a notification given a unique identifier.
  544. *
  545. * @param { string } uid - Unique identifier for the notification to be removed.
  546. * @returns {void}
  547. */
  548. 'hide-notification': uid => {
  549. APP.store.dispatch(hideNotification(uid));
  550. },
  551. /**
  552. * Starts a file recording or streaming session depending on the passed on params.
  553. * For RTMP streams, `rtmpStreamKey` must be passed on. `rtmpBroadcastID` is optional.
  554. * For youtube streams, `youtubeStreamKey` must be passed on. `youtubeBroadcastID` is optional.
  555. * For dropbox recording, recording `mode` should be `file` and a dropbox oauth2 token must be provided.
  556. * For file recording, recording `mode` should be `file` and optionally `shouldShare` could be passed on.
  557. * For local recording, recording `mode` should be `local` and optionally `onlySelf` could be passed on.
  558. * No other params should be passed.
  559. *
  560. * @param { string } arg.mode - Recording mode, either `local`, `file` or `stream`.
  561. * @param { string } arg.dropboxToken - Dropbox oauth2 token.
  562. * @param { boolean } arg.onlySelf - Whether to only record the local streams.
  563. * @param { string } arg.rtmpStreamKey - The RTMP stream key.
  564. * @param { string } arg.rtmpBroadcastID - The RTMP broadcast ID.
  565. * @param { boolean } arg.shouldShare - Whether the recording should be shared with the participants or not.
  566. * Only applies to certain jitsi meet deploys.
  567. * @param { string } arg.youtubeStreamKey - The youtube stream key.
  568. * @param { string } arg.youtubeBroadcastID - The youtube broadcast ID.
  569. * @returns {void}
  570. */
  571. 'start-recording': ({
  572. mode,
  573. dropboxToken,
  574. onlySelf,
  575. shouldShare,
  576. rtmpStreamKey,
  577. rtmpBroadcastID,
  578. youtubeStreamKey,
  579. youtubeBroadcastID
  580. }) => {
  581. const state = APP.store.getState();
  582. const conference = getCurrentConference(state);
  583. if (!conference) {
  584. logger.error('Conference is not defined');
  585. return;
  586. }
  587. if (dropboxToken && !isDropboxEnabled(state)) {
  588. logger.error('Failed starting recording: dropbox is not enabled on this deployment');
  589. return;
  590. }
  591. if (mode === JitsiRecordingConstants.mode.STREAM && !(youtubeStreamKey || rtmpStreamKey)) {
  592. logger.error('Failed starting recording: missing youtube or RTMP stream key');
  593. return;
  594. }
  595. if (mode === 'local') {
  596. const { localRecording } = state['features/base/config'];
  597. if (!localRecording?.disable && supportsLocalRecording()) {
  598. APP.store.dispatch(startLocalVideoRecording(onlySelf));
  599. } else {
  600. logger.error('Failed starting recording: local recording is either disabled or not supported');
  601. }
  602. return;
  603. }
  604. let recordingConfig;
  605. if (mode === JitsiRecordingConstants.mode.FILE) {
  606. const { recordingService } = state['features/base/config'];
  607. if (!recordingService.enabled && !dropboxToken) {
  608. logger.error('Failed starting recording: the recording service is not enabled');
  609. return;
  610. }
  611. if (dropboxToken) {
  612. recordingConfig = {
  613. mode: JitsiRecordingConstants.mode.FILE,
  614. appData: JSON.stringify({
  615. 'file_recording_metadata': {
  616. 'upload_credentials': {
  617. 'service_name': RECORDING_TYPES.DROPBOX,
  618. 'token': dropboxToken
  619. }
  620. }
  621. })
  622. };
  623. } else {
  624. recordingConfig = {
  625. mode: JitsiRecordingConstants.mode.FILE,
  626. appData: JSON.stringify({
  627. 'file_recording_metadata': {
  628. 'share': shouldShare
  629. }
  630. })
  631. };
  632. }
  633. } else if (mode === JitsiRecordingConstants.mode.STREAM) {
  634. recordingConfig = {
  635. broadcastId: youtubeBroadcastID || rtmpBroadcastID,
  636. mode: JitsiRecordingConstants.mode.STREAM,
  637. streamId: youtubeStreamKey || rtmpStreamKey
  638. };
  639. } else {
  640. logger.error('Invalid recording mode provided');
  641. return;
  642. }
  643. if (isScreenshotCaptureEnabled(state, true, false)) {
  644. APP.store.dispatch(toggleScreenshotCaptureSummary(true));
  645. }
  646. conference.startRecording(recordingConfig);
  647. },
  648. /**
  649. * Stops a recording or streaming in progress.
  650. *
  651. * @param {string} mode - `local`, `file` or `stream`.
  652. * @returns {void}
  653. */
  654. 'stop-recording': mode => {
  655. const state = APP.store.getState();
  656. const conference = getCurrentConference(state);
  657. if (!conference) {
  658. logger.error('Conference is not defined');
  659. return;
  660. }
  661. if (mode === 'local') {
  662. APP.store.dispatch(stopLocalVideoRecording());
  663. return;
  664. }
  665. if (![ JitsiRecordingConstants.mode.FILE, JitsiRecordingConstants.mode.STREAM ].includes(mode)) {
  666. logger.error('Invalid recording mode provided!');
  667. return;
  668. }
  669. const activeSession = getActiveSession(state, mode);
  670. if (activeSession && activeSession.id) {
  671. APP.store.dispatch(toggleScreenshotCaptureSummary(false));
  672. conference.stopRecording(activeSession.id);
  673. } else {
  674. logger.error('No recording or streaming session found');
  675. }
  676. },
  677. 'initiate-private-chat': participantId => {
  678. const state = APP.store.getState();
  679. const participant = getParticipantById(state, participantId);
  680. if (participant) {
  681. const { isOpen: isChatOpen } = state['features/chat'];
  682. if (!isChatOpen) {
  683. APP.store.dispatch(toggleChat());
  684. }
  685. APP.store.dispatch(openChat(participant));
  686. } else {
  687. logger.error('No participant found for the given participantId');
  688. }
  689. },
  690. 'cancel-private-chat': () => {
  691. APP.store.dispatch(setPrivateMessageRecipient());
  692. },
  693. 'close-breakout-room': roomId => {
  694. if (!isLocalParticipantModerator(APP.store.getState())) {
  695. logger.error('Missing moderator rights to close breakout rooms');
  696. return;
  697. }
  698. APP.store.dispatch(closeBreakoutRoom(roomId));
  699. },
  700. 'join-breakout-room': roomId => {
  701. APP.store.dispatch(moveToRoom(roomId));
  702. },
  703. 'send-participant-to-room': (participantId, roomId) => {
  704. if (!isLocalParticipantModerator(APP.store.getState())) {
  705. logger.error('Missing moderator rights to send participants to rooms');
  706. return;
  707. }
  708. APP.store.dispatch(sendParticipantToRoom(participantId, roomId));
  709. },
  710. 'kick-participant': participantId => {
  711. APP.store.dispatch(kickParticipant(participantId));
  712. },
  713. 'overwrite-config': config => {
  714. const whitelistedConfig = getWhitelistedJSON('config', config);
  715. APP.store.dispatch(overwriteConfig(whitelistedConfig));
  716. },
  717. 'toggle-virtual-background': () => {
  718. APP.store.dispatch(toggleDialog(SettingsDialog, {
  719. defaultTab: SETTINGS_TABS.VIRTUAL_BACKGROUND }));
  720. },
  721. 'end-conference': () => {
  722. APP.store.dispatch(endConference());
  723. const state = APP.store.getState();
  724. const conference = getCurrentConference(state);
  725. if (!conference) {
  726. logger.error('Conference not yet available');
  727. } else if (conference.isEndConferenceSupported()) {
  728. APP.store.dispatch(endConference());
  729. } else {
  730. logger.error(' End Conference not supported');
  731. }
  732. },
  733. 'toggle-whiteboard': () => {
  734. APP.store.dispatch(toggleWhiteboard());
  735. }
  736. };
  737. transport.on('event', ({ data, name }) => {
  738. if (name && commands[name]) {
  739. commands[name](...data);
  740. return true;
  741. }
  742. return false;
  743. });
  744. transport.on('request', (request, callback) => {
  745. const { dispatch, getState } = APP.store;
  746. if (processExternalDeviceRequest(dispatch, getState, request, callback)) {
  747. return true;
  748. }
  749. const { name } = request;
  750. switch (name) {
  751. case 'capture-largevideo-screenshot' :
  752. APP.store.dispatch(captureLargeVideoScreenshot())
  753. .then(dataURL => {
  754. let error;
  755. if (!dataURL) {
  756. error = new Error('No large video found!');
  757. }
  758. callback({
  759. error,
  760. dataURL
  761. });
  762. });
  763. break;
  764. case 'deployment-info':
  765. callback(APP.store.getState()['features/base/config'].deploymentInfo);
  766. break;
  767. case 'invite': {
  768. const { invitees } = request;
  769. if (!Array.isArray(invitees) || invitees.length === 0) {
  770. callback({
  771. error: new Error('Unexpected format of invitees')
  772. });
  773. break;
  774. }
  775. // The store should be already available because API.init is called
  776. // on appWillMount action.
  777. APP.store.dispatch(
  778. invite(invitees, true))
  779. .then(failedInvitees => {
  780. let error;
  781. let result;
  782. if (failedInvitees.length) {
  783. error = new Error('One or more invites failed!');
  784. } else {
  785. result = true;
  786. }
  787. callback({
  788. error,
  789. result
  790. });
  791. });
  792. break;
  793. }
  794. case 'is-audio-muted':
  795. callback(APP.conference.isLocalAudioMuted());
  796. break;
  797. case 'is-audio-disabled':
  798. callback(isAudioMuteButtonDisabled(APP.store.getState()));
  799. break;
  800. case 'is-moderation-on': {
  801. const { mediaType } = request;
  802. const type = mediaType || MEDIA_TYPE.AUDIO;
  803. callback(isEnabledFromState(type, APP.store.getState()));
  804. break;
  805. }
  806. case 'is-participant-force-muted': {
  807. const state = APP.store.getState();
  808. const { participantId, mediaType } = request;
  809. const type = mediaType || MEDIA_TYPE.AUDIO;
  810. const participant = getParticipantById(state, participantId);
  811. callback(isForceMuted(participant, type, state));
  812. break;
  813. }
  814. case 'is-participants-pane-open': {
  815. callback(getParticipantsPaneOpen(APP.store.getState()));
  816. break;
  817. }
  818. case 'is-video-muted':
  819. callback(APP.conference.isLocalVideoMuted());
  820. break;
  821. case 'is-audio-available':
  822. callback(audioAvailable);
  823. break;
  824. case 'is-video-available':
  825. callback(videoAvailable);
  826. break;
  827. case 'is-sharing-screen':
  828. callback(Boolean(APP.conference.isSharingScreen));
  829. break;
  830. case 'is-start-silent':
  831. callback(Boolean(APP.store.getState()['features/base/config'].startSilent));
  832. break;
  833. case 'get-content-sharing-participants': {
  834. const sharingParticipantIds = getScreenshareParticipantIds(APP.store.getState());
  835. callback({
  836. sharingParticipantIds
  837. });
  838. break;
  839. }
  840. case 'get-livestream-url': {
  841. const state = APP.store.getState();
  842. const conference = getCurrentConference(state);
  843. let livestreamUrl;
  844. if (conference) {
  845. const activeSession = getActiveSession(state, JitsiRecordingConstants.mode.STREAM);
  846. livestreamUrl = activeSession?.liveStreamViewURL;
  847. } else {
  848. logger.error('Conference is not defined');
  849. }
  850. callback({
  851. livestreamUrl
  852. });
  853. break;
  854. }
  855. case 'get-custom-avatar-backgrounds' : {
  856. callback({
  857. avatarBackgrounds: APP.store.getState()['features/dynamic-branding'].avatarBackgrounds
  858. });
  859. break;
  860. }
  861. case 'list-breakout-rooms': {
  862. callback(getBreakoutRooms(APP.store.getState()));
  863. break;
  864. }
  865. case 'rooms-info': {
  866. callback(getRoomsInfo(APP.store.getState()));
  867. break;
  868. }
  869. default:
  870. return false;
  871. }
  872. return true;
  873. });
  874. }
  875. /**
  876. * Check whether the API should be enabled or not.
  877. *
  878. * @returns {boolean}
  879. */
  880. function shouldBeEnabled() {
  881. return (
  882. typeof API_ID === 'number'
  883. // XXX Enable the API when a JSON Web Token (JWT) is specified in
  884. // the location/URL because then it is very likely that the Jitsi
  885. // Meet (Web) app is being used by an external/wrapping (Web) app
  886. // and, consequently, the latter will need to communicate with the
  887. // former. (The described logic is merely a heuristic though.)
  888. || parseJWTFromURLParams());
  889. }
  890. /**
  891. * Executes on toggle-share-screen command.
  892. *
  893. * @param {boolean} [enable] - Whether this toggle is to explicitly enable or
  894. * disable screensharing. If not defined, the application will automatically
  895. * attempt to toggle between enabled and disabled. This boolean is useful for
  896. * explicitly setting desired screensharing state.
  897. * @returns {void}
  898. */
  899. function toggleScreenSharing(enable) {
  900. if (JitsiMeetJS.isDesktopSharingEnabled()) {
  901. APP.store.dispatch(startScreenShareFlow(enable));
  902. }
  903. }
  904. /**
  905. * Removes sensitive data from a mouse event.
  906. *
  907. * @param {MouseEvent} event - The mouse event to sanitize.
  908. * @returns {Object}
  909. */
  910. function sanitizeMouseEvent(event: MouseEvent) {
  911. const {
  912. clientX,
  913. clientY,
  914. movementX,
  915. movementY,
  916. offsetX,
  917. offsetY,
  918. pageX,
  919. pageY,
  920. x,
  921. y,
  922. screenX,
  923. screenY
  924. } = event;
  925. return {
  926. clientX,
  927. clientY,
  928. movementX,
  929. movementY,
  930. offsetX,
  931. offsetY,
  932. pageX,
  933. pageY,
  934. x,
  935. y,
  936. screenX,
  937. screenY
  938. };
  939. }
  940. /**
  941. * Implements API class that communicates with external API class and provides
  942. * interface to access Jitsi Meet features by external applications that embed
  943. * Jitsi Meet.
  944. */
  945. class API {
  946. _enabled: boolean;
  947. /**
  948. * Initializes the API. Setups message event listeners that will receive
  949. * information from external applications that embed Jitsi Meet. It also
  950. * sends a message to the external application that API is initialized.
  951. *
  952. * @param {Object} options - Optional parameters.
  953. * @returns {void}
  954. */
  955. init() {
  956. if (!shouldBeEnabled()) {
  957. return;
  958. }
  959. /**
  960. * Current status (enabled/disabled) of API.
  961. *
  962. * @private
  963. * @type {boolean}
  964. */
  965. this._enabled = true;
  966. initCommands();
  967. this.notifyBrowserSupport(isSupportedBrowser());
  968. }
  969. /**
  970. * Notify external application (if API is enabled) that the large video
  971. * visibility changed.
  972. *
  973. * @param {boolean} isHidden - True if the large video is hidden and false
  974. * otherwise.
  975. * @returns {void}
  976. */
  977. notifyLargeVideoVisibilityChanged(isHidden: boolean) {
  978. this._sendEvent({
  979. name: 'large-video-visibility-changed',
  980. isVisible: !isHidden
  981. });
  982. }
  983. /**
  984. * Notifies the external application (spot) that the local jitsi-participant
  985. * has a status update.
  986. *
  987. * @param {Object} event - The message to pass onto spot.
  988. * @returns {void}
  989. */
  990. sendProxyConnectionEvent(event: Object) {
  991. this._sendEvent({
  992. name: 'proxy-connection-event',
  993. ...event
  994. });
  995. }
  996. /**
  997. * Sends event to the external application.
  998. *
  999. * @param {Object} event - The event to be sent.
  1000. * @returns {void}
  1001. */
  1002. _sendEvent(event: Object = {}) {
  1003. if (this._enabled) {
  1004. transport.sendEvent(event);
  1005. }
  1006. }
  1007. /**
  1008. * Notify external application (if API is enabled) that the chat state has been updated.
  1009. *
  1010. * @param {number} unreadCount - The unread messages counter.
  1011. * @param {boolean} isOpen - True if the chat panel is open.
  1012. * @returns {void}
  1013. */
  1014. notifyChatUpdated(unreadCount: number, isOpen: boolean) {
  1015. this._sendEvent({
  1016. name: 'chat-updated',
  1017. unreadCount,
  1018. isOpen
  1019. });
  1020. }
  1021. /**
  1022. * Notify external application (if API is enabled) that message was sent.
  1023. *
  1024. * @param {string} message - Message body.
  1025. * @param {boolean} privateMessage - True if the message was a private message.
  1026. * @returns {void}
  1027. */
  1028. notifySendingChatMessage(message: string, privateMessage: boolean) {
  1029. this._sendEvent({
  1030. name: 'outgoing-message',
  1031. message,
  1032. privateMessage
  1033. });
  1034. }
  1035. /**
  1036. * Notify external application (if API is enabled) that the mouse has entered inside the iframe.
  1037. *
  1038. * @param {MouseEvent} event - The mousemove event.
  1039. * @returns {void}
  1040. */
  1041. notifyMouseEnter(event: MouseEvent) {
  1042. this._sendEvent({
  1043. name: 'mouse-enter',
  1044. event: sanitizeMouseEvent(event)
  1045. });
  1046. }
  1047. /**
  1048. * Notify external application (if API is enabled) that the mouse has entered inside the iframe.
  1049. *
  1050. * @param {MouseEvent} event - The mousemove event.
  1051. * @returns {void}
  1052. */
  1053. notifyMouseLeave(event: MouseEvent) {
  1054. this._sendEvent({
  1055. name: 'mouse-leave',
  1056. event: sanitizeMouseEvent(event)
  1057. });
  1058. }
  1059. /**
  1060. * Notify external application (if API is enabled) that the mouse has moved inside the iframe.
  1061. *
  1062. * @param {MouseEvent} event - The mousemove event.
  1063. * @returns {void}
  1064. */
  1065. notifyMouseMove(event: MouseEvent) {
  1066. this._sendEvent({
  1067. name: 'mouse-move',
  1068. event: sanitizeMouseEvent(event)
  1069. });
  1070. }
  1071. /**
  1072. * Notify the external application that the moderation status has changed.
  1073. *
  1074. * @param {string} mediaType - Media type for which the moderation changed.
  1075. * @param {boolean} enabled - Whether or not the new moderation status is enabled.
  1076. * @returns {void}
  1077. */
  1078. notifyModerationChanged(mediaType: string, enabled: boolean) {
  1079. this._sendEvent({
  1080. name: 'moderation-status-changed',
  1081. mediaType,
  1082. enabled
  1083. });
  1084. }
  1085. /**
  1086. * Notify the external application that a participant was approved on moderation.
  1087. *
  1088. * @param {string} participantId - The ID of the participant that got approved.
  1089. * @param {string} mediaType - Media type for which the participant was approved.
  1090. * @returns {void}
  1091. */
  1092. notifyParticipantApproved(participantId: string, mediaType: string) {
  1093. this._sendEvent({
  1094. name: 'moderation-participant-approved',
  1095. id: participantId,
  1096. mediaType
  1097. });
  1098. }
  1099. /**
  1100. * Notify the external application that a participant was rejected on moderation.
  1101. *
  1102. * @param {string} participantId - The ID of the participant that got rejected.
  1103. * @param {string} mediaType - Media type for which the participant was rejected.
  1104. * @returns {void}
  1105. */
  1106. notifyParticipantRejected(participantId: string, mediaType: string) {
  1107. this._sendEvent({
  1108. name: 'moderation-participant-rejected',
  1109. id: participantId,
  1110. mediaType
  1111. });
  1112. }
  1113. /**
  1114. * Notify the external app that a notification has been triggered.
  1115. *
  1116. * @param {string} title - The notification title.
  1117. * @param {string} description - The notification description.
  1118. *
  1119. * @returns {void}
  1120. */
  1121. notifyNotificationTriggered(title: string, description: string) {
  1122. this._sendEvent({
  1123. description,
  1124. name: 'notification-triggered',
  1125. title
  1126. });
  1127. }
  1128. /**
  1129. * Notify external application that the video quality setting has changed.
  1130. *
  1131. * @param {number} videoQuality - The video quality. The number represents the maximum height of the video streams.
  1132. * @returns {void}
  1133. */
  1134. notifyVideoQualityChanged(videoQuality: number) {
  1135. this._sendEvent({
  1136. name: 'video-quality-changed',
  1137. videoQuality
  1138. });
  1139. }
  1140. /**
  1141. * Notify external application (if API is enabled) that message was
  1142. * received.
  1143. *
  1144. * @param {Object} options - Object with the message properties.
  1145. * @returns {void}
  1146. */
  1147. notifyReceivedChatMessage(
  1148. { body, id, nick, privateMessage, ts }: {
  1149. body: *, id: string, nick: string, privateMessage: boolean, ts: *
  1150. } = {}) {
  1151. if (APP.conference.isLocalId(id)) {
  1152. return;
  1153. }
  1154. this._sendEvent({
  1155. name: 'incoming-message',
  1156. from: id,
  1157. message: body,
  1158. nick,
  1159. privateMessage,
  1160. stamp: ts
  1161. });
  1162. }
  1163. /**
  1164. * Notify external application (if API is enabled) that user joined the
  1165. * conference.
  1166. *
  1167. * @param {string} id - User id.
  1168. * @param {Object} props - The display name of the user.
  1169. * @returns {void}
  1170. */
  1171. notifyUserJoined(id: string, props: Object) {
  1172. this._sendEvent({
  1173. name: 'participant-joined',
  1174. id,
  1175. ...props
  1176. });
  1177. }
  1178. /**
  1179. * Notify external application (if API is enabled) that user left the
  1180. * conference.
  1181. *
  1182. * @param {string} id - User id.
  1183. * @returns {void}
  1184. */
  1185. notifyUserLeft(id: string) {
  1186. this._sendEvent({
  1187. name: 'participant-left',
  1188. id
  1189. });
  1190. }
  1191. /**
  1192. * Notify external application (if API is enabled) that the user role
  1193. * has changed.
  1194. *
  1195. * @param {string} id - User id.
  1196. * @param {string} role - The new user role.
  1197. * @returns {void}
  1198. */
  1199. notifyUserRoleChanged(id: string, role: string) {
  1200. this._sendEvent({
  1201. name: 'participant-role-changed',
  1202. id,
  1203. role
  1204. });
  1205. }
  1206. /**
  1207. * Notify external application (if API is enabled) that user changed their
  1208. * avatar.
  1209. *
  1210. * @param {string} id - User id.
  1211. * @param {string} avatarURL - The new avatar URL of the participant.
  1212. * @returns {void}
  1213. */
  1214. notifyAvatarChanged(id: string, avatarURL: string) {
  1215. this._sendEvent({
  1216. name: 'avatar-changed',
  1217. avatarURL,
  1218. id
  1219. });
  1220. }
  1221. /**
  1222. * Notify external application (if API is enabled) that user received
  1223. * a text message through datachannels.
  1224. *
  1225. * @param {Object} data - The event data.
  1226. * @returns {void}
  1227. */
  1228. notifyEndpointTextMessageReceived(data: Object) {
  1229. this._sendEvent({
  1230. name: 'endpoint-text-message-received',
  1231. data
  1232. });
  1233. }
  1234. /**
  1235. * Notify external application (if API is enabled) that some face landmark data is available.
  1236. *
  1237. * @param {Object | undefined} faceBox - Detected face(s) bounding box (left, right, width).
  1238. * @param {string} faceExpression - Detected face expression.
  1239. * @returns {void}
  1240. */
  1241. notifyFaceLandmarkDetected(faceBox: Object, faceExpression: string) {
  1242. this._sendEvent({
  1243. name: 'face-landmark-detected',
  1244. faceBox,
  1245. faceExpression
  1246. });
  1247. }
  1248. /**
  1249. * Notify external application (if API is enabled) that the list of sharing participants changed.
  1250. *
  1251. * @param {Object} data - The event data.
  1252. * @returns {void}
  1253. */
  1254. notifySharingParticipantsChanged(data: Object) {
  1255. this._sendEvent({
  1256. name: 'content-sharing-participants-changed',
  1257. data
  1258. });
  1259. }
  1260. /**
  1261. * Notify external application (if API is enabled) that the device list has
  1262. * changed.
  1263. *
  1264. * @param {Object} devices - The new device list.
  1265. * @returns {void}
  1266. */
  1267. notifyDeviceListChanged(devices: Object) {
  1268. this._sendEvent({
  1269. name: 'device-list-changed',
  1270. devices
  1271. });
  1272. }
  1273. /**
  1274. * Notify external application (if API is enabled) that user changed their
  1275. * nickname.
  1276. *
  1277. * @param {string} id - User id.
  1278. * @param {string} displayname - User nickname.
  1279. * @param {string} formattedDisplayName - The display name shown in Jitsi
  1280. * meet's UI for the user.
  1281. * @returns {void}
  1282. */
  1283. notifyDisplayNameChanged(
  1284. id: string,
  1285. { displayName, formattedDisplayName }: Object) {
  1286. this._sendEvent({
  1287. name: 'display-name-change',
  1288. displayname: displayName,
  1289. formattedDisplayName,
  1290. id
  1291. });
  1292. }
  1293. /**
  1294. * Notify external application (if API is enabled) that user changed their
  1295. * email.
  1296. *
  1297. * @param {string} id - User id.
  1298. * @param {string} email - The new email of the participant.
  1299. * @returns {void}
  1300. */
  1301. notifyEmailChanged(
  1302. id: string,
  1303. { email }: Object) {
  1304. this._sendEvent({
  1305. name: 'email-change',
  1306. email,
  1307. id
  1308. });
  1309. }
  1310. /**
  1311. * Notify external application (if API is enabled) that the an error has been logged.
  1312. *
  1313. * @param {string} logLevel - The message log level.
  1314. * @param {Array} args - Array of strings composing the log message.
  1315. * @returns {void}
  1316. */
  1317. notifyLog(logLevel: string, args: Array<string>) {
  1318. this._sendEvent({
  1319. name: 'log',
  1320. logLevel,
  1321. args
  1322. });
  1323. }
  1324. /**
  1325. * Notify external application (if API is enabled) that the conference has
  1326. * been joined.
  1327. *
  1328. * @param {string} roomName - The room name.
  1329. * @param {string} id - The id of the local user.
  1330. * @param {Object} props - The display name, the avatar URL of the local
  1331. * user and the type of the room.
  1332. * @returns {void}
  1333. */
  1334. notifyConferenceJoined(roomName: string, id: string, props: Object) {
  1335. this._sendEvent({
  1336. name: 'video-conference-joined',
  1337. roomName,
  1338. id,
  1339. ...props
  1340. });
  1341. }
  1342. /**
  1343. * Notify external application (if API is enabled) that local user has left the conference.
  1344. *
  1345. * @param {string} roomName - User id.
  1346. * @returns {void}
  1347. */
  1348. notifyConferenceLeft(roomName: string) {
  1349. this._sendEvent({
  1350. name: 'video-conference-left',
  1351. roomName
  1352. });
  1353. }
  1354. /**
  1355. * Notify external application that the data channel has been closed.
  1356. *
  1357. * @param {number} code - The close code.
  1358. * @param {string} reason - The close reason.
  1359. *
  1360. * @returns {void}
  1361. */
  1362. notifyDataChannelClosed(code: number, reason: string) {
  1363. this._sendEvent({
  1364. name: 'data-channel-closed',
  1365. code,
  1366. reason
  1367. });
  1368. }
  1369. /**
  1370. * Notify external application that the data channel has been opened.
  1371. *
  1372. * @returns {void}
  1373. */
  1374. notifyDataChannelOpened() {
  1375. this._sendEvent({ name: 'data-channel-opened' });
  1376. }
  1377. /**
  1378. * Notify external application (if API is enabled) that we are ready to be
  1379. * closed.
  1380. *
  1381. * @returns {void}
  1382. */
  1383. notifyReadyToClose() {
  1384. this._sendEvent({ name: 'video-ready-to-close' });
  1385. }
  1386. /**
  1387. * Notify external application (if API is enabled) that a suspend event in host computer.
  1388. *
  1389. * @returns {void}
  1390. */
  1391. notifySuspendDetected() {
  1392. this._sendEvent({ name: 'suspend-detected' });
  1393. }
  1394. /**
  1395. * Notify external application (if API is enabled) for audio muted status
  1396. * changed.
  1397. *
  1398. * @param {boolean} muted - The new muted status.
  1399. * @returns {void}
  1400. */
  1401. notifyAudioMutedStatusChanged(muted: boolean) {
  1402. this._sendEvent({
  1403. name: 'audio-mute-status-changed',
  1404. muted
  1405. });
  1406. }
  1407. /**
  1408. * Notify external application (if API is enabled) for video muted status
  1409. * changed.
  1410. *
  1411. * @param {boolean} muted - The new muted status.
  1412. * @returns {void}
  1413. */
  1414. notifyVideoMutedStatusChanged(muted: boolean) {
  1415. this._sendEvent({
  1416. name: 'video-mute-status-changed',
  1417. muted
  1418. });
  1419. }
  1420. /**
  1421. * Notify external application (if API is enabled) for audio availability
  1422. * changed.
  1423. *
  1424. * @param {boolean} available - True if available and false otherwise.
  1425. * @returns {void}
  1426. */
  1427. notifyAudioAvailabilityChanged(available: boolean) {
  1428. audioAvailable = available;
  1429. this._sendEvent({
  1430. name: 'audio-availability-changed',
  1431. available
  1432. });
  1433. }
  1434. /**
  1435. * Notify external application (if API is enabled) for video available
  1436. * status changed.
  1437. *
  1438. * @param {boolean} available - True if available and false otherwise.
  1439. * @returns {void}
  1440. */
  1441. notifyVideoAvailabilityChanged(available: boolean) {
  1442. videoAvailable = available;
  1443. this._sendEvent({
  1444. name: 'video-availability-changed',
  1445. available
  1446. });
  1447. }
  1448. /**
  1449. * Notify external application (if API is enabled) that the on stage
  1450. * participant has changed.
  1451. *
  1452. * @param {string} id - User id of the new on stage participant.
  1453. * @returns {void}
  1454. */
  1455. notifyOnStageParticipantChanged(id: string) {
  1456. this._sendEvent({
  1457. name: 'on-stage-participant-changed',
  1458. id
  1459. });
  1460. }
  1461. /**
  1462. * Notify external application (if API is enabled) that the prejoin video
  1463. * visibility had changed.
  1464. *
  1465. * @param {boolean} isVisible - Whether the prejoin video is visible.
  1466. * @returns {void}
  1467. */
  1468. notifyPrejoinVideoVisibilityChanged(isVisible: boolean) {
  1469. this._sendEvent({
  1470. name: 'on-prejoin-video-changed',
  1471. isVisible
  1472. });
  1473. }
  1474. /**
  1475. * Notify external application (if API is enabled) that the prejoin
  1476. * screen was loaded.
  1477. *
  1478. * @returns {void}
  1479. */
  1480. notifyPrejoinLoaded() {
  1481. const state = APP.store.getState();
  1482. const { defaultLocalDisplayName } = state['features/base/config'];
  1483. const displayName = getDisplayName(state);
  1484. this._sendEvent({
  1485. name: 'prejoin-screen-loaded',
  1486. id: LOCAL_PARTICIPANT_DEFAULT_ID,
  1487. displayName,
  1488. formattedDisplayName: appendSuffix(displayName, defaultLocalDisplayName)
  1489. });
  1490. }
  1491. /**
  1492. * Notify external application of an unexpected camera-related error having
  1493. * occurred.
  1494. *
  1495. * @param {string} type - The type of the camera error.
  1496. * @param {string} message - Additional information about the error.
  1497. * @returns {void}
  1498. */
  1499. notifyOnCameraError(type: string, message: string) {
  1500. this._sendEvent({
  1501. name: 'camera-error',
  1502. type,
  1503. message
  1504. });
  1505. }
  1506. /**
  1507. * Notify external application of an unexpected mic-related error having
  1508. * occurred.
  1509. *
  1510. * @param {string} type - The type of the mic error.
  1511. * @param {string} message - Additional information about the error.
  1512. * @returns {void}
  1513. */
  1514. notifyOnMicError(type: string, message: string) {
  1515. this._sendEvent({
  1516. name: 'mic-error',
  1517. type,
  1518. message
  1519. });
  1520. }
  1521. /**
  1522. * Notify external application (if API is enabled) that conference feedback
  1523. * has been submitted. Intended to be used in conjunction with the
  1524. * submit-feedback command to get notified if feedback was submitted.
  1525. *
  1526. * @param {string} error - A failure message, if any.
  1527. * @returns {void}
  1528. */
  1529. notifyFeedbackSubmitted(error: string) {
  1530. this._sendEvent({
  1531. name: 'feedback-submitted',
  1532. error
  1533. });
  1534. }
  1535. /**
  1536. * Notify external application (if API is enabled) that the feedback prompt
  1537. * has been displayed.
  1538. *
  1539. * @returns {void}
  1540. */
  1541. notifyFeedbackPromptDisplayed() {
  1542. this._sendEvent({ name: 'feedback-prompt-displayed' });
  1543. }
  1544. /**
  1545. * Notify external application (if API is enabled) that the display
  1546. * configuration of the filmstrip has been changed.
  1547. *
  1548. * @param {boolean} visible - Whether or not the filmstrip has been set to
  1549. * be displayed or hidden.
  1550. * @returns {void}
  1551. */
  1552. notifyFilmstripDisplayChanged(visible: boolean) {
  1553. this._sendEvent({
  1554. name: 'filmstrip-display-changed',
  1555. visible
  1556. });
  1557. }
  1558. /**
  1559. * Notify external application of a participant, remote or local, being
  1560. * removed from the conference by another participant.
  1561. *
  1562. * @param {string} kicked - The ID of the participant removed from the
  1563. * conference.
  1564. * @param {string} kicker - The ID of the participant that removed the
  1565. * other participant.
  1566. * @returns {void}
  1567. */
  1568. notifyKickedOut(kicked: Object, kicker: Object) {
  1569. this._sendEvent({
  1570. name: 'participant-kicked-out',
  1571. kicked,
  1572. kicker
  1573. });
  1574. }
  1575. /**
  1576. * Notify external application of the current meeting requiring a password
  1577. * to join.
  1578. *
  1579. * @returns {void}
  1580. */
  1581. notifyOnPasswordRequired() {
  1582. this._sendEvent({ name: 'password-required' });
  1583. }
  1584. /**
  1585. * Notify external application (if API is enabled) that the screen sharing
  1586. * has been turned on/off.
  1587. *
  1588. * @param {boolean} on - True if screen sharing is enabled.
  1589. * @param {Object} details - Additional information about the screen
  1590. * sharing.
  1591. * @param {string} details.sourceType - Type of device or window the screen
  1592. * share is capturing.
  1593. * @returns {void}
  1594. */
  1595. notifyScreenSharingStatusChanged(on: boolean, details: Object) {
  1596. this._sendEvent({
  1597. name: 'screen-sharing-status-changed',
  1598. on,
  1599. details
  1600. });
  1601. }
  1602. /**
  1603. * Notify external application (if API is enabled) that the dominant speaker
  1604. * has been turned on/off.
  1605. *
  1606. * @param {string} id - Id of the dominant participant.
  1607. * @returns {void}
  1608. */
  1609. notifyDominantSpeakerChanged(id: string) {
  1610. this._sendEvent({
  1611. name: 'dominant-speaker-changed',
  1612. id
  1613. });
  1614. }
  1615. /**
  1616. * Notify external application (if API is enabled) that the conference
  1617. * changed their subject.
  1618. *
  1619. * @param {string} subject - Conference subject.
  1620. * @returns {void}
  1621. */
  1622. notifySubjectChanged(subject: string) {
  1623. this._sendEvent({
  1624. name: 'subject-change',
  1625. subject
  1626. });
  1627. }
  1628. /**
  1629. * Notify external application (if API is enabled) that tile view has been
  1630. * entered or exited.
  1631. *
  1632. * @param {string} enabled - True if tile view is currently displayed, false
  1633. * otherwise.
  1634. * @returns {void}
  1635. */
  1636. notifyTileViewChanged(enabled: boolean) {
  1637. this._sendEvent({
  1638. name: 'tile-view-changed',
  1639. enabled
  1640. });
  1641. }
  1642. /**
  1643. * Notify external application (if API is enabled) that the localStorage has changed.
  1644. *
  1645. * @param {string} localStorageContent - The new localStorageContent.
  1646. * @returns {void}
  1647. */
  1648. notifyLocalStorageChanged(localStorageContent: string) {
  1649. this._sendEvent({
  1650. name: 'local-storage-changed',
  1651. localStorageContent
  1652. });
  1653. }
  1654. /**
  1655. * Notify external application (if API is enabled) that user updated their hand raised.
  1656. *
  1657. * @param {string} id - User id.
  1658. * @param {boolean} handRaised - Whether user has raised hand.
  1659. * @returns {void}
  1660. */
  1661. notifyRaiseHandUpdated(id: string, handRaised: boolean) {
  1662. this._sendEvent({
  1663. name: 'raise-hand-updated',
  1664. handRaised,
  1665. id
  1666. });
  1667. }
  1668. /**
  1669. * Notify external application (if API is enabled) that recording has started or stopped.
  1670. *
  1671. * @param {boolean} on - True if recording is on, false otherwise.
  1672. * @param {string} mode - Stream or file or local.
  1673. * @param {string} error - Error type or null if success.
  1674. * @returns {void}
  1675. */
  1676. notifyRecordingStatusChanged(on: boolean, mode: string, error?: string) {
  1677. this._sendEvent({
  1678. name: 'recording-status-changed',
  1679. on,
  1680. mode,
  1681. error
  1682. });
  1683. }
  1684. /**
  1685. * Notify external application (if API is enabled) that the current recording link is
  1686. * available.
  1687. *
  1688. * @param {string} link - The recording download link.
  1689. * @param {number} ttl - The recording download link time to live.
  1690. * @returns {void}
  1691. */
  1692. notifyRecordingLinkAvailable(link: string, ttl: number) {
  1693. this._sendEvent({
  1694. name: 'recording-link-available',
  1695. link,
  1696. ttl
  1697. });
  1698. }
  1699. /**
  1700. * Notify external application (if API is enabled) that a participant is knocking in the lobby.
  1701. *
  1702. * @param {Object} participant - Participant data such as id and name.
  1703. * @returns {void}
  1704. */
  1705. notifyKnockingParticipant(participant: Object) {
  1706. this._sendEvent({
  1707. name: 'knocking-participant',
  1708. participant
  1709. });
  1710. }
  1711. /**
  1712. * Notify external application (if API is enabled) that an error occurred.
  1713. *
  1714. * @param {Object} error - The error.
  1715. * @returns {void}
  1716. */
  1717. notifyError(error: Object) {
  1718. this._sendEvent({
  1719. name: 'error-occurred',
  1720. error
  1721. });
  1722. }
  1723. /**
  1724. * Notify external application ( if API is enabled) that a toolbar button was clicked.
  1725. *
  1726. * @param {string} key - The key of the toolbar button.
  1727. * @param {boolean} preventExecution - Whether execution of the button click was prevented or not.
  1728. * @returns {void}
  1729. */
  1730. notifyToolbarButtonClicked(key: string, preventExecution: boolean) {
  1731. this._sendEvent({
  1732. name: 'toolbar-button-clicked',
  1733. key,
  1734. preventExecution
  1735. });
  1736. }
  1737. /**
  1738. * Notify external application (if API is enabled) whether the used browser is supported or not.
  1739. *
  1740. * @param {boolean} supported - If browser is supported or not.
  1741. * @returns {void}
  1742. */
  1743. notifyBrowserSupport(supported: boolean) {
  1744. this._sendEvent({
  1745. name: 'browser-support',
  1746. supported
  1747. });
  1748. }
  1749. /**
  1750. * Notify external application that the breakout rooms changed.
  1751. *
  1752. * @param {Array} rooms - Array containing the breakout rooms and main room.
  1753. * @returns {void}
  1754. */
  1755. notifyBreakoutRoomsUpdated(rooms) {
  1756. this._sendEvent({
  1757. name: 'breakout-rooms-updated',
  1758. rooms
  1759. });
  1760. }
  1761. /**
  1762. * Notify the external application that the state of the participants pane changed.
  1763. *
  1764. * @param {boolean} open - Whether the panel is open or not.
  1765. * @returns {void}
  1766. */
  1767. notifyParticipantsPaneToggled(open) {
  1768. this._sendEvent({
  1769. name: 'participants-pane-toggled',
  1770. open
  1771. });
  1772. }
  1773. /**
  1774. * Notify the external application that the audio or video is being shared by a participant.
  1775. *
  1776. * @param {string} mediaType - Whether the content which is being shared is audio or video.
  1777. * @param {string} value - Whether the sharing is playing, pause or stop (on audio there is only playing and stop).
  1778. * @param {string} participantId - Participant id of the participant which started or ended
  1779. * the video or audio sharing.
  1780. * @returns {void}
  1781. */
  1782. notifyAudioOrVideoSharingToggled(mediaType, value, participantId) {
  1783. this._sendEvent({
  1784. name: 'audio-or-video-sharing-toggled',
  1785. mediaType,
  1786. value,
  1787. participantId
  1788. });
  1789. }
  1790. /**
  1791. * Notify the external application that a PeerConnection lost connectivity. This event is fired only if
  1792. * a PC `failed` but connectivity to the rtcstats server is still maintained signaling that there is a
  1793. * problem establishing a link between the app and the JVB server or the remote peer in case of P2P.
  1794. * Will only fire if rtcstats is enabled.
  1795. *
  1796. * @param {boolean} isP2P - Type of PC.
  1797. * @param {boolean} wasConnected - Was this connection previously connected. If it was it could mean
  1798. * that connectivity was disrupted, if not it most likely means that the app could not reach
  1799. * the JVB server, or the other peer in case of P2P.
  1800. *
  1801. * @returns {void}
  1802. */
  1803. notifyPeerConnectionFailure(isP2P, wasConnected) {
  1804. this._sendEvent({
  1805. name: 'peer-connection-failure',
  1806. isP2P,
  1807. wasConnected
  1808. });
  1809. }
  1810. /**
  1811. * Notify external application ( if API is enabled) that a participant menu button was clicked.
  1812. *
  1813. * @param {string} key - The key of the participant menu button.
  1814. * @param {string} participantId - The ID of the participant for with the participant menu button was clicked.
  1815. * @returns {void}
  1816. */
  1817. notifyParticipantMenuButtonClicked(key, participantId) {
  1818. this._sendEvent({
  1819. name: 'participant-menu-button-clicked',
  1820. key,
  1821. participantId
  1822. });
  1823. }
  1824. /**
  1825. * Notify external application (if API is enabled) if whiteboard state is
  1826. * changed.
  1827. *
  1828. * @param {WhiteboardStatus} status - The new whiteboard status.
  1829. * @returns {void}
  1830. */
  1831. notifyWhiteboardStatusChanged(status: WhiteboardStatus) {
  1832. this._sendEvent({
  1833. name: 'whiteboard-status-changed',
  1834. status
  1835. });
  1836. }
  1837. /**
  1838. * Disposes the allocated resources.
  1839. *
  1840. * @returns {void}
  1841. */
  1842. dispose() {
  1843. if (this._enabled) {
  1844. this._enabled = false;
  1845. }
  1846. }
  1847. }
  1848. export default new API();