| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453 | 
							- // @flow
 - 
 - import { CONNECTION_WILL_CONNECT, SET_LOCATION_URL } from '../connection';
 - import { JitsiConferenceErrors } from '../lib-jitsi-meet';
 - import { assign, ReducerRegistry, set } from '../redux';
 - import { LOCKED_LOCALLY, LOCKED_REMOTELY } from '../../room-lock';
 - 
 - import {
 -     AUTH_STATUS_CHANGED,
 -     CONFERENCE_FAILED,
 -     CONFERENCE_JOINED,
 -     CONFERENCE_LEFT,
 -     CONFERENCE_SUBJECT_CHANGED,
 -     CONFERENCE_WILL_JOIN,
 -     CONFERENCE_WILL_LEAVE,
 -     LOCK_STATE_CHANGED,
 -     P2P_STATUS_CHANGED,
 -     SET_DESKTOP_SHARING_ENABLED,
 -     SET_FOLLOW_ME,
 -     SET_MAX_RECEIVER_VIDEO_QUALITY,
 -     SET_PASSWORD,
 -     SET_PENDING_SUBJECT_CHANGE,
 -     SET_PREFERRED_RECEIVER_VIDEO_QUALITY,
 -     SET_ROOM,
 -     SET_SIP_GATEWAY_ENABLED,
 -     SET_START_MUTED_POLICY
 - } from './actionTypes';
 - import { VIDEO_QUALITY_LEVELS } from './constants';
 - import { isRoomValid } from './functions';
 - 
 - const DEFAULT_STATE = {
 -     conference: undefined,
 -     joining: undefined,
 -     leaving: undefined,
 -     locked: undefined,
 -     maxReceiverVideoQuality: VIDEO_QUALITY_LEVELS.HIGH,
 -     password: undefined,
 -     passwordRequired: undefined,
 -     preferredReceiverVideoQuality: VIDEO_QUALITY_LEVELS.HIGH
 - };
 - 
 - /**
 -  * Listen for actions that contain the conference object, so that it can be
 -  * stored for use by other action creators.
 -  */
 - ReducerRegistry.register(
 -     'features/base/conference',
 -     (state = DEFAULT_STATE, action) => {
 -         switch (action.type) {
 -         case AUTH_STATUS_CHANGED:
 -             return _authStatusChanged(state, action);
 - 
 -         case CONFERENCE_FAILED:
 -             return _conferenceFailed(state, action);
 - 
 -         case CONFERENCE_JOINED:
 -             return _conferenceJoined(state, action);
 - 
 -         case CONFERENCE_SUBJECT_CHANGED:
 -             return set(state, 'subject', action.subject);
 - 
 -         case CONFERENCE_LEFT:
 -         case CONFERENCE_WILL_LEAVE:
 -             return _conferenceLeftOrWillLeave(state, action);
 - 
 -         case CONFERENCE_WILL_JOIN:
 -             return _conferenceWillJoin(state, action);
 - 
 -         case CONNECTION_WILL_CONNECT:
 -             return set(state, 'authRequired', undefined);
 - 
 -         case LOCK_STATE_CHANGED:
 -             return _lockStateChanged(state, action);
 - 
 -         case P2P_STATUS_CHANGED:
 -             return _p2pStatusChanged(state, action);
 - 
 -         case SET_DESKTOP_SHARING_ENABLED:
 -             return _setDesktopSharingEnabled(state, action);
 - 
 -         case SET_FOLLOW_ME:
 -             return set(state, 'followMeEnabled', action.enabled);
 - 
 -         case SET_LOCATION_URL:
 -             return set(state, 'room', undefined);
 - 
 -         case SET_MAX_RECEIVER_VIDEO_QUALITY:
 -             return set(
 -                 state,
 -                 'maxReceiverVideoQuality',
 -                 action.maxReceiverVideoQuality);
 - 
 -         case SET_PASSWORD:
 -             return _setPassword(state, action);
 - 
 -         case SET_PENDING_SUBJECT_CHANGE:
 -             return set(state, 'pendingSubjectChange', action.subject);
 - 
 -         case SET_PREFERRED_RECEIVER_VIDEO_QUALITY:
 -             return set(
 -                 state,
 -                 'preferredReceiverVideoQuality',
 -                 action.preferredReceiverVideoQuality);
 - 
 -         case SET_ROOM:
 -             return _setRoom(state, action);
 - 
 -         case SET_SIP_GATEWAY_ENABLED:
 -             return _setSIPGatewayEnabled(state, action);
 - 
 -         case SET_START_MUTED_POLICY:
 -             return {
 -                 ...state,
 -                 startAudioMutedPolicy: action.startAudioMutedPolicy,
 -                 startVideoMutedPolicy: action.startVideoMutedPolicy
 -             };
 -         }
 - 
 -         return state;
 -     });
 - 
 - /**
 -  * Reduces a specific Redux action AUTH_STATUS_CHANGED of the feature
 -  * base/conference.
 -  *
 -  * @param {Object} state - The Redux state of the feature base/conference.
 -  * @param {Action} action - The Redux action AUTH_STATUS_CHANGED to reduce.
 -  * @private
 -  * @returns {Object} The new state of the feature base/conference after the
 -  * reduction of the specified action.
 -  */
 - function _authStatusChanged(state, { authEnabled, authLogin }) {
 -     return assign(state, {
 -         authEnabled,
 -         authLogin
 -     });
 - }
 - 
 - /**
 -  * Reduces a specific Redux action CONFERENCE_FAILED of the feature
 -  * base/conference.
 -  *
 -  * @param {Object} state - The Redux state of the feature base/conference.
 -  * @param {Action} action - The Redux action CONFERENCE_FAILED to reduce.
 -  * @private
 -  * @returns {Object} The new state of the feature base/conference after the
 -  * reduction of the specified action.
 -  */
 - function _conferenceFailed(state, { conference, error }) {
 -     // The current (similar to getCurrentConference in
 -     // base/conference/functions.js) conference which is joining or joined:
 -     const conference_ = state.conference || state.joining;
 - 
 -     if (conference_ && conference_ !== conference) {
 -         return state;
 -     }
 - 
 -     let authRequired;
 -     let passwordRequired;
 - 
 -     switch (error.name) {
 -     case JitsiConferenceErrors.AUTHENTICATION_REQUIRED:
 -         authRequired = conference;
 -         break;
 - 
 -     case JitsiConferenceErrors.PASSWORD_REQUIRED:
 -         passwordRequired = conference;
 -         break;
 -     }
 - 
 -     return assign(state, {
 -         authRequired,
 -         conference: undefined,
 -         error,
 -         joining: undefined,
 -         leaving: undefined,
 - 
 -         /**
 -          * The indicator of how the conference/room is locked. If falsy, the
 -          * conference/room is unlocked; otherwise, it's either
 -          * {@code LOCKED_LOCALLY} or {@code LOCKED_REMOTELY}.
 -          *
 -          * @type {string}
 -          */
 -         locked: passwordRequired ? LOCKED_REMOTELY : undefined,
 -         password: undefined,
 - 
 -         /**
 -          * The JitsiConference instance which requires a password to join.
 -          *
 -          * @type {JitsiConference}
 -          */
 -         passwordRequired
 -     });
 - }
 - 
 - /**
 -  * Reduces a specific Redux action CONFERENCE_JOINED of the feature
 -  * base/conference.
 -  *
 -  * @param {Object} state - The Redux state of the feature base/conference.
 -  * @param {Action} action - The Redux action CONFERENCE_JOINED to reduce.
 -  * @private
 -  * @returns {Object} The new state of the feature base/conference after the
 -  * reduction of the specified action.
 -  */
 - function _conferenceJoined(state, { conference }) {
 -     // FIXME The indicator which determines whether a JitsiConference is locked
 -     // i.e. password-protected is private to lib-jitsi-meet. However, the
 -     // library does not fire LOCK_STATE_CHANGED upon joining a JitsiConference
 -     // with a password.
 -     // FIXME Technically JitsiConference.room is a private field.
 -     const locked = conference.room && conference.room.locked ? LOCKED_REMOTELY : undefined;
 - 
 -     return assign(state, {
 -         authRequired: undefined,
 - 
 -         /**
 -          * The JitsiConference instance represented by the Redux state of the
 -          * feature base/conference.
 -          *
 -          * @type {JitsiConference}
 -          */
 -         conference,
 -         joining: undefined,
 -         leaving: undefined,
 - 
 -         /**
 -          * The indicator which determines whether the conference is locked.
 -          *
 -          * @type {boolean}
 -          */
 -         locked,
 -         passwordRequired: undefined
 -     });
 - }
 - 
 - /**
 -  * Reduces a specific redux action {@link CONFERENCE_LEFT} or
 -  * {@link CONFERENCE_WILL_LEAVE} for the feature base/conference.
 -  *
 -  * @param {Object} state - The redux state of the feature base/conference.
 -  * @param {Action} action - The redux action {@code CONFERENCE_LEFT} or
 -  * {@code CONFERENCE_WILL_LEAVE} to reduce.
 -  * @private
 -  * @returns {Object} The next/new state of the feature base/conference after the
 -  * reduction of the specified action.
 -  */
 - function _conferenceLeftOrWillLeave(state, { conference, type }) {
 -     const nextState = { ...state };
 - 
 -     // The redux action CONFERENCE_LEFT is the last time that we should be
 -     // hearing from a JitsiConference instance.
 -     //
 -     // The redux action CONFERENCE_WILL_LEAVE represents the order of the user
 -     // to leave a JitsiConference instance. From the user's perspective, there's
 -     // no going back (with respect to the instance itself). The app will perform
 -     // due clean-up like leaving the associated room, but the instance is no
 -     // longer the focus of the attention of the user and, consequently, the app.
 -     for (const p in state) {
 -         if (state[p] === conference) {
 -             nextState[p] = undefined;
 - 
 -             switch (p) {
 -             case 'conference':
 -             case 'passwordRequired':
 -                 // XXX Clear/unset locked & password for a conference which has
 -                 // been LOCKED_LOCALLY or LOCKED_REMOTELY.
 -                 delete nextState.locked;
 -                 delete nextState.password;
 -                 break;
 -             }
 -         }
 -     }
 - 
 -     if (type === CONFERENCE_WILL_LEAVE) {
 -         // A CONFERENCE_WILL_LEAVE is of further consequence only if it is
 -         // expected i.e. if the specified conference is joining or joined.
 -         if (conference === state.joining || conference === state.conference) {
 -             /**
 -              * The JitsiConference instance which is currently in the process of
 -              * being left.
 -              *
 -              * @type {JitsiConference}
 -              */
 -             nextState.leaving = conference;
 -         }
 -     }
 - 
 -     return nextState;
 - }
 - 
 - /**
 -  * Reduces a specific Redux action CONFERENCE_WILL_JOIN of the feature
 -  * base/conference.
 -  *
 -  * @param {Object} state - The Redux state of the feature base/conference.
 -  * @param {Action} action - The Redux action CONFERENCE_WILL_JOIN to reduce.
 -  * @private
 -  * @returns {Object} The new state of the feature base/conference after the
 -  * reduction of the specified action.
 -  */
 - function _conferenceWillJoin(state, { conference }) {
 -     return assign(state, {
 -         error: undefined,
 -         joining: conference
 -     });
 - }
 - 
 - /**
 -  * Reduces a specific Redux action LOCK_STATE_CHANGED of the feature
 -  * base/conference.
 -  *
 -  * @param {Object} state - The Redux state of the feature base/conference.
 -  * @param {Action} action - The Redux action LOCK_STATE_CHANGED to reduce.
 -  * @private
 -  * @returns {Object} The new state of the feature base/conference after the
 -  * reduction of the specified action.
 -  */
 - function _lockStateChanged(state, { conference, locked }) {
 -     if (state.conference !== conference) {
 -         return state;
 -     }
 - 
 -     return assign(state, {
 -         locked: locked ? state.locked || LOCKED_REMOTELY : undefined,
 -         password: locked ? state.password : undefined
 -     });
 - }
 - 
 - /**
 -  * Reduces a specific Redux action P2P_STATUS_CHANGED of the feature
 -  * base/conference.
 -  *
 -  * @param {Object} state - The Redux state of the feature base/conference.
 -  * @param {Action} action - The Redux action P2P_STATUS_CHANGED to reduce.
 -  * @private
 -  * @returns {Object} The new state of the feature base/conference after the
 -  * reduction of the specified action.
 -  */
 - function _p2pStatusChanged(state, action) {
 -     return set(state, 'p2p', action.p2p);
 - }
 - 
 - /**
 -  * Reduces a specific Redux action SET_DESKTOP_SHARING_ENABLED of the feature
 -  * base/conference.
 -  *
 -  * @param {Object} state - The Redux state of the feature base/conference.
 -  * @param {Action} action - The Redux action SET_DESKTOP_SHARING_ENABLED to
 -  * reduce.
 -  * @private
 -  * @returns {Object} The new state of the feature base/conference after the
 -  * reduction of the specified action.
 -  */
 - function _setDesktopSharingEnabled(state, action) {
 -     return set(state, 'desktopSharingEnabled', action.desktopSharingEnabled);
 - }
 - 
 - /**
 -  * Reduces a specific Redux action SET_PASSWORD of the feature base/conference.
 -  *
 -  * @param {Object} state - The Redux state of the feature base/conference.
 -  * @param {Action} action - The Redux action SET_PASSWORD to reduce.
 -  * @private
 -  * @returns {Object} The new state of the feature base/conference after the
 -  * reduction of the specified action.
 -  */
 - function _setPassword(state, { conference, method, password }) {
 -     switch (method) {
 -     case conference.join:
 -         if (state.passwordRequired === conference) {
 -             return assign(state, {
 -                 // XXX 1. The JitsiConference which transitions away from
 -                 // passwordRequired MUST remain in the redux state
 -                 // features/base/conference until it transitions into
 -                 // conference; otherwise, there is a span of time during which
 -                 // the redux state does not even know that there is a
 -                 // JitsiConference whatsoever.
 -                 //
 -                 // 2. The redux action setPassword will attempt to join the
 -                 // JitsiConference so joining is an appropriate transitional
 -                 // redux state.
 -                 //
 -                 // 3. The redux action setPassword will perform the same check
 -                 // before it proceeds with the re-join.
 -                 joining: state.conference ? state.joining : conference,
 -                 locked: LOCKED_REMOTELY,
 - 
 -                 /**
 -                  * The password with which the conference is to be joined.
 -                  *
 -                  * @type {string}
 -                  */
 -                 password,
 -                 passwordRequired: undefined
 -             });
 -         }
 -         break;
 - 
 -     case conference.lock:
 -         return assign(state, {
 -             locked: password ? LOCKED_LOCALLY : undefined,
 -             password
 -         });
 -     }
 - 
 -     return state;
 - }
 - 
 - /**
 -  * Reduces a specific Redux action SET_ROOM of the feature base/conference.
 -  *
 -  * @param {Object} state - The Redux state of the feature base/conference.
 -  * @param {Action} action - The Redux action SET_ROOM to reduce.
 -  * @private
 -  * @returns {Object} The new state of the feature base/conference after the
 -  * reduction of the specified action.
 -  */
 - function _setRoom(state, action) {
 -     let { room } = action;
 - 
 -     if (!isRoomValid(room)) {
 -         // Technically, there are multiple values which don't represent valid
 -         // room names. Practically, each of them is as bad as the rest of them
 -         // because we can't use any of them to join a conference.
 -         room = undefined;
 -     }
 - 
 -     /**
 -      * The name of the room of the conference (to be) joined.
 -      *
 -      * @type {string}
 -      */
 -     return assign(state, {
 -         error: undefined,
 -         room
 -     });
 - }
 - 
 - /**
 -  * Reduces a specific Redux action SET_SIP_GATEWAY_ENABLED of the feature
 -  * base/conference.
 -  *
 -  * @param {Object} state - The Redux state of the feature base/conference.
 -  * @param {Action} action - The Redux action SET_SIP_GATEWAY_ENABLED to reduce.
 -  * @private
 -  * @returns {Object} The new state of the feature base/conference after the
 -  * reduction of the specified action.
 -  */
 - function _setSIPGatewayEnabled(state, action) {
 -     return set(state, 'isSIPGatewayEnabled', action.isSIPGatewayEnabled);
 - }
 
 
  |