2017-04-21 10:55:08 +00:00
|
|
|
/* global config, createConnectionExternally */
|
|
|
|
|
2017-05-04 15:20:41 +00:00
|
|
|
import getRoomName from '../react/features/base/config/getRoomName';
|
2020-05-07 22:26:37 +00:00
|
|
|
import { parseURLParams } from '../react/features/base/util/parseURLParams';
|
2017-04-11 23:27:43 +00:00
|
|
|
|
2016-03-28 21:19:32 +00:00
|
|
|
/**
|
2017-04-11 23:27:43 +00:00
|
|
|
* Implements external connect using createConnectionExternally function defined
|
2017-04-21 10:00:50 +00:00
|
|
|
* in external_connect.js for Jitsi Meet. Parses the room name and JSON Web
|
|
|
|
* Token (JWT) from the URL and executes createConnectionExternally.
|
2016-03-28 21:19:32 +00:00
|
|
|
*
|
2017-04-21 10:00:50 +00:00
|
|
|
* NOTE: If you are using lib-jitsi-meet without Jitsi Meet, you should use this
|
2017-04-11 23:27:43 +00:00
|
|
|
* file as reference only because the implementation is Jitsi Meet-specific.
|
2016-03-28 21:19:32 +00:00
|
|
|
*
|
|
|
|
* NOTE: For optimal results this file should be included right after
|
2017-04-11 23:27:43 +00:00
|
|
|
* external_connect.js.
|
2016-03-28 21:19:32 +00:00
|
|
|
*/
|
|
|
|
|
2017-04-21 10:00:50 +00:00
|
|
|
if (typeof createConnectionExternally === 'function') {
|
2017-12-12 19:16:55 +00:00
|
|
|
// URL params have higher priority than config params.
|
2020-01-24 18:36:20 +00:00
|
|
|
// Do not use external connect if websocket is enabled.
|
2017-04-21 10:00:50 +00:00
|
|
|
let url
|
|
|
|
= parseURLParams(window.location, true, 'hash')[
|
|
|
|
'config.externalConnectUrl']
|
2020-01-24 18:36:20 +00:00
|
|
|
|| config.websocket ? undefined : config.externalConnectUrl;
|
2017-12-12 19:16:55 +00:00
|
|
|
const isRecorder
|
|
|
|
= parseURLParams(window.location, true, 'hash')['config.iAmRecorder'];
|
|
|
|
|
2017-04-21 10:00:50 +00:00
|
|
|
let roomName;
|
2016-06-13 21:11:44 +00:00
|
|
|
|
2017-12-12 19:16:55 +00:00
|
|
|
if (url && (roomName = getRoomName()) && !isRecorder) {
|
2017-04-11 23:27:43 +00:00
|
|
|
url += `?room=${roomName}`;
|
2016-03-28 21:19:32 +00:00
|
|
|
|
2017-04-21 10:00:50 +00:00
|
|
|
const token = parseURLParams(window.location, true, 'search').jwt;
|
2017-04-21 10:55:08 +00:00
|
|
|
|
2017-04-11 23:27:43 +00:00
|
|
|
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();
|
2016-03-28 21:19:32 +00:00
|
|
|
}
|
2017-04-11 23:27:43 +00:00
|
|
|
} else {
|
|
|
|
errorCallback();
|
|
|
|
}
|
2016-03-28 21:19:32 +00:00
|
|
|
|
2017-04-11 23:27:43 +00:00
|
|
|
/**
|
|
|
|
* 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();
|
|
|
|
}
|
2016-03-28 21:19:32 +00:00
|
|
|
|
2017-04-11 23:27:43 +00:00
|
|
|
/**
|
|
|
|
* 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);
|
2016-03-28 21:19:32 +00:00
|
|
|
|
2017-04-11 23:27:43 +00:00
|
|
|
// Sets that global variable to be used later by connect method in
|
|
|
|
// connection.js.
|
|
|
|
window.XMPPAttachInfo = {
|
|
|
|
status: 'error'
|
|
|
|
};
|
|
|
|
checkForConnectHandlerAndConnect();
|
|
|
|
}
|