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

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