LIB_DID_DISPOSE, LIB_DID_INIT, LIB_WILL_DISPOSE, LIB_WILL_INIT
This commit is contained in:
parent
93c9419392
commit
0b9160fb75
|
@ -1,13 +1,23 @@
|
|||
import { Symbol } from '../react';
|
||||
|
||||
/**
|
||||
* Action to signal that lib-jitsi-meet library was disposed.
|
||||
* The type of Redux action which signals that {@link JitsiMeetJS} was disposed.
|
||||
*
|
||||
* {
|
||||
* type: LIB_DISPOSED
|
||||
* type: LIB_DID_DISPOSE
|
||||
* }
|
||||
*/
|
||||
export const LIB_DISPOSED = Symbol('LIB_DISPOSED');
|
||||
export const LIB_DID_DISPOSE = Symbol('LIB_DID_DISPOSE');
|
||||
|
||||
/**
|
||||
* The type of Redux action which signals that {@link JitsiMeetJS.init()} was
|
||||
* invoked and completed successfully.
|
||||
*
|
||||
* {
|
||||
* type: LIB_DID_INIT
|
||||
* }
|
||||
*/
|
||||
export const LIB_DID_INIT = Symbol('LIB_DID_INIT');
|
||||
|
||||
/**
|
||||
* Action to signal that lib-jitsi-meet initialized failed with error.
|
||||
|
@ -20,13 +30,24 @@ export const LIB_DISPOSED = Symbol('LIB_DISPOSED');
|
|||
export const LIB_INIT_ERROR = Symbol('LIB_INIT_ERROR');
|
||||
|
||||
/**
|
||||
* Action to signal that lib-jitsi-meet initialization succeeded.
|
||||
* The type of Redux action which signals that {@link JitsiMeetJS} will be
|
||||
* disposed.
|
||||
*
|
||||
* {
|
||||
* type: LIB_INITIALIZED
|
||||
* type: LIB_WILL_DISPOSE
|
||||
* }
|
||||
*/
|
||||
export const LIB_INITIALIZED = Symbol('LIB_INITIALIZED');
|
||||
export const LIB_WILL_DISPOSE = Symbol('LIB_WILL_DISPOSE');
|
||||
|
||||
/**
|
||||
* The type of Redux action which signals that {@link JitsiMeetJS.init()} will
|
||||
* be invoked.
|
||||
*
|
||||
* {
|
||||
* type: LIB_WILL_INIT
|
||||
* }
|
||||
*/
|
||||
export const LIB_WILL_INIT = Symbol('LIB_WILL_INIT');
|
||||
|
||||
/**
|
||||
* Action to signal that config was set.
|
||||
|
|
|
@ -4,35 +4,40 @@ import type { Dispatch } from 'redux';
|
|||
|
||||
import JitsiMeetJS from './';
|
||||
import {
|
||||
LIB_DISPOSED,
|
||||
LIB_DID_DISPOSE,
|
||||
LIB_DID_INIT,
|
||||
LIB_INIT_ERROR,
|
||||
LIB_INITIALIZED,
|
||||
LIB_WILL_DISPOSE,
|
||||
LIB_WILL_INIT,
|
||||
SET_CONFIG
|
||||
} from './actionTypes';
|
||||
|
||||
declare var APP: Object;
|
||||
|
||||
/**
|
||||
* Disposes lib-jitsi-meet.
|
||||
* Disposes (of) lib-jitsi-meet.
|
||||
*
|
||||
* @returns {Function}
|
||||
*/
|
||||
export function disposeLib() {
|
||||
// XXX We're wrapping it with Promise, because:
|
||||
// a) to be better aligned with initLib() method, which is async.
|
||||
// b) as currently there is no implementation for it in lib-jitsi-meet, and
|
||||
// there is a big chance it will be async.
|
||||
// TODO Currently, lib-jitsi-meet doesn't have any functionality to
|
||||
// dispose itself.
|
||||
return (dispatch: Dispatch<*>) => {
|
||||
dispatch({ type: LIB_DISPOSED });
|
||||
dispatch({ type: LIB_WILL_DISPOSE });
|
||||
|
||||
return Promise.resolve();
|
||||
// XXX We're wrapping it with Promise because:
|
||||
// a) to be better aligned with initLib() method which is async;
|
||||
// b) as currently there is no implementation for it in lib-jitsi-meet
|
||||
// and there is a big chance it will be async.
|
||||
// TODO Currently, lib-jitsi-meet doesn't have the functionality to
|
||||
// dispose itself.
|
||||
return (
|
||||
Promise.resolve()
|
||||
.then(() => dispatch({ type: LIB_DID_DISPOSE })));
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes lib-jitsi-meet with passed configuration.
|
||||
* Initializes lib-jitsi-meet (i.e. {@link invokes JitsiMeetJS.init()}) with the
|
||||
* current config(uration).
|
||||
*
|
||||
* @returns {Function}
|
||||
*/
|
||||
|
@ -50,15 +55,18 @@ export function initLib() {
|
|||
return Promise.resolve();
|
||||
}
|
||||
|
||||
return JitsiMeetJS.init(config)
|
||||
.then(() => dispatch({ type: LIB_INITIALIZED }))
|
||||
.catch(error => {
|
||||
dispatch(libInitError(error));
|
||||
dispatch({ type: LIB_WILL_INIT });
|
||||
|
||||
// TODO Handle LIB_INIT_ERROR error somewhere instead.
|
||||
console.error('lib-jitsi-meet failed to init:', error);
|
||||
throw error;
|
||||
});
|
||||
return (
|
||||
JitsiMeetJS.init(config)
|
||||
.then(() => dispatch({ type: LIB_DID_INIT }))
|
||||
.catch(error => {
|
||||
dispatch(libInitError(error));
|
||||
|
||||
// TODO Handle LIB_INIT_ERROR error somewhere instead.
|
||||
console.error('lib-jitsi-meet failed to init:', error);
|
||||
throw error;
|
||||
}));
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -1,10 +1,7 @@
|
|||
import { PARTICIPANT_LEFT } from '../participants';
|
||||
import { MiddlewareRegistry } from '../redux';
|
||||
|
||||
import {
|
||||
disposeLib,
|
||||
initLib
|
||||
} from './actions';
|
||||
import { disposeLib, initLib } from './actions';
|
||||
import { SET_CONFIG } from './actionTypes';
|
||||
|
||||
/**
|
||||
|
@ -15,6 +12,7 @@ import { SET_CONFIG } from './actionTypes';
|
|||
*
|
||||
* @param {Store} store - Redux store.
|
||||
* @returns {Function}
|
||||
* @private
|
||||
*/
|
||||
MiddlewareRegistry.register(store => next => action => {
|
||||
switch (action.type) {
|
||||
|
@ -39,9 +37,9 @@ MiddlewareRegistry.register(store => next => action => {
|
|||
* specified action to the specified store.
|
||||
* @param {Action} action - The Redux action SET_CONFIG which is being
|
||||
* dispatched in the specified store.
|
||||
* @private
|
||||
* @returns {Object} The new state that is the result of the reduction of the
|
||||
* specified action.
|
||||
* @private
|
||||
*/
|
||||
function _setConfig(store, next, action) {
|
||||
const { dispatch, getState } = store;
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import { ReducerRegistry } from '../redux';
|
||||
|
||||
import {
|
||||
LIB_DISPOSED,
|
||||
LIB_DID_DISPOSE,
|
||||
LIB_DID_INIT,
|
||||
LIB_INIT_ERROR,
|
||||
LIB_INITIALIZED,
|
||||
SET_CONFIG
|
||||
} from './actionTypes';
|
||||
|
||||
|
@ -46,9 +46,16 @@ ReducerRegistry.register(
|
|||
'features/base/lib-jitsi-meet',
|
||||
(state = INITIAL_STATE, action) => {
|
||||
switch (action.type) {
|
||||
case LIB_DISPOSED:
|
||||
case LIB_DID_DISPOSE:
|
||||
return INITIAL_STATE;
|
||||
|
||||
case LIB_DID_INIT:
|
||||
return {
|
||||
...state,
|
||||
initError: undefined,
|
||||
initialized: true
|
||||
};
|
||||
|
||||
case LIB_INIT_ERROR:
|
||||
return {
|
||||
...state,
|
||||
|
@ -56,13 +63,6 @@ ReducerRegistry.register(
|
|||
initialized: false
|
||||
};
|
||||
|
||||
case LIB_INITIALIZED:
|
||||
return {
|
||||
...state,
|
||||
initError: undefined,
|
||||
initialized: true
|
||||
};
|
||||
|
||||
case SET_CONFIG:
|
||||
return _setConfig(state, action);
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* @flow */
|
||||
|
||||
import { LIB_DISPOSED, LIB_INITIALIZED } from '../lib-jitsi-meet';
|
||||
import { LIB_DID_DISPOSE, LIB_DID_INIT } from '../lib-jitsi-meet';
|
||||
import {
|
||||
MEDIA_TYPE,
|
||||
SET_AUDIO_MUTED,
|
||||
|
@ -16,21 +16,21 @@ import { TRACK_UPDATED } from './actionTypes';
|
|||
import { getLocalTrack, setTrackMuted } from './functions';
|
||||
|
||||
/**
|
||||
* Middleware that captures LIB_INITIALIZED and LIB_DISPOSED actions
|
||||
* and respectively creates/destroys local media tracks. Also listens to media-
|
||||
* related actions and performs corresponding operations with tracks.
|
||||
* Middleware that captures LIB_DID_DISPOSE and LIB_DID_INIT actions and,
|
||||
* respectively, creates/destroys local media tracks. Also listens to
|
||||
* media-related actions and performs corresponding operations with tracks.
|
||||
*
|
||||
* @param {Store} store - Redux store.
|
||||
* @returns {Function}
|
||||
*/
|
||||
MiddlewareRegistry.register(store => next => action => {
|
||||
switch (action.type) {
|
||||
case LIB_INITIALIZED:
|
||||
store.dispatch(createLocalTracks());
|
||||
case LIB_DID_DISPOSE:
|
||||
store.dispatch(destroyLocalTracks());
|
||||
break;
|
||||
|
||||
case LIB_DISPOSED:
|
||||
store.dispatch(destroyLocalTracks());
|
||||
case LIB_DID_INIT:
|
||||
store.dispatch(createLocalTracks());
|
||||
break;
|
||||
|
||||
case SET_AUDIO_MUTED:
|
||||
|
|
Loading…
Reference in New Issue