Skip to content

Commit 5106f9f

Browse files
committed
Process do_external_connect.js through webpack
1 parent 2c61d8d commit 5106f9f

File tree

5 files changed

+86
-59
lines changed

5 files changed

+86
-59
lines changed

Makefile

+2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ deploy-appbundle:
2727
cp \
2828
$(BUILD_DIR)/app.bundle.min.js \
2929
$(BUILD_DIR)/app.bundle.min.map \
30+
$(BUILD_DIR)/do_external_connect.min.js \
31+
$(BUILD_DIR)/do_external_connect.min.map \
3032
$(BUILD_DIR)/external_api.min.js \
3133
$(BUILD_DIR)/external_api.min.map \
3234
$(OUTPUT_DIR)/analytics.js \

connection_optimization/.eslintrc.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
'extends': '../react/.eslintrc.js'
3+
};
+70-58
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,87 @@
1-
/* global config, getRoomName, getConfigParamsFromUrl */
2-
/* global createConnectionExternally */
1+
/* global config,
2+
createConnectionExternally,
3+
getConfigParamsFromUrl,
4+
getRoomName */
5+
36
/**
4-
* Implements extrnal connect using createConnectionExtenally function defined
7+
* Implements external connect using createConnectionExternally function defined
58
* in external_connect.js for Jitsi Meet. Parses the room name and token from
6-
* the url and executes createConnectionExtenally.
9+
* the URL and executes createConnectionExternally.
710
*
811
* NOTE: If you are using lib-jitsi-meet without Jitsi Meet you should use this
9-
* file as reference only because the implementation is Jitsi Meet specific.
12+
* file as reference only because the implementation is Jitsi Meet-specific.
1013
*
1114
* NOTE: For optimal results this file should be included right after
12-
* exrnal_connect.js.
15+
* external_connect.js.
1316
*/
1417

15-
/**
16-
* Executes createConnectionExternally function.
17-
*/
18-
(function () {
19-
var hashParams = getConfigParamsFromUrl("hash", true);
20-
var searchParams = getConfigParamsFromUrl("search", true);
18+
const hashParams = getConfigParamsFromUrl('hash', true);
19+
const searchParams = getConfigParamsFromUrl('search', true);
2120

22-
//Url params have higher proirity than config params
23-
var url = config.externalConnectUrl;
24-
if(hashParams.hasOwnProperty('config.externalConnectUrl'))
25-
url = hashParams["config.externalConnectUrl"];
21+
// URL params have higher proirity than config params.
22+
let url
23+
= hashParams.hasOwnProperty('config.externalConnectUrl')
24+
? hashParams['config.externalConnectUrl']
25+
: config.externalConnectUrl;
2626

27-
/**
28-
* Check if connect from connection.js was executed and executes the handler
29-
* that is going to finish the connect work.
30-
*/
31-
function checkForConnectHandlerAndConnect() {
27+
if (url && window.createConnectionExternally) {
28+
const roomName = getRoomName();
3229

33-
if(window.APP && window.APP.connect.status === "ready") {
34-
window.APP.connect.handler();
35-
}
36-
}
30+
if (roomName) {
31+
url += `?room=${roomName}`;
3732

38-
function error_callback(error){
39-
if(error) //error=undefined if external connect is disabled.
40-
console.warn(error);
41-
// Sets that global variable to be used later by connect method in
42-
// connection.js
43-
window.XMPPAttachInfo = {
44-
status: "error"
45-
};
46-
checkForConnectHandlerAndConnect();
47-
}
33+
const token
34+
= hashParams['config.token'] || config.token || searchParams.jwt;
4835

49-
if(!url || !window.createConnectionExternally) {
50-
error_callback();
51-
return;
52-
}
53-
var room_name = getRoomName();
54-
if(!room_name) {
55-
error_callback();
56-
return;
36+
if (token) {
37+
url += `&token=${token}`;
38+
}
39+
40+
createConnectionExternally(
41+
url,
42+
connectionInfo => {
43+
// Sets that global variable to be used later by connect method
44+
// in connection.js.
45+
window.XMPPAttachInfo = {
46+
status: 'success',
47+
data: connectionInfo
48+
};
49+
checkForConnectHandlerAndConnect();
50+
},
51+
errorCallback);
52+
} else {
53+
errorCallback();
5754
}
55+
} else {
56+
errorCallback();
57+
}
5858

59-
url += "?room=" + room_name;
59+
/**
60+
* Check if connect from connection.js was executed and executes the handler
61+
* that is going to finish the connect work.
62+
*
63+
* @returns {void}
64+
*/
65+
function checkForConnectHandlerAndConnect() {
66+
window.APP
67+
&& window.APP.connect.status === 'ready'
68+
&& window.APP.connect.handler();
69+
}
6070

61-
var token = hashParams["config.token"] || config.token ||
62-
searchParams.jwt;
63-
if(token)
64-
url += "&token=" + token;
71+
/**
72+
* Implements a callback to be invoked if anything goes wrong.
73+
*
74+
* @param {Error} error - The specifics of what went wrong.
75+
* @returns {void}
76+
*/
77+
function errorCallback(error) {
78+
// The value of error is undefined if external connect is disabled.
79+
error && console.warn(error);
6580

66-
createConnectionExternally(url, function(connectionInfo) {
67-
// Sets that global variable to be used later by connect method in
68-
// connection.js
69-
window.XMPPAttachInfo = {
70-
status: "success",
71-
data: connectionInfo
72-
};
73-
checkForConnectHandlerAndConnect();
74-
}, error_callback);
75-
})();
81+
// Sets that global variable to be used later by connect method in
82+
// connection.js.
83+
window.XMPPAttachInfo = {
84+
status: 'error'
85+
};
86+
checkForConnectHandlerAndConnect();
87+
}

index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@
129129
<script><!--#include virtual="/config.js" --></script><!-- adapt to your needs, i.e. set hosts and bosh path -->
130130
<script src="static/utils.js?v=1"></script>
131131
<!--#include virtual="connection_optimization/connection_optimization.html" -->
132-
<script src="connection_optimization/do_external_connect.js?v=1"></script>
132+
<script src="libs/do_external_connect.min.js?v=1"></script>
133133
<script><!--#include virtual="/interface_config.js" --></script>
134134
<script><!--#include virtual="/logging_config.js" --></script>
135135
<script src="libs/lib-jitsi-meet.min.js?v=139"></script>

webpack.config.js

+10
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,16 @@ const configs = [
174174
})
175175
}),
176176

177+
// The Webpack configuration to bundle do_external_connect.js (which
178+
// attempts to optimize Jitsi Meet's XMPP connection and, consequently, is
179+
// also known as HTTP pre-bind).
180+
Object.assign({}, config, {
181+
entry: {
182+
'do_external_connect':
183+
'./connection_optimization/do_external_connect.js'
184+
}
185+
}),
186+
177187
// The Webpack configuration to bundle external_api.js (aka
178188
// JitsiMeetExternalAPI).
179189
Object.assign({}, config, {

0 commit comments

Comments
 (0)