Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

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