LIB_DID_DISPOSE, LIB_DID_INIT, LIB_WILL_DISPOSE, LIB_WILL_INIT

This commit is contained in:
Lyubo Marinov 2017-02-27 16:45:53 -06:00
parent 93c9419392
commit 0b9160fb75
5 changed files with 76 additions and 49 deletions

View File

@ -1,13 +1,23 @@
import { Symbol } from '../react'; 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. * 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'); 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. * Action to signal that config was set.

View File

@ -4,35 +4,40 @@ import type { Dispatch } from 'redux';
import JitsiMeetJS from './'; import JitsiMeetJS from './';
import { import {
LIB_DISPOSED, LIB_DID_DISPOSE,
LIB_DID_INIT,
LIB_INIT_ERROR, LIB_INIT_ERROR,
LIB_INITIALIZED, LIB_WILL_DISPOSE,
LIB_WILL_INIT,
SET_CONFIG SET_CONFIG
} from './actionTypes'; } from './actionTypes';
declare var APP: Object; declare var APP: Object;
/** /**
* Disposes lib-jitsi-meet. * Disposes (of) lib-jitsi-meet.
* *
* @returns {Function} * @returns {Function}
*/ */
export function disposeLib() { 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<*>) => { 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} * @returns {Function}
*/ */
@ -50,15 +55,18 @@ export function initLib() {
return Promise.resolve(); return Promise.resolve();
} }
return JitsiMeetJS.init(config) dispatch({ type: LIB_WILL_INIT });
.then(() => dispatch({ type: LIB_INITIALIZED }))
.catch(error => {
dispatch(libInitError(error));
// TODO Handle LIB_INIT_ERROR error somewhere instead. return (
console.error('lib-jitsi-meet failed to init:', error); JitsiMeetJS.init(config)
throw error; .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;
}));
}; };
} }

View File

@ -1,10 +1,7 @@
import { PARTICIPANT_LEFT } from '../participants'; import { PARTICIPANT_LEFT } from '../participants';
import { MiddlewareRegistry } from '../redux'; import { MiddlewareRegistry } from '../redux';
import { import { disposeLib, initLib } from './actions';
disposeLib,
initLib
} from './actions';
import { SET_CONFIG } from './actionTypes'; import { SET_CONFIG } from './actionTypes';
/** /**
@ -15,6 +12,7 @@ import { SET_CONFIG } from './actionTypes';
* *
* @param {Store} store - Redux store. * @param {Store} store - Redux store.
* @returns {Function} * @returns {Function}
* @private
*/ */
MiddlewareRegistry.register(store => next => action => { MiddlewareRegistry.register(store => next => action => {
switch (action.type) { switch (action.type) {
@ -39,9 +37,9 @@ MiddlewareRegistry.register(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(store, next, action) {
const { dispatch, getState } = store; const { dispatch, getState } = store;

View File

@ -1,9 +1,9 @@
import { ReducerRegistry } from '../redux'; import { ReducerRegistry } from '../redux';
import { import {
LIB_DISPOSED, LIB_DID_DISPOSE,
LIB_DID_INIT,
LIB_INIT_ERROR, LIB_INIT_ERROR,
LIB_INITIALIZED,
SET_CONFIG SET_CONFIG
} from './actionTypes'; } from './actionTypes';
@ -46,9 +46,16 @@ ReducerRegistry.register(
'features/base/lib-jitsi-meet', 'features/base/lib-jitsi-meet',
(state = INITIAL_STATE, action) => { (state = INITIAL_STATE, action) => {
switch (action.type) { switch (action.type) {
case LIB_DISPOSED: case LIB_DID_DISPOSE:
return INITIAL_STATE; return INITIAL_STATE;
case LIB_DID_INIT:
return {
...state,
initError: undefined,
initialized: true
};
case LIB_INIT_ERROR: case LIB_INIT_ERROR:
return { return {
...state, ...state,
@ -56,13 +63,6 @@ ReducerRegistry.register(
initialized: false initialized: false
}; };
case LIB_INITIALIZED:
return {
...state,
initError: undefined,
initialized: true
};
case SET_CONFIG: case SET_CONFIG:
return _setConfig(state, action); return _setConfig(state, action);

View File

@ -1,6 +1,6 @@
/* @flow */ /* @flow */
import { LIB_DISPOSED, LIB_INITIALIZED } from '../lib-jitsi-meet'; import { LIB_DID_DISPOSE, LIB_DID_INIT } from '../lib-jitsi-meet';
import { import {
MEDIA_TYPE, MEDIA_TYPE,
SET_AUDIO_MUTED, SET_AUDIO_MUTED,
@ -16,21 +16,21 @@ import { TRACK_UPDATED } from './actionTypes';
import { getLocalTrack, setTrackMuted } from './functions'; import { getLocalTrack, setTrackMuted } from './functions';
/** /**
* Middleware that captures LIB_INITIALIZED and LIB_DISPOSED actions * Middleware that captures LIB_DID_DISPOSE and LIB_DID_INIT actions and,
* and respectively creates/destroys local media tracks. Also listens to media- * respectively, creates/destroys local media tracks. Also listens to
* related actions and performs corresponding operations with tracks. * media-related actions and performs corresponding operations with tracks.
* *
* @param {Store} store - Redux store. * @param {Store} store - Redux store.
* @returns {Function} * @returns {Function}
*/ */
MiddlewareRegistry.register(store => next => action => { MiddlewareRegistry.register(store => next => action => {
switch (action.type) { switch (action.type) {
case LIB_INITIALIZED: case LIB_DID_DISPOSE:
store.dispatch(createLocalTracks()); store.dispatch(destroyLocalTracks());
break; break;
case LIB_DISPOSED: case LIB_DID_INIT:
store.dispatch(destroyLocalTracks()); store.dispatch(createLocalTracks());
break; break;
case SET_AUDIO_MUTED: case SET_AUDIO_MUTED: