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.js 24KB

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