Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

API.js 65KB

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