2017-02-28 03:21:50 +00:00
|
|
|
import { JitsiConferenceErrors } from '../lib-jitsi-meet';
|
2016-12-12 00:29:13 +00:00
|
|
|
import {
|
|
|
|
ReducerRegistry,
|
|
|
|
setStateProperties,
|
|
|
|
setStateProperty
|
|
|
|
} from '../redux';
|
2016-10-05 14:36:59 +00:00
|
|
|
|
|
|
|
import {
|
2016-12-12 01:02:50 +00:00
|
|
|
CONFERENCE_FAILED,
|
2016-10-05 14:36:59 +00:00
|
|
|
CONFERENCE_JOINED,
|
|
|
|
CONFERENCE_LEFT,
|
|
|
|
CONFERENCE_WILL_LEAVE,
|
2016-12-12 19:49:23 +00:00
|
|
|
LOCK_STATE_CHANGED,
|
2017-03-29 12:07:05 +00:00
|
|
|
SET_AUDIO_ONLY,
|
|
|
|
_SET_AUDIO_ONLY_VIDEO_MUTED,
|
2016-12-12 01:02:50 +00:00
|
|
|
SET_PASSWORD,
|
2016-10-05 14:36:59 +00:00
|
|
|
SET_ROOM
|
|
|
|
} from './actionTypes';
|
|
|
|
import { isRoomValid } from './functions';
|
|
|
|
|
2016-12-12 00:29:13 +00:00
|
|
|
/**
|
|
|
|
* 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 = {}, action) => {
|
|
|
|
switch (action.type) {
|
2016-12-12 01:02:50 +00:00
|
|
|
case CONFERENCE_FAILED:
|
|
|
|
return _conferenceFailed(state, action);
|
|
|
|
|
2016-12-12 00:29:13 +00:00
|
|
|
case CONFERENCE_JOINED:
|
|
|
|
return _conferenceJoined(state, action);
|
2016-10-05 14:36:59 +00:00
|
|
|
|
2016-12-12 00:29:13 +00:00
|
|
|
case CONFERENCE_LEFT:
|
|
|
|
return _conferenceLeft(state, action);
|
2016-10-05 14:36:59 +00:00
|
|
|
|
2016-12-12 00:29:13 +00:00
|
|
|
case CONFERENCE_WILL_LEAVE:
|
|
|
|
return _conferenceWillLeave(state, action);
|
|
|
|
|
2016-12-12 19:49:23 +00:00
|
|
|
case LOCK_STATE_CHANGED:
|
|
|
|
return _lockStateChanged(state, action);
|
|
|
|
|
2017-03-29 12:07:05 +00:00
|
|
|
case SET_AUDIO_ONLY:
|
|
|
|
return _setAudioOnly(state, action);
|
|
|
|
|
|
|
|
case _SET_AUDIO_ONLY_VIDEO_MUTED:
|
|
|
|
return _setAudioOnlyVideoMuted(state, action);
|
|
|
|
|
2016-12-12 01:02:50 +00:00
|
|
|
case SET_PASSWORD:
|
|
|
|
return _setPassword(state, action);
|
|
|
|
|
2016-12-12 00:29:13 +00:00
|
|
|
case SET_ROOM:
|
|
|
|
return _setRoom(state, action);
|
|
|
|
}
|
|
|
|
|
|
|
|
return state;
|
|
|
|
});
|
2016-10-05 14:36:59 +00:00
|
|
|
|
2016-12-12 01:02:50 +00:00
|
|
|
/**
|
|
|
|
* 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, action) {
|
|
|
|
const conference = action.conference;
|
|
|
|
|
|
|
|
if (state.conference && state.conference !== conference) {
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
const passwordRequired
|
|
|
|
= JitsiConferenceErrors.PASSWORD_REQUIRED === action.error
|
|
|
|
? conference
|
|
|
|
: undefined;
|
|
|
|
|
|
|
|
return (
|
|
|
|
setStateProperties(state, {
|
2017-03-29 12:07:05 +00:00
|
|
|
audioOnly: undefined,
|
|
|
|
audioOnlyVideoMuted: undefined,
|
2016-12-12 01:02:50 +00:00
|
|
|
conference: undefined,
|
|
|
|
leaving: undefined,
|
2016-12-12 19:49:23 +00:00
|
|
|
locked: undefined,
|
2016-12-12 01:02:50 +00:00
|
|
|
password: undefined,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The JitsiConference instance which requires a password to join.
|
|
|
|
*
|
|
|
|
* @type {JitsiConference}
|
|
|
|
*/
|
|
|
|
passwordRequired
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
2016-10-05 14:36:59 +00:00
|
|
|
/**
|
2016-12-12 00:29:13 +00:00
|
|
|
* 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, action) {
|
2016-12-12 19:49:23 +00:00
|
|
|
const conference = action.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.
|
|
|
|
const locked = conference.room.locked || undefined;
|
|
|
|
|
2016-12-12 00:29:13 +00:00
|
|
|
return (
|
|
|
|
setStateProperties(state, {
|
|
|
|
/**
|
|
|
|
* The JitsiConference instance represented by the Redux state of
|
|
|
|
* the feature base/conference.
|
|
|
|
*
|
|
|
|
* @type {JitsiConference}
|
|
|
|
*/
|
2016-12-12 19:49:23 +00:00
|
|
|
conference,
|
2016-12-12 01:02:50 +00:00
|
|
|
leaving: undefined,
|
2016-12-12 19:49:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The indicator which determines whether the conference is locked.
|
|
|
|
*
|
|
|
|
* @type {boolean}
|
|
|
|
*/
|
|
|
|
locked,
|
2016-12-12 01:02:50 +00:00
|
|
|
passwordRequired: undefined
|
2016-12-12 00:29:13 +00:00
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reduces a specific Redux action CONFERENCE_LEFT of the feature
|
|
|
|
* base/conference.
|
|
|
|
*
|
|
|
|
* @param {Object} state - The Redux state of the feature base/conference.
|
|
|
|
* @param {Action} action - The Redux action CONFERENCE_LEFT to reduce.
|
|
|
|
* @private
|
|
|
|
* @returns {Object} The new state of the feature base/conference after the
|
|
|
|
* reduction of the specified action.
|
2016-10-05 14:36:59 +00:00
|
|
|
*/
|
2016-12-12 00:29:13 +00:00
|
|
|
function _conferenceLeft(state, action) {
|
|
|
|
const conference = action.conference;
|
2016-10-05 14:36:59 +00:00
|
|
|
|
2016-12-12 00:29:13 +00:00
|
|
|
if (state.conference !== conference) {
|
2016-10-05 14:36:59 +00:00
|
|
|
return state;
|
2016-12-12 00:29:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
setStateProperties(state, {
|
2017-03-29 12:07:05 +00:00
|
|
|
audioOnly: undefined,
|
|
|
|
audioOnlyVideoMuted: undefined,
|
2016-12-12 00:29:13 +00:00
|
|
|
conference: undefined,
|
2016-12-12 01:02:50 +00:00
|
|
|
leaving: undefined,
|
2016-12-12 19:49:23 +00:00
|
|
|
locked: undefined,
|
2016-12-12 01:02:50 +00:00
|
|
|
password: undefined,
|
|
|
|
passwordRequired: undefined
|
2016-12-12 00:29:13 +00:00
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reduces a specific Redux action CONFERENCE_WILL_LEAVE of the feature
|
|
|
|
* base/conference.
|
|
|
|
*
|
|
|
|
* @param {Object} state - The Redux state of the feature base/conference.
|
|
|
|
* @param {Action} action - The Redux action CONFERENCE_WILL_LEAVE to reduce.
|
|
|
|
* @private
|
|
|
|
* @returns {Object} The new state of the feature base/conference after the
|
|
|
|
* reduction of the specified action.
|
|
|
|
*/
|
|
|
|
function _conferenceWillLeave(state, action) {
|
|
|
|
const conference = action.conference;
|
|
|
|
|
|
|
|
if (state.conference !== conference) {
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
setStateProperties(state, {
|
|
|
|
/**
|
|
|
|
* The JitsiConference instance which is currently in the process of
|
|
|
|
* being left.
|
|
|
|
*
|
|
|
|
* @type {JitsiConference}
|
|
|
|
*/
|
2016-12-12 01:02:50 +00:00
|
|
|
leaving: conference,
|
|
|
|
passwordRequired: undefined
|
2016-12-12 00:29:13 +00:00
|
|
|
}));
|
|
|
|
}
|
2016-12-07 22:04:52 +00:00
|
|
|
|
2016-12-12 19:49:23 +00:00
|
|
|
/**
|
|
|
|
* 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, action) {
|
|
|
|
if (state.conference !== action.conference) {
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
return setStateProperty(state, 'locked', action.locked || undefined);
|
|
|
|
}
|
|
|
|
|
2017-03-29 12:07:05 +00:00
|
|
|
/**
|
|
|
|
* Reduces a specific Redux action SET_AUDIO_ONLY of the feature
|
|
|
|
* base/conference.
|
|
|
|
*
|
|
|
|
* @param {Object} state - The Redux state of the feature base/conference.
|
|
|
|
* @param {Action} action - The Redux action SET_AUDIO_ONLY to reduce.
|
|
|
|
* @private
|
|
|
|
* @returns {Object} The new state of the feature base/conference after the
|
|
|
|
* reduction of the specified action.
|
|
|
|
*/
|
|
|
|
function _setAudioOnly(state, action) {
|
|
|
|
return setStateProperty(state, 'audioOnly', action.audioOnly);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reduces a specific Redux action _SET_AUDIO_ONLY_VIDEO_MUTED of the feature
|
|
|
|
* base/conference.
|
|
|
|
*
|
|
|
|
* @param {Object} state - The Redux state of the feature base/conference.
|
|
|
|
* @param {Action} action - The Redux action SET_AUDIO_ONLY_VIDEO_MUTED to
|
|
|
|
* reduce.
|
|
|
|
* @private
|
|
|
|
* @returns {Object} The new state of the feature base/conference after the
|
|
|
|
* reduction of the specified action.
|
|
|
|
*/
|
|
|
|
function _setAudioOnlyVideoMuted(state, action) {
|
|
|
|
return setStateProperty(state, 'audioOnlyVideoMuted', action.muted);
|
|
|
|
}
|
|
|
|
|
2016-12-12 01:02:50 +00:00
|
|
|
/**
|
|
|
|
* 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, action) {
|
|
|
|
const conference = action.conference;
|
|
|
|
|
|
|
|
switch (action.method) {
|
|
|
|
case conference.join:
|
|
|
|
if (state.passwordRequired === conference) {
|
|
|
|
return (
|
|
|
|
setStateProperties(state, {
|
|
|
|
/**
|
|
|
|
* The password with which the conference is to be joined.
|
|
|
|
*
|
|
|
|
* @type {string}
|
|
|
|
*/
|
|
|
|
password: action.password,
|
|
|
|
passwordRequired: undefined
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2016-12-07 22:04:52 +00:00
|
|
|
/**
|
|
|
|
* 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.room;
|
|
|
|
|
2017-01-15 19:05:17 +00:00
|
|
|
if (!isRoomValid(room)) {
|
2016-12-07 22:04:52 +00:00
|
|
|
// 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.
|
2016-12-12 00:29:13 +00:00
|
|
|
room = undefined;
|
2016-12-07 22:04:52 +00:00
|
|
|
}
|
|
|
|
|
2016-12-12 00:29:13 +00:00
|
|
|
/**
|
|
|
|
* The name of the room of the conference (to be) joined.
|
|
|
|
*
|
|
|
|
* @type {string}
|
|
|
|
*/
|
2016-12-07 22:04:52 +00:00
|
|
|
return setStateProperty(state, 'room', room);
|
|
|
|
}
|