2017-10-04 22:36:09 +00:00
|
|
|
// @flow
|
|
|
|
|
2017-09-22 20:09:04 +00:00
|
|
|
import { CONNECTION_WILL_CONNECT } from '../connection';
|
2017-02-28 03:21:50 +00:00
|
|
|
import { JitsiConferenceErrors } from '../lib-jitsi-meet';
|
2017-04-22 22:57:08 +00:00
|
|
|
import { assign, ReducerRegistry, set } from '../redux';
|
2017-09-22 20:09:04 +00:00
|
|
|
import { LOCKED_LOCALLY, LOCKED_REMOTELY } from '../../room-lock';
|
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,
|
2017-07-06 11:51:35 +00:00
|
|
|
CONFERENCE_WILL_JOIN,
|
2016-10-05 14:36:59 +00:00
|
|
|
CONFERENCE_WILL_LEAVE,
|
2016-12-12 19:49:23 +00:00
|
|
|
LOCK_STATE_CHANGED,
|
2017-08-09 19:40:03 +00:00
|
|
|
P2P_STATUS_CHANGED,
|
2017-03-29 12:07:05 +00:00
|
|
|
SET_AUDIO_ONLY,
|
2016-12-12 01:02:50 +00:00
|
|
|
SET_PASSWORD,
|
2017-08-09 19:40:03 +00:00
|
|
|
SET_RECEIVE_VIDEO_QUALITY,
|
2017-10-03 16:30:42 +00:00
|
|
|
SET_ROOM,
|
|
|
|
SET_SIP_GATEWAY_ENABLED
|
2016-10-05 14:36:59 +00:00
|
|
|
} from './actionTypes';
|
2017-09-28 21:25:04 +00:00
|
|
|
import { VIDEO_QUALITY_LEVELS } from './constants';
|
2016-10-05 14:36:59 +00:00
|
|
|
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
|
|
|
|
2017-07-06 11:51:35 +00:00
|
|
|
case CONFERENCE_WILL_JOIN:
|
|
|
|
return _conferenceWillJoin(state, action);
|
|
|
|
|
2016-12-12 00:29:13 +00:00
|
|
|
case CONFERENCE_WILL_LEAVE:
|
|
|
|
return _conferenceWillLeave(state, action);
|
|
|
|
|
2017-09-22 20:09:04 +00:00
|
|
|
case CONNECTION_WILL_CONNECT:
|
|
|
|
return set(state, 'authRequired', undefined);
|
|
|
|
|
2016-12-12 19:49:23 +00:00
|
|
|
case LOCK_STATE_CHANGED:
|
|
|
|
return _lockStateChanged(state, action);
|
|
|
|
|
2017-08-09 19:40:03 +00:00
|
|
|
case P2P_STATUS_CHANGED:
|
|
|
|
return _p2pStatusChanged(state, action);
|
|
|
|
|
2017-03-29 12:07:05 +00:00
|
|
|
case SET_AUDIO_ONLY:
|
|
|
|
return _setAudioOnly(state, action);
|
|
|
|
|
2016-12-12 01:02:50 +00:00
|
|
|
case SET_PASSWORD:
|
|
|
|
return _setPassword(state, action);
|
|
|
|
|
2017-08-09 19:40:03 +00:00
|
|
|
case SET_RECEIVE_VIDEO_QUALITY:
|
|
|
|
return _setReceiveVideoQuality(state, action);
|
|
|
|
|
2016-12-12 00:29:13 +00:00
|
|
|
case SET_ROOM:
|
|
|
|
return _setRoom(state, action);
|
2017-10-03 16:30:42 +00:00
|
|
|
|
|
|
|
case SET_SIP_GATEWAY_ENABLED:
|
|
|
|
return _setSIPGatewayEnabled(state, action);
|
2016-12-12 00:29:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
2017-07-07 17:21:08 +00:00
|
|
|
function _conferenceFailed(state, { conference, error }) {
|
2016-12-12 01:02:50 +00:00
|
|
|
if (state.conference && state.conference !== conference) {
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2017-09-22 20:09:04 +00:00
|
|
|
let authRequired;
|
|
|
|
let passwordRequired;
|
|
|
|
|
2017-10-05 12:41:35 +00:00
|
|
|
switch (error.name) {
|
2017-09-22 20:09:04 +00:00
|
|
|
case JitsiConferenceErrors.AUTHENTICATION_REQUIRED:
|
|
|
|
authRequired = conference;
|
|
|
|
break;
|
2016-12-12 01:02:50 +00:00
|
|
|
|
2017-09-22 20:09:04 +00:00
|
|
|
case JitsiConferenceErrors.PASSWORD_REQUIRED:
|
|
|
|
passwordRequired = conference;
|
|
|
|
break;
|
|
|
|
}
|
2017-09-08 13:36:42 +00:00
|
|
|
|
2017-07-07 17:21:08 +00:00
|
|
|
return assign(state, {
|
2017-09-08 13:36:42 +00:00
|
|
|
authRequired,
|
2017-07-07 17:21:08 +00:00
|
|
|
conference: undefined,
|
|
|
|
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
|
|
|
|
});
|
2016-12-12 01:02:50 +00:00
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
*/
|
2017-07-07 17:21:08 +00:00
|
|
|
function _conferenceJoined(state, { conference }) {
|
2016-12-12 19:49:23 +00:00
|
|
|
// 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.
|
2017-04-13 00:23:43 +00:00
|
|
|
const locked = conference.room.locked ? LOCKED_REMOTELY : undefined;
|
2016-12-12 19:49:23 +00:00
|
|
|
|
2017-07-07 17:21:08 +00:00
|
|
|
return assign(state, {
|
2017-09-08 13:36:42 +00:00
|
|
|
authRequired: undefined,
|
|
|
|
|
2017-07-07 17:21:08 +00:00
|
|
|
/**
|
|
|
|
* 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,
|
2017-08-09 19:40:03 +00:00
|
|
|
passwordRequired: undefined,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The current resolution restraint on receiving remote video. By
|
|
|
|
* default the conference will send the highest level possible.
|
|
|
|
*
|
|
|
|
* @type number
|
|
|
|
*/
|
|
|
|
receiveVideoQuality: VIDEO_QUALITY_LEVELS.HIGH
|
2017-07-07 17:21:08 +00:00
|
|
|
});
|
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
|
|
|
*/
|
2017-07-07 17:21:08 +00:00
|
|
|
function _conferenceLeft(state, { conference }) {
|
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
|
|
|
}
|
|
|
|
|
2017-07-07 17:21:08 +00:00
|
|
|
return assign(state, {
|
2017-09-08 13:36:42 +00:00
|
|
|
authRequired: undefined,
|
2017-07-07 17:21:08 +00:00
|
|
|
conference: undefined,
|
|
|
|
joining: undefined,
|
|
|
|
leaving: undefined,
|
|
|
|
locked: undefined,
|
|
|
|
password: undefined,
|
|
|
|
passwordRequired: undefined
|
|
|
|
});
|
2016-12-12 00:29:13 +00:00
|
|
|
}
|
|
|
|
|
2017-07-06 11:51:35 +00:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2017-07-07 17:21:08 +00:00
|
|
|
function _conferenceWillJoin(state, { conference }) {
|
|
|
|
return set(state, 'joining', conference);
|
2017-07-06 11:51:35 +00:00
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
*/
|
2017-07-07 17:21:08 +00:00
|
|
|
function _conferenceWillLeave(state, { conference }) {
|
2016-12-12 00:29:13 +00:00
|
|
|
if (state.conference !== conference) {
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2017-07-07 17:21:08 +00:00
|
|
|
return assign(state, {
|
2017-09-08 13:36:42 +00:00
|
|
|
authRequired: undefined,
|
2017-07-07 17:21:08 +00:00
|
|
|
joining: undefined,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The JitsiConference instance which is currently in the process of
|
|
|
|
* being left.
|
|
|
|
*
|
|
|
|
* @type {JitsiConference}
|
|
|
|
*/
|
|
|
|
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.
|
|
|
|
*/
|
2017-07-07 17:21:08 +00:00
|
|
|
function _lockStateChanged(state, { conference, locked }) {
|
|
|
|
if (state.conference !== conference) {
|
2016-12-12 19:49:23 +00:00
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2017-04-22 22:57:08 +00:00
|
|
|
return assign(state, {
|
2017-07-07 17:21:08 +00:00
|
|
|
locked: locked ? state.locked || LOCKED_REMOTELY : undefined,
|
|
|
|
password: locked ? state.password : undefined
|
2017-04-13 00:23:43 +00:00
|
|
|
});
|
2016-12-12 19:49:23 +00:00
|
|
|
}
|
|
|
|
|
2017-03-29 12:07:05 +00:00
|
|
|
/**
|
2017-08-09 19:40:03 +00:00
|
|
|
* Reduces a specific Redux action P2P_STATUS_CHANGED of the feature
|
2017-03-29 12:07:05 +00:00
|
|
|
* base/conference.
|
|
|
|
*
|
|
|
|
* @param {Object} state - The Redux state of the feature base/conference.
|
2017-08-09 19:40:03 +00:00
|
|
|
* @param {Action} action - The Redux action P2P_STATUS_CHANGED to reduce.
|
2017-03-29 12:07:05 +00:00
|
|
|
* @private
|
|
|
|
* @returns {Object} The new state of the feature base/conference after the
|
|
|
|
* reduction of the specified action.
|
|
|
|
*/
|
2017-08-09 19:40:03 +00:00
|
|
|
function _p2pStatusChanged(state, action) {
|
|
|
|
return set(state, 'p2p', action.p2p);
|
2017-03-29 12:07:05 +00:00
|
|
|
}
|
|
|
|
|
2017-04-21 21:14:14 +00:00
|
|
|
/**
|
2017-08-09 19:40:03 +00:00
|
|
|
* Reduces a specific Redux action SET_AUDIO_ONLY of the feature
|
2017-04-21 21:14:14 +00:00
|
|
|
* base/conference.
|
|
|
|
*
|
|
|
|
* @param {Object} state - The Redux state of the feature base/conference.
|
2017-08-09 19:40:03 +00:00
|
|
|
* @param {Action} action - The Redux action SET_AUDIO_ONLY to reduce.
|
2017-04-21 21:14:14 +00:00
|
|
|
* @private
|
|
|
|
* @returns {Object} The new state of the feature base/conference after the
|
|
|
|
* reduction of the specified action.
|
|
|
|
*/
|
2017-08-09 19:40:03 +00:00
|
|
|
function _setAudioOnly(state, action) {
|
|
|
|
return set(state, 'audioOnly', action.audioOnly);
|
2017-04-21 21:14:14 +00:00
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
*/
|
2017-07-07 17:21:08 +00:00
|
|
|
function _setPassword(state, { conference, method, password }) {
|
|
|
|
switch (method) {
|
2017-04-18 21:49:52 +00:00
|
|
|
case conference.join:
|
2016-12-12 01:02:50 +00:00
|
|
|
if (state.passwordRequired === conference) {
|
2017-07-07 17:21:08 +00:00
|
|
|
return assign(state, {
|
|
|
|
locked: LOCKED_REMOTELY,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The password with which the conference is to be joined.
|
|
|
|
*
|
|
|
|
* @type {string}
|
|
|
|
*/
|
|
|
|
password,
|
|
|
|
passwordRequired: undefined
|
|
|
|
});
|
2016-12-12 01:02:50 +00:00
|
|
|
}
|
|
|
|
break;
|
2017-04-18 21:49:52 +00:00
|
|
|
|
|
|
|
case conference.lock:
|
2017-04-22 22:57:08 +00:00
|
|
|
return assign(state, {
|
2017-07-07 17:21:08 +00:00
|
|
|
locked: password ? LOCKED_LOCALLY : undefined,
|
|
|
|
password
|
2017-04-13 00:23:43 +00:00
|
|
|
});
|
|
|
|
}
|
2016-12-12 01:02:50 +00:00
|
|
|
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2017-08-09 19:40:03 +00:00
|
|
|
/**
|
|
|
|
* Reduces a specific Redux action SET_RECEIVE_VIDEO_QUALITY of the feature
|
|
|
|
* base/conference.
|
|
|
|
*
|
|
|
|
* @param {Object} state - The Redux state of the feature base/conference.
|
|
|
|
* @param {Action} action - The Redux action SET_RECEIVE_VIDEO_QUALITY to
|
|
|
|
* reduce.
|
|
|
|
* @private
|
|
|
|
* @returns {Object} The new state of the feature base/conference after the
|
|
|
|
* reduction of the specified action.
|
|
|
|
*/
|
|
|
|
function _setReceiveVideoQuality(state, action) {
|
|
|
|
return set(state, 'receiveVideoQuality', action.receiveVideoQuality);
|
|
|
|
}
|
|
|
|
|
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) {
|
2017-10-04 22:36:09 +00:00
|
|
|
let { room } = action;
|
2016-12-07 22:04:52 +00:00
|
|
|
|
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}
|
|
|
|
*/
|
2017-04-22 22:57:08 +00:00
|
|
|
return set(state, 'room', room);
|
2016-12-07 22:04:52 +00:00
|
|
|
}
|
2017-10-03 16:30:42 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
}
|