jiti-meet/react/features/base/connection/actions.web.js

133 lines
4.2 KiB
JavaScript
Raw Normal View History

2017-02-03 18:50:06 +00:00
/* @flow */
import type { Dispatch } from 'redux';
2016-12-12 21:13:17 +00:00
2017-02-28 03:21:50 +00:00
import { JitsiConferenceEvents } from '../lib-jitsi-meet';
2016-12-12 21:13:17 +00:00
import UIEvents from '../../../../service/UI/UIEvents';
import { SET_DOMAIN } from './actionTypes';
2016-12-12 21:13:17 +00:00
import { appNavigate } from '../../app';
2017-02-14 22:28:15 +00:00
import { setUnsupportedBrowser } from '../../unsupported-browser';
2017-02-03 18:50:06 +00:00
declare var APP: Object;
2017-02-16 21:22:40 +00:00
declare var config: Object;
2017-02-03 18:50:06 +00:00
const logger = require('jitsi-meet-logger').getLogger(__filename);
2016-12-12 21:13:17 +00:00
export {
connectionEstablished,
connectionFailed
} from './actions.native.js';
2016-12-12 21:13:17 +00:00
/**
* Opens new connection.
*
* @returns {Promise<JitsiConnection>}
*/
export function connect() {
2017-02-03 18:50:06 +00:00
return (dispatch: Dispatch<*>, getState: Function) => {
2016-12-12 21:13:17 +00:00
const state = getState();
2017-01-15 19:05:17 +00:00
// XXX Lib-jitsi-meet does not accept uppercase letters.
const room = state['features/base/conference'].room.toLowerCase();
2016-12-12 21:13:17 +00:00
// XXX For web based version we use conference initialization logic
// from the old app (at the moment of writing).
return APP.conference.init({ roomName: room }).then(() => {
if (APP.logCollector) {
// Start the LogCollector's periodic "store logs" task
APP.logCollector.start();
APP.logCollectorStarted = true;
// Make an attempt to flush in case a lot of logs have been
// cached, before the collector was started.
APP.logCollector.flush();
// This event listener will flush the logs, before
// the statistics module (CallStats) is stopped.
//
// NOTE The LogCollector is not stopped, because this event can
// be triggered multiple times during single conference
// (whenever statistics module is stopped). That includes
// the case when Jicofo terminates the single person left in the
// room. It will then restart the media session when someone
// eventually join the room which will start the stats again.
APP.conference.addConferenceListener(
JitsiConferenceEvents.BEFORE_STATISTICS_DISPOSED,
2016-12-12 21:13:17 +00:00
() => {
if (APP.logCollector) {
APP.logCollector.flush();
}
}
);
}
APP.UI.initConference();
APP.UI.addListener(UIEvents.LANG_CHANGED, language => {
APP.translation.setLanguage(language);
APP.settings.setLanguage(language);
});
APP.keyboardshortcut.init();
2017-02-16 21:22:40 +00:00
if (config.requireDisplayName && !APP.settings.getDisplayName()) {
APP.UI.promptDisplayName();
}
2016-12-12 21:13:17 +00:00
})
.catch(err => {
APP.UI.hideRingOverLay();
APP.API.notifyConferenceLeft(APP.conference.roomName);
logger.error(err);
2017-02-14 22:28:15 +00:00
dispatch(setUnsupportedBrowser(err));
// If during the conference initialization was defined that
// browser doesn't support WebRTC then we should define
// which route to render.
dispatch(appNavigate(room));
// Force reinitialization of the conference if WebRTC is ready.
if (err.webRTCReadyPromise) {
err.webRTCReadyPromise.then(() => {
// Setting plugin required flag to false because
// it's already been installed.
dispatch(setUnsupportedBrowser({
name: 'OK'
2017-02-14 22:28:15 +00:00
}));
dispatch(appNavigate(room));
});
}
2016-12-12 21:13:17 +00:00
});
};
}
/**
* Closes connection.
*
* @returns {Function}
*/
export function disconnect() {
// XXX For web based version we use conference hanging up logic from the old
// app.
2016-12-12 21:13:17 +00:00
return () => APP.conference.hangup();
}
/**
* Sets connection domain.
*
* @param {string} domain - Domain name.
* @returns {{
* type: SET_DOMAIN,
* domain: string
* }}
*/
2017-02-03 18:50:06 +00:00
export function setDomain(domain: string) {
2016-12-12 21:13:17 +00:00
return {
type: SET_DOMAIN,
domain
};
}