You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

actions.ts 28KB

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