mirror of https://github.com/jitsi/jitsi-meet
parent
b67994235e
commit
2f01746c55
@ -1,158 +0,0 @@ |
||||
import { setRoom } from '../base/conference'; |
||||
import { |
||||
getDomain, |
||||
setDomain |
||||
} from '../base/connection'; |
||||
import { |
||||
loadConfig, |
||||
setConfig |
||||
} from '../base/lib-jitsi-meet'; |
||||
|
||||
import { |
||||
APP_WILL_MOUNT, |
||||
APP_WILL_UNMOUNT |
||||
} from './actionTypes'; |
||||
import { |
||||
_getRoomAndDomainFromUrlString, |
||||
_getRouteToRender |
||||
} from './functions'; |
||||
import './reducer'; |
||||
|
||||
/** |
||||
* Triggers an in-app navigation to a different route. Allows navigation to be |
||||
* abstracted between the mobile and web versions. |
||||
* |
||||
* @param {(string|undefined)} urlOrRoom - The URL or room name to which to |
||||
* navigate. |
||||
* @returns {Function} |
||||
*/ |
||||
export function appNavigate(urlOrRoom) { |
||||
return (dispatch, getState) => { |
||||
const oldDomain = getDomain(getState()); |
||||
|
||||
const { domain, room } = _getRoomAndDomainFromUrlString(urlOrRoom); |
||||
|
||||
// TODO Kostiantyn Tsaregradskyi: We should probably detect if user is
|
||||
// currently in a conference and ask her if she wants to close the
|
||||
// current conference and start a new one with the new room name or
|
||||
// domain.
|
||||
|
||||
if (typeof domain === 'undefined' || oldDomain === domain) { |
||||
// If both domain and room vars became undefined, that means we're
|
||||
// actually dealing with just room name and not with URL.
|
||||
dispatch( |
||||
_setRoomAndNavigate( |
||||
typeof room === 'undefined' && typeof domain === 'undefined' |
||||
? urlOrRoom |
||||
: room)); |
||||
} else if (oldDomain !== domain) { |
||||
// Update domain without waiting for config to be loaded to prevent
|
||||
// race conditions when we will start to load config multiple times.
|
||||
dispatch(setDomain(domain)); |
||||
|
||||
// If domain has changed, we need to load the config of the new
|
||||
// domain and set it, and only after that we can navigate to
|
||||
// different route.
|
||||
loadConfig(`https://${domain}`) |
||||
.then( |
||||
config => configLoaded(/* err */ undefined, config), |
||||
err => configLoaded(err, /* config */ undefined)); |
||||
} |
||||
|
||||
/** |
||||
* Notifies that an attempt to load the config(uration) of domain has |
||||
* completed. |
||||
* |
||||
* @param {string|undefined} err - If the loading has failed, the error |
||||
* detailing the cause of the failure. |
||||
* @param {Object|undefined} config - If the loading has succeeded, the |
||||
* loaded config(uration). |
||||
* @returns {void} |
||||
*/ |
||||
function configLoaded(err, config) { |
||||
if (err) { |
||||
// XXX The failure could be, for example, because of a
|
||||
// certificate-related error. In which case the connection will
|
||||
// fail later in Strophe anyway even if we use the default
|
||||
// config here.
|
||||
|
||||
// The function loadConfig will log the err.
|
||||
return; |
||||
} |
||||
|
||||
// We set room name only here to prevent race conditions on app
|
||||
// start to not make app re-render conference page for two times.
|
||||
dispatch(setRoom(room)); |
||||
dispatch(setConfig(config)); |
||||
_navigate(getState()); |
||||
} |
||||
}; |
||||
} |
||||
|
||||
/** |
||||
* Signals that a specific App will mount (in the terms of React). |
||||
* |
||||
* @param {App} app - The App which will mount. |
||||
* @returns {{ |
||||
* type: APP_WILL_MOUNT, |
||||
* app: App |
||||
* }} |
||||
*/ |
||||
export function appWillMount(app) { |
||||
return { |
||||
type: APP_WILL_MOUNT, |
||||
app |
||||
}; |
||||
} |
||||
|
||||
/** |
||||
* Signals that a specific App will unmount (in the terms of React). |
||||
* |
||||
* @param {App} app - The App which will unmount. |
||||
* @returns {{ |
||||
* type: APP_WILL_UNMOUNT, |
||||
* app: App |
||||
* }} |
||||
*/ |
||||
export function appWillUnmount(app) { |
||||
return { |
||||
type: APP_WILL_UNMOUNT, |
||||
app |
||||
}; |
||||
} |
||||
|
||||
/** |
||||
* Navigates to route corresponding to current room name. |
||||
* |
||||
* @param {Object} state - Redux state. |
||||
* @private |
||||
* @returns {void} |
||||
*/ |
||||
function _navigate(state) { |
||||
const app = state['features/app'].app; |
||||
const routeToRender = _getRouteToRender(state); |
||||
|
||||
app._navigate(routeToRender); |
||||
} |
||||
|
||||
/** |
||||
* Sets room and navigates to new route if needed. |
||||
* |
||||
* @param {string} newRoom - New room name. |
||||
* @private |
||||
* @returns {Function} |
||||
*/ |
||||
function _setRoomAndNavigate(newRoom) { |
||||
return (dispatch, getState) => { |
||||
const oldRoom = getState()['features/base/conference'].room; |
||||
|
||||
dispatch(setRoom(newRoom)); |
||||
|
||||
const state = getState(); |
||||
const room = state['features/base/conference'].room; |
||||
|
||||
if (room !== oldRoom) { |
||||
_navigate(state); |
||||
} |
||||
}; |
||||
} |
@ -1,61 +0,0 @@ |
||||
import { |
||||
LIB_DISPOSED, |
||||
SET_CONFIG |
||||
} from './actionTypes'; |
||||
import './middleware'; |
||||
import './reducer'; |
||||
|
||||
/** |
||||
* Disposes 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({ type: LIB_DISPOSED }); |
||||
|
||||
return Promise.resolve(); |
||||
}; |
||||
} |
||||
|
||||
/** |
||||
* Initializes lib-jitsi-meet with passed configuration. |
||||
* |
||||
* @returns {Function} |
||||
*/ |
||||
export function initLib() { |
||||
return (dispatch, getState) => { |
||||
const config = getState()['features/base/lib-jitsi-meet'].config; |
||||
|
||||
if (!config) { |
||||
throw new Error('Cannot initialize lib-jitsi-meet without config'); |
||||
} |
||||
|
||||
// XXX Temporary solution. Until conference.js hasn't been moved
|
||||
// to the react app we shouldn't use JitsiMeetJS from react app.
|
||||
return Promise.resolve(); |
||||
}; |
||||
} |
||||
|
||||
/** |
||||
* Sets config. |
||||
* |
||||
* @param {Object} config - Config object accepted by JitsiMeetJS#init() |
||||
* method. |
||||
* @returns {{ |
||||
* type: SET_CONFIG, |
||||
* config: Object |
||||
* }} |
||||
*/ |
||||
export function setConfig(config) { |
||||
return { |
||||
type: SET_CONFIG, |
||||
config |
||||
}; |
||||
} |
@ -1,10 +0,0 @@ |
||||
/** |
||||
* Returns config.js file from global scope. |
||||
* We can't use version that's being used for native app |
||||
* because the old app uses config from global scope. |
||||
* |
||||
* @returns {Promise<Object>} |
||||
*/ |
||||
export function loadConfig() { |
||||
return Promise.resolve(window.config); |
||||
} |
Loading…
Reference in new issue