2017-02-03 18:51:12 +00:00
|
|
|
/* @flow */
|
|
|
|
|
2017-09-08 14:03:27 +00:00
|
|
|
import { SET_ROOM, setAudioOnly } from '../conference';
|
2017-07-27 19:08:40 +00:00
|
|
|
import { parseURLParams } from '../config';
|
2016-10-05 14:36:59 +00:00
|
|
|
import { MiddlewareRegistry } from '../redux';
|
|
|
|
import { setTrackMuted, TRACK_ADDED } from '../tracks';
|
|
|
|
|
2017-07-27 19:08:40 +00:00
|
|
|
import { setAudioMuted, setCameraFacingMode, setVideoMuted } from './actions';
|
2017-07-31 10:34:18 +00:00
|
|
|
import { CAMERA_FACING_MODE } from './constants';
|
2016-10-05 14:36:59 +00:00
|
|
|
|
|
|
|
/**
|
2017-07-27 19:08:40 +00:00
|
|
|
* Implements the entry point of the middleware of the feature base/media.
|
2016-10-05 14:36:59 +00:00
|
|
|
*
|
2017-07-27 19:08:40 +00:00
|
|
|
* @param {Store} store - The redux store.
|
2016-10-05 14:36:59 +00:00
|
|
|
* @returns {Function}
|
|
|
|
*/
|
|
|
|
MiddlewareRegistry.register(store => next => action => {
|
|
|
|
switch (action.type) {
|
2017-07-27 19:08:40 +00:00
|
|
|
case SET_ROOM:
|
|
|
|
return _setRoom(store, next, action);
|
|
|
|
|
|
|
|
case TRACK_ADDED: {
|
|
|
|
const result = next(action);
|
2016-10-05 14:36:59 +00:00
|
|
|
|
2017-01-28 23:28:13 +00:00
|
|
|
action.track.local && _syncTrackMutedState(store, action.track);
|
2017-07-27 19:08:40 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2016-10-05 14:36:59 +00:00
|
|
|
}
|
|
|
|
|
2017-07-27 19:08:40 +00:00
|
|
|
return next(action);
|
2016-10-05 14:36:59 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
2017-07-27 19:08:40 +00:00
|
|
|
* Notifies the feature base/media that the action {@link SET_ROOM} is being
|
|
|
|
* dispatched within a specific redux {@code store}.
|
2016-10-05 14:36:59 +00:00
|
|
|
*
|
2017-07-27 19:08:40 +00:00
|
|
|
* @param {Store} store - The redux store in which the specified {@code action}
|
|
|
|
* is being dispatched.
|
|
|
|
* @param {Dispatch} next - The redux {@code dispatch} function to dispatch the
|
|
|
|
* specified {@code action} to the specified {@code store}.
|
|
|
|
* @param {Action} action - The redux action, {@code SET_ROOM}, which is being
|
|
|
|
* dispatched in the specified {@code store}.
|
2017-01-28 23:28:13 +00:00
|
|
|
* @private
|
2017-07-27 19:08:40 +00:00
|
|
|
* @returns {Object} The new state that is the result of the reduction of the
|
|
|
|
* specified {@code action}.
|
2016-10-05 14:36:59 +00:00
|
|
|
*/
|
2017-07-27 19:08:40 +00:00
|
|
|
function _setRoom({ dispatch, getState }, next, action) {
|
2017-09-27 04:37:08 +00:00
|
|
|
const { room } = action;
|
|
|
|
|
|
|
|
// Read the config.
|
|
|
|
|
2017-07-27 19:08:40 +00:00
|
|
|
const state = getState();
|
2017-09-27 04:37:08 +00:00
|
|
|
let urlParams;
|
2017-07-27 19:08:40 +00:00
|
|
|
let audioMuted;
|
|
|
|
let videoMuted;
|
|
|
|
|
2017-09-27 04:37:08 +00:00
|
|
|
if (room) {
|
|
|
|
// The Jitsi Meet client may override the Jitsi Meet deployment in the
|
|
|
|
// (location) URL on the subject of the following:
|
|
|
|
// - startAudioOnly
|
|
|
|
// - startWithAudioMuted
|
|
|
|
// - startWithVideoMuted
|
|
|
|
urlParams
|
2017-07-27 19:08:40 +00:00
|
|
|
= parseURLParams(state['features/base/connection'].locationURL);
|
|
|
|
|
|
|
|
audioMuted = urlParams['config.startWithAudioMuted'];
|
|
|
|
videoMuted = urlParams['config.startWithVideoMuted'];
|
|
|
|
}
|
|
|
|
|
2017-09-27 04:37:08 +00:00
|
|
|
// Of course, the Jitsi Meet deployment defines config.js which should be
|
|
|
|
// respected if the client did not override it.
|
2017-07-27 19:08:40 +00:00
|
|
|
const config = state['features/base/config'];
|
|
|
|
|
|
|
|
typeof audioMuted === 'undefined'
|
|
|
|
&& (audioMuted = config.startWithAudioMuted);
|
|
|
|
typeof videoMuted === 'undefined'
|
|
|
|
&& (videoMuted = config.startWithVideoMuted);
|
|
|
|
|
2017-09-27 04:37:08 +00:00
|
|
|
// Apply the config.
|
2017-07-27 19:08:40 +00:00
|
|
|
|
2017-08-04 21:06:42 +00:00
|
|
|
// Unconditionally express the desires/expectations/intents of the app and
|
|
|
|
// the user i.e. the state of base/media. Eventually, practice/reality i.e.
|
|
|
|
// the state of base/tracks will or will not agree with the desires.
|
2017-09-27 04:37:08 +00:00
|
|
|
dispatch(setAudioMuted(Boolean(audioMuted)));
|
2017-08-04 21:06:42 +00:00
|
|
|
dispatch(setCameraFacingMode(CAMERA_FACING_MODE.USER));
|
2017-09-27 04:37:08 +00:00
|
|
|
dispatch(setVideoMuted(Boolean(videoMuted)));
|
|
|
|
|
|
|
|
// config.startAudioOnly
|
|
|
|
//
|
|
|
|
// FIXME Technically, the audio-only feature is owned by base/conference,
|
|
|
|
// not base/media so the following should be in base/conference.
|
|
|
|
// Practically, I presume it was easier to write the source code here
|
|
|
|
// because it looks like config.startWithAudioMuted and
|
|
|
|
// config.startWithVideoMuted.
|
|
|
|
if (room) {
|
|
|
|
let audioOnly = urlParams && urlParams['config.startAudioOnly'];
|
|
|
|
|
|
|
|
typeof audioOnly === 'undefined' && (audioOnly = config.startAudioOnly);
|
|
|
|
dispatch(setAudioOnly(Boolean(audioOnly)));
|
2017-09-08 14:03:27 +00:00
|
|
|
}
|
|
|
|
|
2017-07-27 19:08:40 +00:00
|
|
|
return next(action);
|
2016-10-05 14:36:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Syncs muted state of local media track with muted state from media state.
|
|
|
|
*
|
2017-07-27 19:08:40 +00:00
|
|
|
* @param {Store} store - The redux store.
|
|
|
|
* @param {Track} track - The local media track.
|
2017-01-28 23:28:13 +00:00
|
|
|
* @private
|
2016-10-05 14:36:59 +00:00
|
|
|
* @returns {void}
|
|
|
|
*/
|
2017-08-18 11:30:30 +00:00
|
|
|
function _syncTrackMutedState({ getState }, track) {
|
2017-07-31 16:27:34 +00:00
|
|
|
const state = getState()['features/base/media'];
|
2017-08-02 15:00:51 +00:00
|
|
|
const muted = Boolean(state[track.mediaType].muted);
|
2016-10-05 14:36:59 +00:00
|
|
|
|
|
|
|
// XXX If muted state of track when it was added is different from our media
|
|
|
|
// muted state, we need to mute track and explicitly modify 'muted' property
|
|
|
|
// on track. This is because though TRACK_ADDED action was dispatched it's
|
2017-07-27 19:08:40 +00:00
|
|
|
// not yet in redux state and JitsiTrackEvents.TRACK_MUTE_CHANGED may be
|
2016-10-05 14:36:59 +00:00
|
|
|
// fired before track gets to state.
|
|
|
|
if (track.muted !== muted) {
|
|
|
|
track.muted = muted;
|
2017-08-18 11:30:30 +00:00
|
|
|
setTrackMuted(track.jitsiTrack, muted);
|
2016-10-05 14:36:59 +00:00
|
|
|
}
|
|
|
|
}
|