2017-05-04 15:20:41 +00:00
|
|
|
/* @flow */
|
2016-10-05 14:36:59 +00:00
|
|
|
|
2017-05-04 15:20:41 +00:00
|
|
|
import { setConfigFromURLParams } from '../../base/config';
|
|
|
|
import { loadScript } from '../../base/util';
|
2017-04-23 20:17:31 +00:00
|
|
|
|
2017-02-19 00:42:11 +00:00
|
|
|
import JitsiMeetJS from './_';
|
|
|
|
|
|
|
|
declare var APP: Object;
|
|
|
|
|
|
|
|
const JitsiConnectionErrors = JitsiMeetJS.errors.connection;
|
|
|
|
|
2017-05-04 15:20:41 +00:00
|
|
|
/**
|
|
|
|
* Creates a JitsiLocalTrack model from the given device id.
|
|
|
|
*
|
|
|
|
* @param {string} type - The media type of track being created. Expected values
|
|
|
|
* are "video" or "audio".
|
|
|
|
* @param {string} deviceId - The id of the target media source.
|
|
|
|
* @returns {Promise<JitsiLocalTrack>}
|
|
|
|
*/
|
|
|
|
export function createLocalTrack(type: string, deviceId: string) {
|
|
|
|
return (
|
|
|
|
JitsiMeetJS.createLocalTracks({
|
|
|
|
cameraDeviceId: deviceId,
|
|
|
|
devices: [ type ],
|
|
|
|
|
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
firefox_fake_device:
|
|
|
|
window.config && window.config.firefox_fake_device,
|
|
|
|
micDeviceId: deviceId
|
|
|
|
})
|
|
|
|
.then(([ jitsiLocalTrack ]) => jitsiLocalTrack));
|
|
|
|
}
|
|
|
|
|
2017-02-19 00:42:11 +00:00
|
|
|
/**
|
|
|
|
* Determines whether a specific JitsiConnectionErrors instance indicates a
|
|
|
|
* fatal JitsiConnection error.
|
|
|
|
*
|
|
|
|
* FIXME Figure out the category of errors defined by the fucntion and describe
|
|
|
|
* that category. I've currently named the category fatal because it appears to
|
|
|
|
* be used in the cases of unrecoverable errors that necessitate a reload.
|
|
|
|
*
|
|
|
|
* @param {string} error - The JitsiConnectionErrors instance to
|
|
|
|
* categorize/classify.
|
|
|
|
* @returns {boolean} True if the specified JitsiConnectionErrors instance
|
|
|
|
* indicates a fatal JitsiConnection error; otherwise, false.
|
|
|
|
*/
|
|
|
|
export function isFatalJitsiConnectionError(error: string) {
|
|
|
|
return (
|
|
|
|
error === JitsiConnectionErrors.CONNECTION_DROPPED_ERROR
|
|
|
|
|| error === JitsiConnectionErrors.OTHER_ERROR
|
|
|
|
|| error === JitsiConnectionErrors.SERVER_ERROR);
|
|
|
|
}
|
|
|
|
|
2016-10-05 14:36:59 +00:00
|
|
|
/**
|
2017-05-09 05:15:43 +00:00
|
|
|
* Loads config.js from a specific remote server.
|
2016-10-05 14:36:59 +00:00
|
|
|
*
|
|
|
|
* @param {string} host - Host where config.js is hosted.
|
2017-05-09 05:15:43 +00:00
|
|
|
* @param {string} path='config.js' - Relative pah to config.js file.
|
2016-10-05 14:36:59 +00:00
|
|
|
* @returns {Promise<Object>}
|
|
|
|
*/
|
2017-05-09 05:15:43 +00:00
|
|
|
export function loadConfig(host: string, path: string = 'config.js') {
|
2017-05-04 15:20:41 +00:00
|
|
|
let promise;
|
2017-01-10 19:06:18 +00:00
|
|
|
|
2017-05-04 15:20:41 +00:00
|
|
|
if (typeof APP === 'undefined') {
|
|
|
|
promise
|
|
|
|
= loadScript(new URL(path, host).toString())
|
|
|
|
.then(() => {
|
|
|
|
const { config } = window;
|
2016-10-05 14:36:59 +00:00
|
|
|
|
2017-05-04 15:20:41 +00:00
|
|
|
// We don't want to pollute global scope.
|
|
|
|
window.config = undefined;
|
2016-10-05 14:36:59 +00:00
|
|
|
|
2017-05-04 15:20:41 +00:00
|
|
|
if (typeof config !== 'object') {
|
|
|
|
throw new Error('window.config is not an object');
|
|
|
|
}
|
2016-10-05 14:36:59 +00:00
|
|
|
|
2017-05-04 15:20:41 +00:00
|
|
|
return config;
|
|
|
|
})
|
|
|
|
.catch(err => {
|
|
|
|
console.error(`Failed to load ${path} from ${host}`, err);
|
2016-10-05 14:36:59 +00:00
|
|
|
|
2017-05-04 15:20:41 +00:00
|
|
|
throw err;
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
// Return config.js file from global scope. We can't use the version
|
|
|
|
// that's being used for the React Native app because the old/current
|
|
|
|
// Web app uses config from the global scope.
|
|
|
|
promise = Promise.resolve(window.config);
|
|
|
|
}
|
2017-03-29 17:43:30 +00:00
|
|
|
|
2017-05-04 15:20:41 +00:00
|
|
|
// FIXME It's neither here nor there at the time of this writing where
|
|
|
|
// config, interfaceConfig, and loggingConfig should be overwritten by URL
|
|
|
|
// params.
|
|
|
|
promise = promise.then(value => {
|
|
|
|
setConfigFromURLParams();
|
|
|
|
|
|
|
|
return value;
|
|
|
|
});
|
|
|
|
|
|
|
|
return promise;
|
2017-03-29 17:43:30 +00:00
|
|
|
}
|