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

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