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

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