2017-10-02 23:08:07 +00:00
|
|
|
/* @flow */
|
|
|
|
|
2017-02-16 19:57:39 +00:00
|
|
|
import type { Dispatch } from 'redux';
|
|
|
|
|
2017-02-28 03:21:50 +00:00
|
|
|
import JitsiMeetJS from './_';
|
2016-10-05 14:36:59 +00:00
|
|
|
import {
|
2017-02-27 22:45:53 +00:00
|
|
|
LIB_DID_DISPOSE,
|
|
|
|
LIB_DID_INIT,
|
2016-10-05 14:36:59 +00:00
|
|
|
LIB_INIT_ERROR,
|
2017-02-27 22:45:53 +00:00
|
|
|
LIB_WILL_DISPOSE,
|
core: refactor routing
Unfortunately, as the Jitsi Meet development evolved the routing mechanism
became more complex and thre logic ended up spread across multiple parts of the
codebase, which made it hard to follow and extend.
This change aims to fix that by rewriting the routing logic and centralizing it
in (pretty much) a single place, with no implicit inter-dependencies.
In order to arrive there, however, some extra changes were needed, which were
not caught early enough and are thus part of this change:
- JitsiMeetJS initialization is now synchronous: there is nothing async about
it, and the only async requirement (Temasys support) was lifted. See [0].
- WebRTC support can be detected early: building on top of the above, WebRTC
support can now be detected immediately, so take advantage of this to simplify
how we handle unsupported browsers. See [0].
The new router takes decissions based on the Redux state at the time of
invocation. A route can be represented by either a component or a URl reference,
with the latter taking precedence. On mobile, obviously, there is no concept of
URL reference so routing is based solely on components.
[0]: https://github.com/jitsi/lib-jitsi-meet/pull/779
2018-06-29 07:58:31 +00:00
|
|
|
LIB_WILL_INIT
|
2016-10-05 14:36:59 +00:00
|
|
|
} from './actionTypes';
|
2017-09-01 19:14:03 +00:00
|
|
|
import { isAnalyticsEnabled } from './functions';
|
2016-10-05 14:36:59 +00:00
|
|
|
|
2017-02-16 19:57:39 +00:00
|
|
|
declare var APP: Object;
|
|
|
|
|
2016-10-05 14:36:59 +00:00
|
|
|
/**
|
2017-02-27 22:45:53 +00:00
|
|
|
* Disposes (of) lib-jitsi-meet.
|
2016-10-05 14:36:59 +00:00
|
|
|
*
|
|
|
|
* @returns {Function}
|
|
|
|
*/
|
|
|
|
export function disposeLib() {
|
2019-03-19 15:42:25 +00:00
|
|
|
return (dispatch: Dispatch<any>) => {
|
2017-02-27 22:45:53 +00:00
|
|
|
dispatch({ type: LIB_WILL_DISPOSE });
|
2016-10-05 14:36:59 +00:00
|
|
|
|
2017-02-27 22:45:53 +00:00
|
|
|
// TODO Currently, lib-jitsi-meet doesn't have the functionality to
|
|
|
|
// dispose itself.
|
2017-05-17 21:44:28 +00:00
|
|
|
dispatch({ type: LIB_DID_DISPOSE });
|
2016-10-05 14:36:59 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-02-27 22:45:53 +00:00
|
|
|
* Initializes lib-jitsi-meet (i.e. {@link invokes JitsiMeetJS.init()}) with the
|
|
|
|
* current config(uration).
|
2016-10-05 14:36:59 +00:00
|
|
|
*
|
|
|
|
* @returns {Function}
|
|
|
|
*/
|
|
|
|
export function initLib() {
|
2019-03-19 15:42:25 +00:00
|
|
|
return (dispatch: Dispatch<any>, getState: Function): void => {
|
2017-04-23 20:14:02 +00:00
|
|
|
const config = getState()['features/base/config'];
|
2016-10-05 14:36:59 +00:00
|
|
|
|
|
|
|
if (!config) {
|
2017-02-24 19:08:49 +00:00
|
|
|
throw new Error('Cannot init lib-jitsi-meet without config');
|
2016-10-05 14:36:59 +00:00
|
|
|
}
|
|
|
|
|
2017-02-27 22:45:53 +00:00
|
|
|
dispatch({ type: LIB_WILL_INIT });
|
2016-10-05 14:36:59 +00:00
|
|
|
|
core: refactor routing
Unfortunately, as the Jitsi Meet development evolved the routing mechanism
became more complex and thre logic ended up spread across multiple parts of the
codebase, which made it hard to follow and extend.
This change aims to fix that by rewriting the routing logic and centralizing it
in (pretty much) a single place, with no implicit inter-dependencies.
In order to arrive there, however, some extra changes were needed, which were
not caught early enough and are thus part of this change:
- JitsiMeetJS initialization is now synchronous: there is nothing async about
it, and the only async requirement (Temasys support) was lifted. See [0].
- WebRTC support can be detected early: building on top of the above, WebRTC
support can now be detected immediately, so take advantage of this to simplify
how we handle unsupported browsers. See [0].
The new router takes decissions based on the Redux state at the time of
invocation. A route can be represented by either a component or a URl reference,
with the latter taking precedence. On mobile, obviously, there is no concept of
URL reference so routing is based solely on components.
[0]: https://github.com/jitsi/lib-jitsi-meet/pull/779
2018-06-29 07:58:31 +00:00
|
|
|
try {
|
|
|
|
JitsiMeetJS.init({
|
|
|
|
enableAnalyticsLogging: isAnalyticsEnabled(getState),
|
|
|
|
...config
|
|
|
|
});
|
|
|
|
dispatch({ type: LIB_DID_INIT });
|
|
|
|
} catch (error) {
|
|
|
|
dispatch(libInitError(error));
|
|
|
|
}
|
2016-10-05 14:36:59 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-02-24 19:08:49 +00:00
|
|
|
/**
|
|
|
|
* Notifies about a specific error raised by {@link JitsiMeetJS.init()}.
|
|
|
|
*
|
|
|
|
* @param {Error} error - The Error raised by JitsiMeetJS.init().
|
|
|
|
* @returns {{
|
|
|
|
* type: LIB_INIT_ERROR,
|
|
|
|
* error: Error
|
|
|
|
* }}
|
|
|
|
*/
|
|
|
|
export function libInitError(error: Error) {
|
|
|
|
return {
|
|
|
|
type: LIB_INIT_ERROR,
|
|
|
|
error
|
|
|
|
};
|
|
|
|
}
|