Browse Source

Process do_external_connect.js through webpack

master
Lyubo Marinov 7 years ago
parent
commit
5106f9f958
5 changed files with 86 additions and 59 deletions
  1. 2
    0
      Makefile
  2. 3
    0
      connection_optimization/.eslintrc.js
  3. 70
    58
      connection_optimization/do_external_connect.js
  4. 1
    1
      index.html
  5. 10
    0
      webpack.config.js

+ 2
- 0
Makefile View File

@@ -27,6 +27,8 @@ deploy-appbundle:
27 27
 	cp \
28 28
 		$(BUILD_DIR)/app.bundle.min.js \
29 29
 		$(BUILD_DIR)/app.bundle.min.map \
30
+		$(BUILD_DIR)/do_external_connect.min.js \
31
+		$(BUILD_DIR)/do_external_connect.min.map \
30 32
 		$(BUILD_DIR)/external_api.min.js \
31 33
 		$(BUILD_DIR)/external_api.min.map \
32 34
 		$(OUTPUT_DIR)/analytics.js \

+ 3
- 0
connection_optimization/.eslintrc.js View File

@@ -0,0 +1,3 @@
1
+module.exports = {
2
+    'extends': '../react/.eslintrc.js'
3
+};

+ 70
- 58
connection_optimization/do_external_connect.js View File

@@ -1,75 +1,87 @@
1
-/* global config, getRoomName, getConfigParamsFromUrl */
2
-/* global createConnectionExternally */
1
+/* global config,
2
+          createConnectionExternally,
3
+          getConfigParamsFromUrl,
4
+          getRoomName */
5
+
3 6
 /**
4
- * Implements extrnal connect using createConnectionExtenally function defined
7
+ * Implements external connect using createConnectionExternally function defined
5 8
  * 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.
7 10
  *
8 11
  * 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.
10 13
  *
11 14
  * NOTE: For optimal results this file should be included right after
12
- * exrnal_connect.js.
15
+ * external_connect.js.
13 16
  */
14 17
 
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);
21 20
 
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;
26 26
 
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();
32 29
 
33
-        if(window.APP && window.APP.connect.status === "ready") {
34
-            window.APP.connect.handler();
35
-        }
36
-    }
30
+    if (roomName) {
31
+        url += `?room=${roomName}`;
37 32
 
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;
48 35
 
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();
57 54
     }
55
+} else {
56
+    errorCallback();
57
+}
58 58
 
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
+}
60 70
 
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);
65 80
 
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
+}

+ 1
- 1
index.html View File

@@ -129,7 +129,7 @@
129 129
     <script><!--#include virtual="/config.js" --></script><!-- adapt to your needs, i.e. set hosts and bosh path -->
130 130
     <script src="static/utils.js?v=1"></script>
131 131
     <!--#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>
133 133
     <script><!--#include virtual="/interface_config.js" --></script>
134 134
     <script><!--#include virtual="/logging_config.js" --></script>
135 135
     <script src="libs/lib-jitsi-meet.min.js?v=139"></script>

+ 10
- 0
webpack.config.js View File

@@ -174,6 +174,16 @@ const configs = [
174 174
         })
175 175
     }),
176 176
 
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
+
177 187
     // The Webpack configuration to bundle external_api.js (aka
178 188
     // JitsiMeetExternalAPI).
179 189
     Object.assign({}, config, {

Loading…
Cancel
Save