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

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