Simplify, comply w/ coding style
Rename setStateProperties and setStateProperty to assign and set, respectively. Inspired by Object.assign, _.assign, and _.set.
This commit is contained in:
parent
1f16233afa
commit
bce1610794
|
@ -1,11 +1,7 @@
|
||||||
import { LOCKED_LOCALLY, LOCKED_REMOTELY } from '../../room-lock';
|
import { LOCKED_LOCALLY, LOCKED_REMOTELY } from '../../room-lock';
|
||||||
|
|
||||||
import { JitsiConferenceErrors } from '../lib-jitsi-meet';
|
import { JitsiConferenceErrors } from '../lib-jitsi-meet';
|
||||||
import {
|
import { assign, ReducerRegistry, set } from '../redux';
|
||||||
ReducerRegistry,
|
|
||||||
setStateProperties,
|
|
||||||
setStateProperty
|
|
||||||
} from '../redux';
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
CONFERENCE_FAILED,
|
CONFERENCE_FAILED,
|
||||||
|
@ -80,7 +76,7 @@ function _conferenceFailed(state, action) {
|
||||||
: undefined;
|
: undefined;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
setStateProperties(state, {
|
assign(state, {
|
||||||
audioOnly: undefined,
|
audioOnly: undefined,
|
||||||
audioOnlyVideoMuted: undefined,
|
audioOnlyVideoMuted: undefined,
|
||||||
conference: undefined,
|
conference: undefined,
|
||||||
|
@ -125,7 +121,7 @@ function _conferenceJoined(state, action) {
|
||||||
const locked = conference.room.locked ? LOCKED_REMOTELY : undefined;
|
const locked = conference.room.locked ? LOCKED_REMOTELY : undefined;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
setStateProperties(state, {
|
assign(state, {
|
||||||
/**
|
/**
|
||||||
* The JitsiConference instance represented by the Redux state of
|
* The JitsiConference instance represented by the Redux state of
|
||||||
* the feature base/conference.
|
* the feature base/conference.
|
||||||
|
@ -163,7 +159,7 @@ function _conferenceLeft(state, action) {
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
setStateProperties(state, {
|
assign(state, {
|
||||||
audioOnly: undefined,
|
audioOnly: undefined,
|
||||||
audioOnlyVideoMuted: undefined,
|
audioOnlyVideoMuted: undefined,
|
||||||
conference: undefined,
|
conference: undefined,
|
||||||
|
@ -192,7 +188,7 @@ function _conferenceWillLeave(state, action) {
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
setStateProperties(state, {
|
assign(state, {
|
||||||
/**
|
/**
|
||||||
* The JitsiConference instance which is currently in the process of
|
* The JitsiConference instance which is currently in the process of
|
||||||
* being left.
|
* being left.
|
||||||
|
@ -225,7 +221,7 @@ function _lockStateChanged(state, action) {
|
||||||
locked = state.locked || LOCKED_REMOTELY;
|
locked = state.locked || LOCKED_REMOTELY;
|
||||||
}
|
}
|
||||||
|
|
||||||
return setStateProperties(state, {
|
return assign(state, {
|
||||||
locked,
|
locked,
|
||||||
password: action.locked ? state.password : null
|
password: action.locked ? state.password : null
|
||||||
});
|
});
|
||||||
|
@ -242,7 +238,7 @@ function _lockStateChanged(state, action) {
|
||||||
* reduction of the specified action.
|
* reduction of the specified action.
|
||||||
*/
|
*/
|
||||||
function _setAudioOnly(state, action) {
|
function _setAudioOnly(state, action) {
|
||||||
return setStateProperty(state, 'audioOnly', action.audioOnly);
|
return set(state, 'audioOnly', action.audioOnly);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -257,7 +253,7 @@ function _setAudioOnly(state, action) {
|
||||||
* reduction of the specified action.
|
* reduction of the specified action.
|
||||||
*/
|
*/
|
||||||
function _setAudioOnlyVideoMuted(state, action) {
|
function _setAudioOnlyVideoMuted(state, action) {
|
||||||
return setStateProperty(state, 'audioOnlyVideoMuted', action.muted);
|
return set(state, 'audioOnlyVideoMuted', action.muted);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -276,7 +272,7 @@ function _setPassword(state, action) {
|
||||||
case conference.join:
|
case conference.join:
|
||||||
if (state.passwordRequired === conference) {
|
if (state.passwordRequired === conference) {
|
||||||
return (
|
return (
|
||||||
setStateProperties(state, {
|
assign(state, {
|
||||||
locked: LOCKED_REMOTELY,
|
locked: LOCKED_REMOTELY,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -291,7 +287,7 @@ function _setPassword(state, action) {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case conference.lock:
|
case conference.lock:
|
||||||
return setStateProperties(state, {
|
return assign(state, {
|
||||||
locked: action.password ? LOCKED_LOCALLY : undefined,
|
locked: action.password ? LOCKED_LOCALLY : undefined,
|
||||||
password: action.password
|
password: action.password
|
||||||
});
|
});
|
||||||
|
@ -324,5 +320,5 @@ function _setRoom(state, action) {
|
||||||
*
|
*
|
||||||
* @type {string}
|
* @type {string}
|
||||||
*/
|
*/
|
||||||
return setStateProperty(state, 'room', room);
|
return set(state, 'room', room);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/* @flow */
|
/* @flow */
|
||||||
|
|
||||||
import { ReducerRegistry, setStateProperty } from '../redux';
|
import { ReducerRegistry, set } from '../redux';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
CONNECTION_DISCONNECTED,
|
CONNECTION_DISCONNECTED,
|
||||||
|
@ -40,7 +40,7 @@ ReducerRegistry.register(
|
||||||
*/
|
*/
|
||||||
function _connectionDisconnected(state: Object, action: Object) {
|
function _connectionDisconnected(state: Object, action: Object) {
|
||||||
if (state.connection === action.connection) {
|
if (state.connection === action.connection) {
|
||||||
return setStateProperty(state, 'connection', undefined);
|
return set(state, 'connection', undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
return state;
|
return state;
|
||||||
|
@ -57,7 +57,7 @@ function _connectionDisconnected(state: Object, action: Object) {
|
||||||
* reduction of the specified action.
|
* reduction of the specified action.
|
||||||
*/
|
*/
|
||||||
function _connectionEstablished(state: Object, action: Object) {
|
function _connectionEstablished(state: Object, action: Object) {
|
||||||
return setStateProperty(state, 'connection', action.connection);
|
return set(state, 'connection', action.connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,27 +1,26 @@
|
||||||
import { ReducerRegistry, setStateProperties } from '../redux';
|
import { assign, ReducerRegistry } from '../redux';
|
||||||
|
|
||||||
import {
|
import { HIDE_DIALOG, OPEN_DIALOG } from './actionTypes';
|
||||||
HIDE_DIALOG,
|
|
||||||
OPEN_DIALOG
|
|
||||||
} from './actionTypes';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Listen for actions which show or hide dialogs.
|
* Reduces redux actions which show or hide dialogs.
|
||||||
*
|
*
|
||||||
* @param {Object[]} state - Current state.
|
* @param {State} state - The current redux state.
|
||||||
* @param {Object} action - Action object.
|
* @param {Action} action - The redux action to reduce.
|
||||||
* @param {string} action.type - Type of action.
|
* @param {string} action.type - The type of the redux action to reduce..
|
||||||
* @returns {{}}
|
* @returns {State} The next redux state that is the result of reducing the
|
||||||
|
* specified action.
|
||||||
*/
|
*/
|
||||||
ReducerRegistry.register('features/base/dialog', (state = {}, action) => {
|
ReducerRegistry.register('features/base/dialog', (state = {}, action) => {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case HIDE_DIALOG:
|
case HIDE_DIALOG:
|
||||||
return setStateProperties(state, {
|
return assign(state, {
|
||||||
component: undefined,
|
component: undefined,
|
||||||
componentProps: undefined
|
componentProps: undefined
|
||||||
});
|
});
|
||||||
|
|
||||||
case OPEN_DIALOG:
|
case OPEN_DIALOG:
|
||||||
return setStateProperties(state, {
|
return assign(state, {
|
||||||
component: action.component,
|
component: action.component,
|
||||||
componentProps: action.componentProps
|
componentProps: action.componentProps
|
||||||
});
|
});
|
||||||
|
|
|
@ -70,14 +70,14 @@ export function loadConfig(host: string, path: string = '/config.js') {
|
||||||
* @returns {Promise<JitsiLocalTrack>}
|
* @returns {Promise<JitsiLocalTrack>}
|
||||||
*/
|
*/
|
||||||
export function createLocalTrack(type, deviceId) {
|
export function createLocalTrack(type, deviceId) {
|
||||||
return JitsiMeetJS
|
return JitsiMeetJS.createLocalTracks({
|
||||||
.createLocalTracks({
|
cameraDeviceId: deviceId,
|
||||||
devices: [ type ],
|
devices: [ type ],
|
||||||
micDeviceId: deviceId,
|
|
||||||
cameraDeviceId: deviceId,
|
|
||||||
|
|
||||||
// eslint-disable-next-line camelcase
|
// eslint-disable-next-line camelcase
|
||||||
firefox_fake_device: window.config
|
firefox_fake_device:
|
||||||
&& window.config.firefox_fake_device
|
window.config && window.config.firefox_fake_device,
|
||||||
}).then(([ jitsiLocalTrack ]) => jitsiLocalTrack);
|
micDeviceId: deviceId
|
||||||
|
})
|
||||||
|
.then(([ jitsiLocalTrack ]) => jitsiLocalTrack);
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,8 +12,8 @@ import { WEBRTC_NOT_READY, WEBRTC_NOT_SUPPORTED } from './constants';
|
||||||
* lib-jitsi-meet, and initializes a new one with new config.
|
* lib-jitsi-meet, and initializes a new one with new config.
|
||||||
*
|
*
|
||||||
* @param {Store} store - Redux store.
|
* @param {Store} store - Redux store.
|
||||||
* @returns {Function}
|
|
||||||
* @private
|
* @private
|
||||||
|
* @returns {Function}
|
||||||
*/
|
*/
|
||||||
MiddlewareRegistry.register(store => next => action => {
|
MiddlewareRegistry.register(store => next => action => {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
|
@ -45,14 +45,14 @@ MiddlewareRegistry.register(store => next => action => {
|
||||||
* specified action to the specified store.
|
* specified action to the specified store.
|
||||||
* @param {Action} action - The Redux action LIB_INIT_ERROR which is being
|
* @param {Action} action - The Redux action LIB_INIT_ERROR which is being
|
||||||
* dispatched in the specified store.
|
* dispatched in the specified store.
|
||||||
|
* @private
|
||||||
* @returns {Object} The new state that is the result of the reduction of the
|
* @returns {Object} The new state that is the result of the reduction of the
|
||||||
* specified action.
|
* specified action.
|
||||||
* @private
|
|
||||||
*/
|
*/
|
||||||
function _libInitError(store, next, action) {
|
function _libInitError(store, next, action) {
|
||||||
const nextState = next(action);
|
const nextState = next(action);
|
||||||
|
|
||||||
const error = action.error;
|
const { error } = action;
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
let webRTCReady;
|
let webRTCReady;
|
||||||
|
@ -83,16 +83,15 @@ function _libInitError(store, next, action) {
|
||||||
* specified action to the specified store.
|
* specified action to the specified store.
|
||||||
* @param {Action} action - The Redux action SET_CONFIG which is being
|
* @param {Action} action - The Redux action SET_CONFIG which is being
|
||||||
* dispatched in the specified store.
|
* dispatched in the specified store.
|
||||||
|
* @private
|
||||||
* @returns {Object} The new state that is the result of the reduction of the
|
* @returns {Object} The new state that is the result of the reduction of the
|
||||||
* specified action.
|
* specified action.
|
||||||
* @private
|
|
||||||
*/
|
*/
|
||||||
function _setConfig(store, next, action) {
|
function _setConfig({ dispatch, getState }, next, action) {
|
||||||
const { dispatch, getState } = store;
|
|
||||||
const { initialized } = getState()['features/base/lib-jitsi-meet'];
|
const { initialized } = getState()['features/base/lib-jitsi-meet'];
|
||||||
|
|
||||||
// XXX Since the config is changing, the library lib-jitsi-meet must be
|
// XXX Since the config is changing, the library lib-jitsi-meet must be
|
||||||
// initialized again with the new config. Consequntly, it may need to be
|
// initialized again with the new config. Consequently, it may need to be
|
||||||
// disposed of first.
|
// disposed of first.
|
||||||
// TODO Currently, disposeLib actually does not dispose of lib-jitsi-meet
|
// TODO Currently, disposeLib actually does not dispose of lib-jitsi-meet
|
||||||
// because lib-jitsi-meet does not implement such functionality.
|
// because lib-jitsi-meet does not implement such functionality.
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { ReducerRegistry, setStateProperty } from '../redux';
|
import { ReducerRegistry, set } from '../redux';
|
||||||
import { randomHexString } from '../util';
|
import { randomHexString } from '../util';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
@ -55,10 +55,7 @@ function _participant(state, action) {
|
||||||
case DOMINANT_SPEAKER_CHANGED:
|
case DOMINANT_SPEAKER_CHANGED:
|
||||||
// Only one dominant speaker is allowed.
|
// Only one dominant speaker is allowed.
|
||||||
return (
|
return (
|
||||||
setStateProperty(
|
set(state, 'dominantSpeaker', state.id === action.participant.id));
|
||||||
state,
|
|
||||||
'dominantSpeaker',
|
|
||||||
state.id === action.participant.id));
|
|
||||||
|
|
||||||
case PARTICIPANT_ID_CHANGED:
|
case PARTICIPANT_ID_CHANGED:
|
||||||
if (state.id === action.oldValue) {
|
if (state.id === action.oldValue) {
|
||||||
|
@ -145,11 +142,7 @@ function _participant(state, action) {
|
||||||
|
|
||||||
case PIN_PARTICIPANT:
|
case PIN_PARTICIPANT:
|
||||||
// Currently, only one pinned participant is allowed.
|
// Currently, only one pinned participant is allowed.
|
||||||
return (
|
return set(state, 'pinned', state.id === action.participant.id);
|
||||||
setStateProperty(
|
|
||||||
state,
|
|
||||||
'pinned',
|
|
||||||
state.id === action.participant.id));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return state;
|
return state;
|
||||||
|
|
|
@ -11,11 +11,11 @@
|
||||||
* from the specified target by setting the specified properties to the
|
* from the specified target by setting the specified properties to the
|
||||||
* specified values.
|
* specified values.
|
||||||
*/
|
*/
|
||||||
export function setStateProperties(target, source) {
|
export function assign(target, source) {
|
||||||
let t = target;
|
let t = target;
|
||||||
|
|
||||||
for (const property in source) { // eslint-disable-line guard-for-in
|
for (const property in source) { // eslint-disable-line guard-for-in
|
||||||
t = setStateProperty(t, property, source[property], t === target);
|
t = set(t, property, source[property], t === target);
|
||||||
}
|
}
|
||||||
|
|
||||||
return t;
|
return t;
|
||||||
|
@ -37,8 +37,8 @@ export function setStateProperties(target, source) {
|
||||||
* constructed from the specified <tt>state</tt> by setting the specified
|
* constructed from the specified <tt>state</tt> by setting the specified
|
||||||
* <tt>property</tt> to the specified <tt>value</tt>.
|
* <tt>property</tt> to the specified <tt>value</tt>.
|
||||||
*/
|
*/
|
||||||
export function setStateProperty(state, property, value) {
|
export function set(state, property, value) {
|
||||||
return _setStateProperty(state, property, value, /* copyOnWrite */ true);
|
return _set(state, property, value, /* copyOnWrite */ true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* eslint-disable max-params */
|
/* eslint-disable max-params */
|
||||||
|
@ -62,7 +62,7 @@ export function setStateProperty(state, property, value) {
|
||||||
* <tt>state</tt> by setting the specified <tt>property</tt> to the specified
|
* <tt>state</tt> by setting the specified <tt>property</tt> to the specified
|
||||||
* <tt>value</tt>.
|
* <tt>value</tt>.
|
||||||
*/
|
*/
|
||||||
function _setStateProperty(state, property, value, copyOnWrite) {
|
function _set(state, property, value, copyOnWrite) {
|
||||||
// Delete state properties that are to be set to undefined. (It is a matter
|
// Delete state properties that are to be set to undefined. (It is a matter
|
||||||
// of personal preference, mostly.)
|
// of personal preference, mostly.)
|
||||||
if (typeof value === 'undefined'
|
if (typeof value === 'undefined'
|
||||||
|
|
|
@ -1,18 +1,11 @@
|
||||||
import { CONFERENCE_FAILED } from '../base/conference';
|
import { CONFERENCE_FAILED } from '../base/conference';
|
||||||
import {
|
import { CONNECTION_ESTABLISHED, CONNECTION_FAILED } from '../base/connection';
|
||||||
CONNECTION_ESTABLISHED,
|
|
||||||
CONNECTION_FAILED
|
|
||||||
} from '../base/connection';
|
|
||||||
import {
|
import {
|
||||||
isFatalJitsiConnectionError,
|
isFatalJitsiConnectionError,
|
||||||
JitsiConferenceErrors,
|
JitsiConferenceErrors,
|
||||||
JitsiConnectionErrors
|
JitsiConnectionErrors
|
||||||
} from '../base/lib-jitsi-meet';
|
} from '../base/lib-jitsi-meet';
|
||||||
import {
|
import { assign, ReducerRegistry, set } from '../base/redux';
|
||||||
ReducerRegistry,
|
|
||||||
setStateProperties,
|
|
||||||
setStateProperty
|
|
||||||
} from '../base/redux';
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
MEDIA_PERMISSION_PROMPT_VISIBILITY_CHANGED,
|
MEDIA_PERMISSION_PROMPT_VISIBILITY_CHANGED,
|
||||||
|
@ -59,7 +52,7 @@ function _conferenceFailed(state, action) {
|
||||||
|
|
||||||
if (error === JitsiConferenceErrors.FOCUS_LEFT
|
if (error === JitsiConferenceErrors.FOCUS_LEFT
|
||||||
|| error === JitsiConferenceErrors.VIDEOBRIDGE_NOT_AVAILABLE) {
|
|| error === JitsiConferenceErrors.VIDEOBRIDGE_NOT_AVAILABLE) {
|
||||||
return setStateProperties(state, {
|
return assign(state, {
|
||||||
haveToReload: true,
|
haveToReload: true,
|
||||||
isNetworkFailure: false,
|
isNetworkFailure: false,
|
||||||
reason: action.errorMessage
|
reason: action.errorMessage
|
||||||
|
@ -79,7 +72,7 @@ function _conferenceFailed(state, action) {
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
function _connectionEstablished(state) {
|
function _connectionEstablished(state) {
|
||||||
return setStateProperty(state, 'connectionEstablished', true);
|
return set(state, 'connectionEstablished', true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -99,10 +92,9 @@ function _connectionFailed(state, action) {
|
||||||
|
|
||||||
logger.error(`XMPP connection error: ${errorMessage}`);
|
logger.error(`XMPP connection error: ${errorMessage}`);
|
||||||
|
|
||||||
return setStateProperties(state, {
|
return assign(state, {
|
||||||
haveToReload: true,
|
haveToReload: true,
|
||||||
|
|
||||||
|
|
||||||
// From all of the cases above only CONNECTION_DROPPED_ERROR is
|
// From all of the cases above only CONNECTION_DROPPED_ERROR is
|
||||||
// considered a network type of failure.
|
// considered a network type of failure.
|
||||||
isNetworkFailure:
|
isNetworkFailure:
|
||||||
|
@ -125,7 +117,7 @@ function _connectionFailed(state, action) {
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
function _mediaPermissionPromptVisibilityChanged(state, action) {
|
function _mediaPermissionPromptVisibilityChanged(state, action) {
|
||||||
return setStateProperties(state, {
|
return assign(state, {
|
||||||
browser: action.browser,
|
browser: action.browser,
|
||||||
isMediaPermissionPromptVisible: action.isVisible
|
isMediaPermissionPromptVisible: action.isVisible
|
||||||
});
|
});
|
||||||
|
@ -140,5 +132,5 @@ function _mediaPermissionPromptVisibilityChanged(state, action) {
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
function _suspendDetected(state) {
|
function _suspendDetected(state) {
|
||||||
return setStateProperty(state, 'suspendDetected', true);
|
return set(state, 'suspendDetected', true);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue