[RN] Don't open the camera on startup when there is no welcome page
The end goal of this patch was to avoid opening the camera when there is no welcome page. In order to achieve this, the logic for creating the local tracks was refactored: Before this patch local tracks were created when lib-jitsi-meet was initialized, and destroyed when it was deinitialized. As a side note, this meant that when a conference in a non-default domain was joined, local tracks were destroyed and recreated in quick succession. Now, local trans are created and destroyed based on what the next route will be, and this happens when the target room has been decided. This allows us to create local tracks the moment we need to render any route, and destroy them when there is no route to be rendered. As an interesting byproduct, this refactor also avoids the destruction + recreation of local tracks when a conference in a non-default domain was left.
This commit is contained in:
parent
b62b296080
commit
8225600b61
|
@ -5,6 +5,7 @@ import {
|
|||
SET_LOCATION_URL
|
||||
} from '../base/connection';
|
||||
import { MiddlewareRegistry } from '../base/redux';
|
||||
import { createInitialLocalTracks, destroyLocalTracks } from '../base/tracks';
|
||||
|
||||
MiddlewareRegistry.register(store => next => action => {
|
||||
switch (action.type) {
|
||||
|
@ -12,8 +13,10 @@ MiddlewareRegistry.register(store => next => action => {
|
|||
return _connectionEstablished(store, next, action);
|
||||
|
||||
case SET_LOCATION_URL:
|
||||
return _setLocationURL(store, next, action);
|
||||
|
||||
case SET_ROOM:
|
||||
return _setLocationURLOrRoom(store, next, action);
|
||||
return _setRoom(store, next, action);
|
||||
}
|
||||
|
||||
return next(action);
|
||||
|
@ -63,36 +66,77 @@ function _connectionEstablished(store, next, action) {
|
|||
/**
|
||||
* Navigates to a route in accord with a specific redux state.
|
||||
*
|
||||
* @param {Object} state - The redux state which determines/identifies the route
|
||||
* @param {Store} store - The redux store which determines/identifies the route
|
||||
* to navigate to.
|
||||
* @private
|
||||
* @returns {void}
|
||||
*/
|
||||
function _navigate(state) {
|
||||
function _navigate({ dispatch, getState }) {
|
||||
const state = getState();
|
||||
const { app, getRouteToRender } = state['features/app'];
|
||||
const routeToRender = getRouteToRender && getRouteToRender(state);
|
||||
|
||||
// Create/destroy the local tracks as needed: create them the first time we
|
||||
// are going to render an actual route (be that the WelcomePage or the
|
||||
// Conference).
|
||||
//
|
||||
// When the WelcomePage is disabled, the app will transition to the
|
||||
// null/undefined route. Detect these transitions and create/destroy the
|
||||
// local tracks so the camera doesn't stay open if the app is not rendering
|
||||
// any component.
|
||||
if (typeof routeToRender === 'undefined' || routeToRender === null) {
|
||||
// Destroy the local tracks if there is no route to render and there is
|
||||
// no welcome page.
|
||||
app.props.welcomePageEnabled || dispatch(destroyLocalTracks());
|
||||
} else {
|
||||
// Create the local tracks if they haven't been created yet.
|
||||
state['features/base/tracks'].some(t => t.local)
|
||||
|| dispatch(createInitialLocalTracks());
|
||||
}
|
||||
|
||||
app._navigate(routeToRender);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notifies the feature app that the action {@link SET_LOCATION_URL} or
|
||||
* {@link SET_ROOM} is being dispatched within a specific redux {@code store}.
|
||||
* Notifies the feature app that the action {@link SET_LOCATION_URL} is being
|
||||
* dispatched within a specific redux {@code store}.
|
||||
*
|
||||
* @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_LOCATION_URL} or
|
||||
* {@code SET_ROOM} which is being dispatched in the specified {@code store}.
|
||||
* @param {Action} action - The redux action, {@code SET_LOCATION_URL}, which is
|
||||
* being dispatched in the specified {@code store}.
|
||||
* @private
|
||||
* @returns {Object} The new state that is the result of the reduction of the
|
||||
* specified {@code action}.
|
||||
*/
|
||||
function _setLocationURLOrRoom({ getState }, next, action) {
|
||||
function _setLocationURL({ getState }, next, action) {
|
||||
const result = next(action);
|
||||
|
||||
_navigate(getState());
|
||||
getState()['features/app'].app._navigate(undefined);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notifies the feature app that the action {@link SET_ROOM} is being dispatched
|
||||
* within a specific redux {@code store}.
|
||||
*
|
||||
* @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}.
|
||||
* @private
|
||||
* @returns {Object} The new state that is the result of the reduction of the
|
||||
* specified {@code action}.
|
||||
*/
|
||||
function _setRoom(store, next, action) {
|
||||
const result = next(action);
|
||||
|
||||
_navigate(store);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
/* @flow */
|
||||
|
||||
import { LIB_DID_DISPOSE, LIB_DID_INIT } from '../lib-jitsi-meet';
|
||||
import {
|
||||
CAMERA_FACING_MODE,
|
||||
MEDIA_TYPE,
|
||||
|
@ -14,10 +13,6 @@ import {
|
|||
} from '../media';
|
||||
import { MiddlewareRegistry } from '../redux';
|
||||
|
||||
import {
|
||||
createInitialLocalTracks,
|
||||
destroyLocalTracks
|
||||
} from './actions';
|
||||
import { TRACK_ADDED, TRACK_REMOVED, TRACK_UPDATED } from './actionTypes';
|
||||
import { getLocalTrack, setTrackMuted } from './functions';
|
||||
|
||||
|
@ -33,14 +28,6 @@ declare var APP: Object;
|
|||
*/
|
||||
MiddlewareRegistry.register(store => next => action => {
|
||||
switch (action.type) {
|
||||
case LIB_DID_DISPOSE:
|
||||
store.dispatch(destroyLocalTracks());
|
||||
break;
|
||||
|
||||
case LIB_DID_INIT:
|
||||
store.dispatch(createInitialLocalTracks());
|
||||
break;
|
||||
|
||||
case SET_AUDIO_MUTED:
|
||||
_setMuted(store, action, MEDIA_TYPE.AUDIO);
|
||||
break;
|
||||
|
|
Loading…
Reference in New Issue