jiti-meet/connection_optimization/do_external_connect.js

91 lines
2.5 KiB
JavaScript
Raw Normal View History

2017-04-21 10:55:08 +00:00
/* global config, createConnectionExternally */
import {
getRoomName,
parseURLParams
} from '../react/features/base/config/functions';
/**
* Implements external connect using createConnectionExternally function defined
* in external_connect.js for Jitsi Meet. Parses the room name and token from
* the URL and executes createConnectionExternally.
*
* NOTE: If you are using lib-jitsi-meet without Jitsi Meet you should use this
* file as reference only because the implementation is Jitsi Meet-specific.
*
* NOTE: For optimal results this file should be included right after
* external_connect.js.
*/
2017-04-21 10:55:08 +00:00
const hashParams = parseURLParams(window.location, true);
2016-06-13 21:11:44 +00:00
// URL params have higher proirity than config params.
2017-04-21 10:55:08 +00:00
let url = hashParams['config.externalConnectUrl'] || config.externalConnectUrl;
if (url && window.createConnectionExternally) {
const roomName = getRoomName();
if (roomName) {
url += `?room=${roomName}`;
2017-04-21 10:55:08 +00:00
let token = hashParams['config.token'] || config.token;
if (!token) {
const searchParams
= parseURLParams(window.location, true, 'search');
2017-04-21 10:55:08 +00:00
token = searchParams.jwt;
}
if (token) {
url += `&token=${token}`;
}
createConnectionExternally(
url,
connectionInfo => {
// Sets that global variable to be used later by connect method
// in connection.js.
window.XMPPAttachInfo = {
status: 'success',
data: connectionInfo
};
checkForConnectHandlerAndConnect();
},
errorCallback);
} else {
errorCallback();
}
} else {
errorCallback();
}
/**
* Check if connect from connection.js was executed and executes the handler
* that is going to finish the connect work.
*
* @returns {void}
*/
function checkForConnectHandlerAndConnect() {
window.APP
&& window.APP.connect.status === 'ready'
&& window.APP.connect.handler();
}
/**
* Implements a callback to be invoked if anything goes wrong.
*
* @param {Error} error - The specifics of what went wrong.
* @returns {void}
*/
function errorCallback(error) {
// The value of error is undefined if external connect is disabled.
error && console.warn(error);
// Sets that global variable to be used later by connect method in
// connection.js.
window.XMPPAttachInfo = {
status: 'error'
};
checkForConnectHandlerAndConnect();
}