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 31KB

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