您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

actions.js 23KB

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