Skip to content

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

LIB_DID_DISPOSE, LIB_DID_INIT, LIB_WILL_DISPOSE, LIB_WILL_INIT

Lyubo Marinov0b9160fb7592
diff --git a/react/features/base/lib-jitsi-meet/actionTypes.js b/react/features/base/lib-jitsi-meet/actionTypes.js
index 3993de2dcf..ace4605e12 100644
--- a/react/features/base/lib-jitsi-meet/actionTypes.js
+++ b/react/features/base/lib-jitsi-meet/actionTypes.js
@@ -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_WILL_DISPOSE
+ * }
+ */
+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_INITIALIZED
+ * type: LIB_WILL_INIT
* }
*/
-export const LIB_INITIALIZED = Symbol('LIB_INITIALIZED');
+export const LIB_WILL_INIT = Symbol('LIB_WILL_INIT');
/**
* Action to signal that config was set.
diff --git a/react/features/base/lib-jitsi-meet/actions.js b/react/features/base/lib-jitsi-meet/actions.js
index 6ab6f6c3b6..b0061e9f37 100644
--- a/react/features/base/lib-jitsi-meet/actions.js
+++ b/react/features/base/lib-jitsi-meet/actions.js
@@ -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;
+ }));
};
}
diff --git a/react/features/base/lib-jitsi-meet/middleware.js b/react/features/base/lib-jitsi-meet/middleware.js
index cb412d11aa..26bca5c8f4 100644
--- a/react/features/base/lib-jitsi-meet/middleware.js
+++ b/react/features/base/lib-jitsi-meet/middleware.js
@@ -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;
diff --git a/react/features/base/lib-jitsi-meet/reducer.js b/react/features/base/lib-jitsi-meet/reducer.js
index 10d934d510..2ea127f117 100644
--- a/react/features/base/lib-jitsi-meet/reducer.js
+++ b/react/features/base/lib-jitsi-meet/reducer.js
@@ -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,21 +46,21 @@ 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_INIT_ERROR:
+ case LIB_DID_INIT:
return {
...state,
- initError: action.error,
- initialized: false
+ initError: undefined,
+ initialized: true
};
- case LIB_INITIALIZED:
+ case LIB_INIT_ERROR:
return {
...state,
- initError: undefined,
- initialized: true
+ initError: action.error,
+ initialized: false
};
case SET_CONFIG:
diff --git a/react/features/base/tracks/middleware.js b/react/features/base/tracks/middleware.js
index 5e4259c117..e6c46c609a 100644
--- a/react/features/base/tracks/middleware.js
+++ b/react/features/base/tracks/middleware.js
@@ -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: