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

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