Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

actions.any.ts 34KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144
  1. import { createStartMutedConfigurationEvent } from '../../analytics/AnalyticsEvents';
  2. import { sendAnalytics } from '../../analytics/functions';
  3. import { IReduxState, IStore } from '../../app/types';
  4. import { transcriberJoined, transcriberLeft } from '../../transcribing/actions';
  5. import { setIAmVisitor } from '../../visitors/actions';
  6. import { iAmVisitor } from '../../visitors/functions';
  7. import { overwriteConfig } from '../config/actions';
  8. import { getReplaceParticipant } from '../config/functions';
  9. import { connect, disconnect, hangup } from '../connection/actions';
  10. import { JITSI_CONNECTION_CONFERENCE_KEY } from '../connection/constants';
  11. import { hasAvailableDevices } from '../devices/functions.any';
  12. import JitsiMeetJS, { JitsiConferenceEvents, JitsiE2ePingEvents } from '../lib-jitsi-meet';
  13. import {
  14. setAudioMuted,
  15. setAudioUnmutePermissions,
  16. setVideoMuted,
  17. setVideoUnmutePermissions
  18. } from '../media/actions';
  19. import { MEDIA_TYPE, MediaType } from '../media/constants';
  20. import {
  21. dominantSpeakerChanged,
  22. participantKicked,
  23. participantMutedUs,
  24. participantPresenceChanged,
  25. participantRoleChanged,
  26. participantSourcesUpdated,
  27. participantUpdated
  28. } from '../participants/actions';
  29. import { getNormalizedDisplayName, getParticipantByIdOrUndefined } from '../participants/functions';
  30. import { IJitsiParticipant } from '../participants/types';
  31. import { toState } from '../redux/functions';
  32. import {
  33. destroyLocalTracks,
  34. replaceLocalTrack,
  35. trackAdded,
  36. trackRemoved
  37. } from '../tracks/actions.any';
  38. import { getLocalTracks } from '../tracks/functions';
  39. import { getBackendSafeRoomName } from '../util/uri';
  40. import {
  41. AUTH_STATUS_CHANGED,
  42. CONFERENCE_FAILED,
  43. CONFERENCE_JOINED,
  44. CONFERENCE_JOIN_IN_PROGRESS,
  45. CONFERENCE_LEFT,
  46. CONFERENCE_LOCAL_SUBJECT_CHANGED,
  47. CONFERENCE_SUBJECT_CHANGED,
  48. CONFERENCE_TIMESTAMP_CHANGED,
  49. CONFERENCE_UNIQUE_ID_SET,
  50. CONFERENCE_WILL_INIT,
  51. CONFERENCE_WILL_JOIN,
  52. CONFERENCE_WILL_LEAVE,
  53. DATA_CHANNEL_CLOSED,
  54. DATA_CHANNEL_OPENED,
  55. E2E_RTT_CHANGED,
  56. ENDPOINT_MESSAGE_RECEIVED,
  57. KICKED_OUT,
  58. LOCK_STATE_CHANGED,
  59. NON_PARTICIPANT_MESSAGE_RECEIVED,
  60. P2P_STATUS_CHANGED,
  61. SEND_TONES,
  62. SET_ASSUMED_BANDWIDTH_BPS,
  63. SET_FOLLOW_ME,
  64. SET_FOLLOW_ME_RECORDER,
  65. SET_OBFUSCATED_ROOM,
  66. SET_PASSWORD,
  67. SET_PASSWORD_FAILED,
  68. SET_PENDING_SUBJECT_CHANGE,
  69. SET_ROOM,
  70. SET_START_MUTED_POLICY,
  71. SET_START_REACTIONS_MUTED,
  72. UPDATE_CONFERENCE_METADATA
  73. } from './actionTypes';
  74. import { setupVisitorStartupMedia } from './actions';
  75. import {
  76. AVATAR_URL_COMMAND,
  77. EMAIL_COMMAND,
  78. JITSI_CONFERENCE_URL_KEY
  79. } from './constants';
  80. import {
  81. _addLocalTracksToConference,
  82. commonUserJoinedHandling,
  83. commonUserLeftHandling,
  84. getConferenceOptions,
  85. getConferenceState,
  86. getCurrentConference,
  87. getVisitorOptions,
  88. sendLocalParticipant
  89. } from './functions';
  90. import logger from './logger';
  91. import { IConferenceMetadata, IJitsiConference } from './reducer';
  92. /**
  93. * Adds conference (event) listeners.
  94. *
  95. * @param {JitsiConference} conference - The JitsiConference instance.
  96. * @param {Dispatch} dispatch - The Redux dispatch function.
  97. * @param {Object} state - The Redux state.
  98. * @private
  99. * @returns {void}
  100. */
  101. function _addConferenceListeners(conference: IJitsiConference, dispatch: IStore['dispatch'], state: IReduxState) {
  102. // A simple logger for conference errors received through
  103. // the listener. These errors are not handled now, but logged.
  104. conference.on(JitsiConferenceEvents.CONFERENCE_ERROR,
  105. (error: Error) => logger.error('Conference error.', error));
  106. // Dispatches into features/base/conference follow:
  107. // we want to ignore this event in case of tokenAuthUrl config
  108. // we are deprecating this and at some point will get rid of it
  109. if (!state['features/base/config'].tokenAuthUrl) {
  110. conference.on(
  111. JitsiConferenceEvents.AUTH_STATUS_CHANGED,
  112. (authEnabled: boolean, authLogin: string) => dispatch(authStatusChanged(authEnabled, authLogin)));
  113. }
  114. conference.on(
  115. JitsiConferenceEvents.CONFERENCE_FAILED,
  116. (err: string, ...args: any[]) => dispatch(conferenceFailed(conference, err, ...args)));
  117. conference.on(
  118. JitsiConferenceEvents.CONFERENCE_JOINED,
  119. (..._args: any[]) => dispatch(conferenceJoined(conference)));
  120. conference.on(
  121. JitsiConferenceEvents.CONFERENCE_UNIQUE_ID_SET,
  122. (..._args: any[]) => dispatch(conferenceUniqueIdSet(conference)));
  123. conference.on(
  124. JitsiConferenceEvents.CONFERENCE_JOIN_IN_PROGRESS,
  125. (..._args: any[]) => dispatch(conferenceJoinInProgress(conference)));
  126. conference.on(
  127. JitsiConferenceEvents.CONFERENCE_LEFT,
  128. (..._args: any[]) => {
  129. dispatch(conferenceTimestampChanged(0));
  130. dispatch(conferenceLeft(conference));
  131. });
  132. conference.on(JitsiConferenceEvents.SUBJECT_CHANGED,
  133. (subject: string) => dispatch(conferenceSubjectChanged(subject)));
  134. conference.on(JitsiConferenceEvents.CONFERENCE_CREATED_TIMESTAMP,
  135. (timestamp: number) => dispatch(conferenceTimestampChanged(timestamp)));
  136. conference.on(
  137. JitsiConferenceEvents.KICKED,
  138. (participant: any) => dispatch(kickedOut(conference, participant)));
  139. conference.on(
  140. JitsiConferenceEvents.PARTICIPANT_KICKED,
  141. (kicker: any, kicked: any) => dispatch(participantKicked(kicker, kicked)));
  142. conference.on(
  143. JitsiConferenceEvents.PARTICIPANT_SOURCE_UPDATED,
  144. (jitsiParticipant: IJitsiParticipant) => dispatch(participantSourcesUpdated(jitsiParticipant)));
  145. conference.on(
  146. JitsiConferenceEvents.LOCK_STATE_CHANGED,
  147. (locked: boolean) => dispatch(lockStateChanged(conference, locked)));
  148. // Dispatches into features/base/media follow:
  149. conference.on(
  150. JitsiConferenceEvents.STARTED_MUTED,
  151. () => {
  152. const audioMuted = Boolean(conference.isStartAudioMuted());
  153. const videoMuted = Boolean(conference.isStartVideoMuted());
  154. const localTracks = getLocalTracks(state['features/base/tracks']);
  155. sendAnalytics(createStartMutedConfigurationEvent('remote', audioMuted, videoMuted));
  156. logger.log(`Start muted: ${audioMuted ? 'audio, ' : ''}${videoMuted ? 'video' : ''}`);
  157. // XXX Jicofo tells lib-jitsi-meet to start with audio and/or video
  158. // muted i.e. Jicofo expresses an intent. Lib-jitsi-meet has turned
  159. // Jicofo's intent into reality by actually muting the respective
  160. // tracks. The reality is expressed in base/tracks already so what
  161. // is left is to express Jicofo's intent in base/media.
  162. // TODO Maybe the app needs to learn about Jicofo's intent and
  163. // transfer that intent to lib-jitsi-meet instead of lib-jitsi-meet
  164. // acting on Jicofo's intent without the app's knowledge.
  165. dispatch(setAudioMuted(audioMuted));
  166. dispatch(setVideoMuted(videoMuted));
  167. // Remove the tracks from peerconnection as well.
  168. for (const track of localTracks) {
  169. const trackType = track.jitsiTrack.getType();
  170. // Do not remove the audio track on RN. Starting with iOS 15 it will fail to unmute otherwise.
  171. if ((audioMuted && trackType === MEDIA_TYPE.AUDIO && navigator.product !== 'ReactNative')
  172. || (videoMuted && trackType === MEDIA_TYPE.VIDEO)) {
  173. dispatch(replaceLocalTrack(track.jitsiTrack, null, conference));
  174. }
  175. }
  176. });
  177. conference.on(
  178. JitsiConferenceEvents.AUDIO_UNMUTE_PERMISSIONS_CHANGED,
  179. (disableAudioMuteChange: boolean) => {
  180. dispatch(setAudioUnmutePermissions(disableAudioMuteChange));
  181. });
  182. conference.on(
  183. JitsiConferenceEvents.VIDEO_UNMUTE_PERMISSIONS_CHANGED,
  184. (disableVideoMuteChange: boolean) => {
  185. dispatch(setVideoUnmutePermissions(disableVideoMuteChange));
  186. });
  187. // Dispatches into features/base/tracks follow:
  188. conference.on(
  189. JitsiConferenceEvents.TRACK_ADDED,
  190. (t: any) => t && !t.isLocal() && dispatch(trackAdded(t)));
  191. conference.on(
  192. JitsiConferenceEvents.TRACK_REMOVED,
  193. (t: any) => t && !t.isLocal() && dispatch(trackRemoved(t)));
  194. conference.on(
  195. JitsiConferenceEvents.TRACK_MUTE_CHANGED,
  196. (track: any, participantThatMutedUs: any) => {
  197. if (participantThatMutedUs) {
  198. dispatch(participantMutedUs(participantThatMutedUs, track));
  199. }
  200. });
  201. conference.on(JitsiConferenceEvents.TRACK_UNMUTE_REJECTED, (track: any) => dispatch(destroyLocalTracks(track)));
  202. // Dispatches into features/base/participants follow:
  203. conference.on(
  204. JitsiConferenceEvents.DISPLAY_NAME_CHANGED,
  205. (id: string, displayName: string) => dispatch(participantUpdated({
  206. conference,
  207. id,
  208. name: getNormalizedDisplayName(displayName)
  209. })));
  210. conference.on(
  211. JitsiConferenceEvents.SILENT_STATUS_CHANGED,
  212. (id: string, isSilent: boolean) => dispatch(participantUpdated({
  213. conference,
  214. id,
  215. isSilent
  216. })));
  217. conference.on(
  218. JitsiConferenceEvents.DOMINANT_SPEAKER_CHANGED,
  219. (dominant: string, previous: string[], silence: boolean | string) => {
  220. dispatch(dominantSpeakerChanged(dominant, previous, Boolean(silence), conference));
  221. });
  222. conference.on(
  223. JitsiConferenceEvents.ENDPOINT_MESSAGE_RECEIVED,
  224. (participant: Object, json: Object) => dispatch(endpointMessageReceived(participant, json)));
  225. conference.on(
  226. JitsiConferenceEvents.NON_PARTICIPANT_MESSAGE_RECEIVED,
  227. (id: string, json: Object) => dispatch(nonParticipantMessageReceived(id, json)));
  228. conference.on(
  229. JitsiConferenceEvents.USER_JOINED,
  230. (_id: string, user: any) => commonUserJoinedHandling({ dispatch }, conference, user));
  231. conference.on(
  232. JitsiConferenceEvents.USER_LEFT,
  233. (_id: string, user: any) => commonUserLeftHandling({ dispatch }, conference, user));
  234. conference.on(
  235. JitsiConferenceEvents.USER_ROLE_CHANGED,
  236. (id: string, role: string) => dispatch(participantRoleChanged(id, role)));
  237. conference.on(
  238. JitsiConferenceEvents.USER_STATUS_CHANGED,
  239. (id: string, presence: string) => dispatch(participantPresenceChanged(id, presence)));
  240. conference.on(
  241. JitsiE2ePingEvents.E2E_RTT_CHANGED,
  242. (participant: Object, rtt: number) => dispatch(e2eRttChanged(participant, rtt)));
  243. conference.on(
  244. JitsiConferenceEvents.BOT_TYPE_CHANGED,
  245. (id: string, botType: string) => dispatch(participantUpdated({
  246. conference,
  247. id,
  248. botType
  249. })));
  250. conference.on(
  251. JitsiConferenceEvents.TRANSCRIPTION_STATUS_CHANGED,
  252. (status: string, id: string, abruptly: boolean) => {
  253. if (status === JitsiMeetJS.constants.transcriptionStatus.ON) {
  254. dispatch(transcriberJoined(id));
  255. } else if (status === JitsiMeetJS.constants.transcriptionStatus.OFF) {
  256. dispatch(transcriberLeft(id, abruptly));
  257. }
  258. });
  259. conference.addCommandListener(
  260. AVATAR_URL_COMMAND,
  261. (data: { value: string; }, id: string) => {
  262. const participant = getParticipantByIdOrUndefined(state, id);
  263. // if already set from presence(jwt), skip the command processing
  264. if (!participant?.avatarURL) {
  265. return dispatch(participantUpdated({
  266. conference,
  267. id,
  268. avatarURL: data.value
  269. }));
  270. }
  271. });
  272. conference.addCommandListener(
  273. EMAIL_COMMAND,
  274. (data: { value: string; }, id: string) => dispatch(participantUpdated({
  275. conference,
  276. id,
  277. email: data.value
  278. })));
  279. }
  280. /**
  281. * Action for updating the conference metadata.
  282. *
  283. * @param {IConferenceMetadata} metadata - The metadata object.
  284. * @returns {{
  285. * type: UPDATE_CONFERENCE_METADATA,
  286. * metadata: IConferenceMetadata
  287. * }}
  288. */
  289. export function updateConferenceMetadata(metadata: IConferenceMetadata | null) {
  290. return {
  291. type: UPDATE_CONFERENCE_METADATA,
  292. metadata
  293. };
  294. }
  295. /**
  296. * Create an action for when the end-to-end RTT against a specific remote participant has changed.
  297. *
  298. * @param {Object} participant - The participant against which the rtt is measured.
  299. * @param {number} rtt - The rtt.
  300. * @returns {{
  301. * type: E2E_RTT_CHANGED,
  302. * e2eRtt: {
  303. * participant: Object,
  304. * rtt: number
  305. * }
  306. * }}
  307. */
  308. export function e2eRttChanged(participant: Object, rtt: number) {
  309. return {
  310. type: E2E_RTT_CHANGED,
  311. e2eRtt: {
  312. rtt,
  313. participant
  314. }
  315. };
  316. }
  317. /**
  318. * Updates the current known state of server-side authentication.
  319. *
  320. * @param {boolean} authEnabled - Whether or not server authentication is
  321. * enabled.
  322. * @param {string} authLogin - The current name of the logged in user, if any.
  323. * @returns {{
  324. * type: AUTH_STATUS_CHANGED,
  325. * authEnabled: boolean,
  326. * authLogin: string
  327. * }}
  328. */
  329. export function authStatusChanged(authEnabled: boolean, authLogin: string) {
  330. return {
  331. type: AUTH_STATUS_CHANGED,
  332. authEnabled,
  333. authLogin
  334. };
  335. }
  336. /**
  337. * Signals that a specific conference has failed.
  338. *
  339. * @param {JitsiConference} conference - The JitsiConference that has failed.
  340. * @param {string} error - The error describing/detailing the cause of the
  341. * failure.
  342. * @param {any} params - Rest of the params that we receive together with the event.
  343. * @returns {{
  344. * type: CONFERENCE_FAILED,
  345. * conference: JitsiConference,
  346. * error: Error
  347. * }}
  348. * @public
  349. */
  350. export function conferenceFailed(conference: IJitsiConference, error: string, ...params: any) {
  351. return {
  352. type: CONFERENCE_FAILED,
  353. conference,
  354. // Make the error resemble an Error instance (to the extent that
  355. // jitsi-meet needs it).
  356. error: {
  357. name: error,
  358. params,
  359. recoverable: undefined
  360. }
  361. };
  362. }
  363. /**
  364. * Signals that a specific conference has been joined.
  365. *
  366. * @param {JitsiConference} conference - The JitsiConference instance which was
  367. * joined by the local participant.
  368. * @returns {{
  369. * type: CONFERENCE_JOINED,
  370. * conference: JitsiConference
  371. * }}
  372. */
  373. export function conferenceJoined(conference: IJitsiConference) {
  374. return {
  375. type: CONFERENCE_JOINED,
  376. conference
  377. };
  378. }
  379. /**
  380. * Signals that a specific conference join is in progress.
  381. *
  382. * @param {JitsiConference} conference - The JitsiConference instance for which join by the local participant
  383. * is in progress.
  384. * @returns {{
  385. * type: CONFERENCE_JOIN_IN_PROGRESS,
  386. * conference: JitsiConference
  387. * }}
  388. */
  389. export function conferenceJoinInProgress(conference: IJitsiConference) {
  390. return {
  391. type: CONFERENCE_JOIN_IN_PROGRESS,
  392. conference
  393. };
  394. }
  395. /**
  396. * Signals that a specific conference has been left.
  397. *
  398. * @param {JitsiConference} conference - The JitsiConference instance which was
  399. * left by the local participant.
  400. * @returns {{
  401. * type: CONFERENCE_LEFT,
  402. * conference: JitsiConference
  403. * }}
  404. */
  405. export function conferenceLeft(conference?: IJitsiConference) {
  406. return {
  407. type: CONFERENCE_LEFT,
  408. conference
  409. };
  410. }
  411. /**
  412. * Signals that the conference subject has been changed.
  413. *
  414. * @param {string} subject - The new subject.
  415. * @returns {{
  416. * type: CONFERENCE_SUBJECT_CHANGED,
  417. * subject: string
  418. * }}
  419. */
  420. export function conferenceSubjectChanged(subject: string) {
  421. return {
  422. type: CONFERENCE_SUBJECT_CHANGED,
  423. subject
  424. };
  425. }
  426. /**
  427. * Signals that the conference timestamp has been changed.
  428. *
  429. * @param {number} conferenceTimestamp - The UTC timestamp.
  430. * @returns {{
  431. * type: CONFERENCE_TIMESTAMP_CHANGED,
  432. * conferenceTimestamp
  433. * }}
  434. */
  435. export function conferenceTimestampChanged(conferenceTimestamp: number) {
  436. return {
  437. type: CONFERENCE_TIMESTAMP_CHANGED,
  438. conferenceTimestamp
  439. };
  440. }
  441. /**
  442. * Signals that the unique identifier for conference has been set.
  443. *
  444. * @param {JitsiConference} conference - The JitsiConference instance, where the uuid has been set.
  445. * @returns {{
  446. * type: CONFERENCE_UNIQUE_ID_SET,
  447. * conference: JitsiConference,
  448. * }}
  449. */
  450. export function conferenceUniqueIdSet(conference: IJitsiConference) {
  451. return {
  452. type: CONFERENCE_UNIQUE_ID_SET,
  453. conference
  454. };
  455. }
  456. /**
  457. * Adds any existing local tracks to a specific conference before the conference
  458. * is joined. Then signals the intention of the application to have the local
  459. * participant join the specified conference.
  460. *
  461. * @param {JitsiConference} conference - The {@code JitsiConference} instance
  462. * the local participant will (try to) join.
  463. * @returns {Function}
  464. */
  465. export function _conferenceWillJoin(conference: IJitsiConference) {
  466. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  467. const state = getState();
  468. const localTracks
  469. = getLocalTracks(state['features/base/tracks'])
  470. .map(t => t.jitsiTrack);
  471. if (localTracks.length && !iAmVisitor(state)) {
  472. _addLocalTracksToConference(conference, localTracks);
  473. }
  474. dispatch(conferenceWillJoin(conference));
  475. };
  476. }
  477. /**
  478. * Signals the intention of the application to have a conference initialized.
  479. *
  480. * @returns {{
  481. * type: CONFERENCE_WILL_INIT
  482. * }}
  483. */
  484. export function conferenceWillInit() {
  485. return {
  486. type: CONFERENCE_WILL_INIT
  487. };
  488. }
  489. /**
  490. * Signals the intention of the application to have the local participant
  491. * join the specified conference.
  492. *
  493. * @param {JitsiConference} conference - The {@code JitsiConference} instance
  494. * the local participant will (try to) join.
  495. * @returns {{
  496. * type: CONFERENCE_WILL_JOIN,
  497. * conference: JitsiConference
  498. * }}
  499. */
  500. export function conferenceWillJoin(conference?: IJitsiConference) {
  501. return {
  502. type: CONFERENCE_WILL_JOIN,
  503. conference
  504. };
  505. }
  506. /**
  507. * Signals the intention of the application to have the local participant leave
  508. * a specific conference. Similar in fashion to CONFERENCE_LEFT. Contrary to it
  509. * though, it's not guaranteed because CONFERENCE_LEFT may be triggered by
  510. * lib-jitsi-meet and not the application.
  511. *
  512. * @param {JitsiConference} conference - The JitsiConference instance which will
  513. * be left by the local participant.
  514. * @param {boolean} isRedirect - Indicates if the action has been dispatched as part of visitor promotion.
  515. * @returns {{
  516. * type: CONFERENCE_LEFT,
  517. * conference: JitsiConference,
  518. * isRedirect: boolean
  519. * }}
  520. */
  521. export function conferenceWillLeave(conference?: IJitsiConference, isRedirect?: boolean) {
  522. return {
  523. type: CONFERENCE_WILL_LEAVE,
  524. conference,
  525. isRedirect
  526. };
  527. }
  528. /**
  529. * Initializes a new conference.
  530. *
  531. * @param {string} overrideRoom - Override the room to join, instead of taking it
  532. * from Redux.
  533. * @returns {Function}
  534. */
  535. export function createConference(overrideRoom?: string | String) {
  536. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  537. const state = getState();
  538. const { connection, locationURL } = state['features/base/connection'];
  539. if (!connection) {
  540. throw new Error('Cannot create a conference without a connection!');
  541. }
  542. const { password, room } = state['features/base/conference'];
  543. if (!room) {
  544. throw new Error('Cannot join a conference without a room name!');
  545. }
  546. // XXX: revisit this.
  547. // Hide the custom domain in the room name.
  548. const tmp: any = overrideRoom || room;
  549. let _room: any = getBackendSafeRoomName(tmp);
  550. if (tmp.domain) {
  551. // eslint-disable-next-line no-new-wrappers
  552. _room = new String(tmp);
  553. _room.domain = tmp.domain;
  554. }
  555. const conference = connection.initJitsiConference(_room, getConferenceOptions(state));
  556. // @ts-ignore
  557. connection[JITSI_CONNECTION_CONFERENCE_KEY] = conference;
  558. conference[JITSI_CONFERENCE_URL_KEY] = locationURL;
  559. dispatch(_conferenceWillJoin(conference));
  560. _addConferenceListeners(conference, dispatch, state);
  561. sendLocalParticipant(state, conference);
  562. const replaceParticipant = getReplaceParticipant(state);
  563. conference.join(password, replaceParticipant);
  564. };
  565. }
  566. /**
  567. * Will try to join the conference again in case it failed earlier with
  568. * {@link JitsiConferenceErrors.AUTHENTICATION_REQUIRED}. It means that Jicofo
  569. * did not allow to create new room from anonymous domain, but it can be tried
  570. * again later in case authenticated user created it in the meantime.
  571. *
  572. * @returns {Function}
  573. */
  574. export function checkIfCanJoin() {
  575. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  576. const { authRequired, password }
  577. = getState()['features/base/conference'];
  578. const replaceParticipant = getReplaceParticipant(getState());
  579. authRequired && dispatch(_conferenceWillJoin(authRequired));
  580. authRequired?.join(password, replaceParticipant);
  581. };
  582. }
  583. /**
  584. * Signals the data channel with the bridge has successfully opened.
  585. *
  586. * @returns {{
  587. * type: DATA_CHANNEL_OPENED
  588. * }}
  589. */
  590. export function dataChannelOpened() {
  591. return {
  592. type: DATA_CHANNEL_OPENED
  593. };
  594. }
  595. /**
  596. * Signals the data channel with the bridge was abruptly closed.
  597. *
  598. * @param {number} code - Close code.
  599. * @param {string} reason - Close reason.
  600. *
  601. * @returns {{
  602. * type: DATA_CHANNEL_CLOSED,
  603. * code: number,
  604. * reason: string
  605. * }}
  606. */
  607. export function dataChannelClosed(code: number, reason: string) {
  608. return {
  609. type: DATA_CHANNEL_CLOSED,
  610. code,
  611. reason
  612. };
  613. }
  614. /**
  615. * Signals that a participant sent an endpoint message on the data channel.
  616. *
  617. * @param {Object} participant - The participant details sending the message.
  618. * @param {Object} data - The data carried by the endpoint message.
  619. * @returns {{
  620. * type: ENDPOINT_MESSAGE_RECEIVED,
  621. * participant: Object,
  622. * data: Object
  623. * }}
  624. */
  625. export function endpointMessageReceived(participant: Object, data: Object) {
  626. return {
  627. type: ENDPOINT_MESSAGE_RECEIVED,
  628. participant,
  629. data
  630. };
  631. }
  632. /**
  633. * Action to end a conference for all participants.
  634. *
  635. * @returns {Function}
  636. */
  637. export function endConference() {
  638. return async (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  639. const { conference } = getConferenceState(toState(getState));
  640. conference?.end();
  641. };
  642. }
  643. /**
  644. * Signals that we've been kicked out of the conference.
  645. *
  646. * @param {JitsiConference} conference - The {@link JitsiConference} instance
  647. * for which the event is being signaled.
  648. * @param {JitsiParticipant} participant - The {@link JitsiParticipant}
  649. * instance which initiated the kick event.
  650. * @returns {{
  651. * type: KICKED_OUT,
  652. * conference: JitsiConference,
  653. * participant: JitsiParticipant
  654. * }}
  655. */
  656. export function kickedOut(conference: IJitsiConference, participant: Object) {
  657. return {
  658. type: KICKED_OUT,
  659. conference,
  660. participant
  661. };
  662. }
  663. /**
  664. * Action to leave a conference.
  665. *
  666. * @returns {Function}
  667. */
  668. export function leaveConference() {
  669. return async (dispatch: IStore['dispatch']) => dispatch(hangup(true));
  670. }
  671. /**
  672. * Signals that the lock state of a specific JitsiConference changed.
  673. *
  674. * @param {JitsiConference} conference - The JitsiConference which had its lock
  675. * state changed.
  676. * @param {boolean} locked - If the specified conference became locked, true;
  677. * otherwise, false.
  678. * @returns {{
  679. * type: LOCK_STATE_CHANGED,
  680. * conference: JitsiConference,
  681. * locked: boolean
  682. * }}
  683. */
  684. export function lockStateChanged(conference: IJitsiConference, locked: boolean) {
  685. return {
  686. type: LOCK_STATE_CHANGED,
  687. conference,
  688. locked
  689. };
  690. }
  691. /**
  692. * Signals that a non participant endpoint message has been received.
  693. *
  694. * @param {string} id - The resource id of the sender.
  695. * @param {Object} json - The json carried by the endpoint message.
  696. * @returns {{
  697. * type: NON_PARTICIPANT_MESSAGE_RECEIVED,
  698. * id: Object,
  699. * json: Object
  700. * }}
  701. */
  702. export function nonParticipantMessageReceived(id: string, json: Object) {
  703. return {
  704. type: NON_PARTICIPANT_MESSAGE_RECEIVED,
  705. id,
  706. json
  707. };
  708. }
  709. /**
  710. * Updates the known state of start muted policies.
  711. *
  712. * @param {boolean} audioMuted - Whether or not members will join the conference
  713. * as audio muted.
  714. * @param {boolean} videoMuted - Whether or not members will join the conference
  715. * as video muted.
  716. * @returns {{
  717. * type: SET_START_MUTED_POLICY,
  718. * startAudioMutedPolicy: boolean,
  719. * startVideoMutedPolicy: boolean
  720. * }}
  721. */
  722. export function onStartMutedPolicyChanged(
  723. audioMuted: boolean, videoMuted: boolean) {
  724. return {
  725. type: SET_START_MUTED_POLICY,
  726. startAudioMutedPolicy: audioMuted,
  727. startVideoMutedPolicy: videoMuted
  728. };
  729. }
  730. /**
  731. * Sets whether or not peer2peer is currently enabled.
  732. *
  733. * @param {boolean} p2p - Whether or not peer2peer is currently active.
  734. * @returns {{
  735. * type: P2P_STATUS_CHANGED,
  736. * p2p: boolean
  737. * }}
  738. */
  739. export function p2pStatusChanged(p2p: boolean) {
  740. return {
  741. type: P2P_STATUS_CHANGED,
  742. p2p
  743. };
  744. }
  745. /**
  746. * Signals to play touch tones.
  747. *
  748. * @param {string} tones - The tones to play.
  749. * @param {number} [duration] - How long to play each tone.
  750. * @param {number} [pause] - How long to pause between each tone.
  751. * @returns {{
  752. * type: SEND_TONES,
  753. * tones: string,
  754. * duration: number,
  755. * pause: number
  756. * }}
  757. */
  758. export function sendTones(tones: string, duration: number, pause: number) {
  759. return {
  760. type: SEND_TONES,
  761. tones,
  762. duration,
  763. pause
  764. };
  765. }
  766. /**
  767. * Enables or disables the Follow Me feature.
  768. *
  769. * @param {boolean} enabled - Whether or not Follow Me should be enabled.
  770. * @returns {{
  771. * type: SET_FOLLOW_ME,
  772. * enabled: boolean
  773. * }}
  774. */
  775. export function setFollowMe(enabled: boolean) {
  776. return {
  777. type: SET_FOLLOW_ME,
  778. enabled
  779. };
  780. }
  781. /**
  782. * Enables or disables the Follow Me feature used only for the recorder.
  783. *
  784. * @param {boolean} enabled - Whether Follow Me should be enabled and used only by the recorder.
  785. * @returns {{
  786. * type: SET_FOLLOW_ME_RECORDER,
  787. * enabled: boolean
  788. * }}
  789. */
  790. export function setFollowMeRecorder(enabled: boolean) {
  791. return {
  792. type: SET_FOLLOW_ME_RECORDER,
  793. enabled
  794. };
  795. }
  796. /**
  797. * Enables or disables the Mute reaction sounds feature.
  798. *
  799. * @param {boolean} muted - Whether or not reaction sounds should be muted for all participants.
  800. * @param {boolean} updateBackend - Whether or not the moderator should notify all participants for the new setting.
  801. * @returns {{
  802. * type: SET_START_REACTIONS_MUTED,
  803. * muted: boolean
  804. * }}
  805. */
  806. export function setStartReactionsMuted(muted: boolean, updateBackend = false) {
  807. return {
  808. type: SET_START_REACTIONS_MUTED,
  809. muted,
  810. updateBackend
  811. };
  812. }
  813. /**
  814. * Sets the password to join or lock a specific JitsiConference.
  815. *
  816. * @param {JitsiConference} conference - The JitsiConference which requires a
  817. * password to join or is to be locked with the specified password.
  818. * @param {Function} method - The JitsiConference method of password protection
  819. * such as join or lock.
  820. * @param {string} password - The password with which the specified conference
  821. * is to be joined or locked.
  822. * @returns {Function}
  823. */
  824. export function setPassword(
  825. conference: IJitsiConference | undefined,
  826. method: Function | undefined,
  827. password?: string) {
  828. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  829. if (!conference) {
  830. return Promise.reject();
  831. }
  832. switch (method) {
  833. case conference.join: {
  834. let state = getState()['features/base/conference'];
  835. dispatch({
  836. type: SET_PASSWORD,
  837. conference,
  838. method,
  839. password
  840. });
  841. // Join the conference with the newly-set password.
  842. // Make sure that the action did set the password.
  843. state = getState()['features/base/conference'];
  844. if (state.password === password
  845. // Make sure that the application still wants the
  846. // conference joined.
  847. && !state.conference) {
  848. method.call(conference, password);
  849. }
  850. break;
  851. }
  852. case conference.lock: {
  853. const state = getState()['features/base/conference'];
  854. if (state.conference === conference) {
  855. return (
  856. method.call(conference, password)
  857. .then(() => dispatch({
  858. type: SET_PASSWORD,
  859. conference,
  860. method,
  861. password
  862. }))
  863. .catch((error: Error) => dispatch({
  864. type: SET_PASSWORD_FAILED,
  865. error
  866. }))
  867. );
  868. }
  869. return Promise.reject();
  870. }
  871. }
  872. };
  873. }
  874. /**
  875. * Sets the obfuscated room name of the conference to be joined.
  876. *
  877. * @param {(string)} obfuscatedRoom - Obfuscated room name.
  878. * @param {(string)} obfuscatedRoomSource - The room name that was obfuscated.
  879. * @returns {{
  880. * type: SET_OBFUSCATED_ROOM,
  881. * room: string
  882. * }}
  883. */
  884. export function setObfuscatedRoom(obfuscatedRoom: string, obfuscatedRoomSource: string) {
  885. return {
  886. type: SET_OBFUSCATED_ROOM,
  887. obfuscatedRoom,
  888. obfuscatedRoomSource
  889. };
  890. }
  891. /**
  892. * Sets (the name of) the room of the conference to be joined.
  893. *
  894. * @param {(string|undefined)} room - The name of the room of the conference to
  895. * be joined.
  896. * @returns {{
  897. * type: SET_ROOM,
  898. * room: string
  899. * }}
  900. */
  901. export function setRoom(room?: string) {
  902. return {
  903. type: SET_ROOM,
  904. room
  905. };
  906. }
  907. /**
  908. * Sets whether or not members should join audio and/or video muted.
  909. *
  910. * @param {boolean} startAudioMuted - Whether or not members will join the
  911. * conference as audio muted.
  912. * @param {boolean} startVideoMuted - Whether or not members will join the
  913. * conference as video muted.
  914. * @returns {Function}
  915. */
  916. export function setStartMutedPolicy(
  917. startAudioMuted: boolean, startVideoMuted: boolean) {
  918. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  919. const conference = getCurrentConference(getState());
  920. conference?.setStartMutedPolicy({
  921. audio: startAudioMuted,
  922. video: startVideoMuted
  923. });
  924. dispatch(
  925. onStartMutedPolicyChanged(startAudioMuted, startVideoMuted));
  926. };
  927. }
  928. /**
  929. * Sets the conference subject.
  930. *
  931. * @param {string} subject - The new subject.
  932. * @returns {void}
  933. */
  934. export function setSubject(subject: string) {
  935. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  936. const { conference } = getState()['features/base/conference'];
  937. if (conference) {
  938. conference.setSubject(subject);
  939. } else {
  940. dispatch({
  941. type: SET_PENDING_SUBJECT_CHANGE,
  942. subject
  943. });
  944. }
  945. };
  946. }
  947. /**
  948. * Sets the conference local subject.
  949. *
  950. * @param {string} localSubject - The new local subject.
  951. * @returns {{
  952. * type: CONFERENCE_LOCAL_SUBJECT_CHANGED,
  953. * localSubject: string
  954. * }}
  955. */
  956. export function setLocalSubject(localSubject: string) {
  957. return {
  958. type: CONFERENCE_LOCAL_SUBJECT_CHANGED,
  959. localSubject
  960. };
  961. }
  962. /**
  963. * Sets the assumed bandwidth bps.
  964. *
  965. * @param {number} assumedBandwidthBps - The new assumed bandwidth.
  966. * @returns {{
  967. * type: SET_ASSUMED_BANDWIDTH_BPS,
  968. * assumedBandwidthBps: number
  969. * }}
  970. */
  971. export function setAssumedBandwidthBps(assumedBandwidthBps: number) {
  972. return {
  973. type: SET_ASSUMED_BANDWIDTH_BPS,
  974. assumedBandwidthBps
  975. };
  976. }
  977. /**
  978. * Redirects to a new visitor node.
  979. *
  980. * @param {string | undefined} vnode - The vnode to use or undefined if moving back to the main room.
  981. * @param {string} focusJid - The focus jid to use.
  982. * @param {string} username - The username to use.
  983. * @returns {void}
  984. */
  985. export function redirect(vnode: string, focusJid: string, username: string) {
  986. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  987. const newConfig = getVisitorOptions(getState, vnode, focusJid, username);
  988. if (!newConfig) {
  989. logger.warn('Not redirected missing params');
  990. return;
  991. }
  992. dispatch(overwriteConfig(newConfig));
  993. dispatch(disconnect(true))
  994. .then(() => {
  995. dispatch(setIAmVisitor(Boolean(vnode)));
  996. // we do not clear local tracks on error, so we need to manually clear them
  997. return dispatch(destroyLocalTracks());
  998. })
  999. .then(() => {
  1000. dispatch(conferenceWillInit());
  1001. return dispatch(connect());
  1002. })
  1003. .then(() => {
  1004. const media: Array<MediaType> = [];
  1005. if (!vnode) {
  1006. const state = getState();
  1007. const { enableMediaOnPromote = {} } = state['features/base/config'].visitors ?? {};
  1008. const { audio = false, video = false } = enableMediaOnPromote;
  1009. if (audio) {
  1010. const { available, muted, unmuteBlocked } = state['features/base/media'].audio;
  1011. const { startSilent } = state['features/base/config'];
  1012. // do not unmute the user if he was muted before (on the prejoin, the config
  1013. // or URL param, etc.)
  1014. if (!unmuteBlocked && !muted && !startSilent && available) {
  1015. media.push(MEDIA_TYPE.AUDIO);
  1016. }
  1017. }
  1018. if (video) {
  1019. const { muted, unmuteBlocked } = state['features/base/media'].video;
  1020. // do not unmute the user if he was muted before (on the prejoin, the config, URL param or
  1021. // audo only, etc)
  1022. if (!unmuteBlocked && !muted && hasAvailableDevices(state, 'videoInput')) {
  1023. media.push(MEDIA_TYPE.VIDEO);
  1024. }
  1025. }
  1026. }
  1027. dispatch(setupVisitorStartupMedia(media));
  1028. });
  1029. };
  1030. }