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

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