Browse Source

Implements server side connection establishment

master
hristoterezov 8 years ago
parent
commit
bf9c4ea444

+ 3
- 2
Makefile View File

@@ -31,8 +31,9 @@ deploy-appbundle:
31 31
 
32 32
 deploy-lib-jitsi-meet:
33 33
 	cp $(LIBJITSIMEET_DIR)/lib-jitsi-meet.min.js \
34
-	$(LIBJITSIMEET_DIR)/lib-jitsi-meet.min.map $(DEPLOY_DIR)
35
-
34
+	$(LIBJITSIMEET_DIR)/lib-jitsi-meet.min.map \
35
+	$(LIBJITSIMEET_DIR)/connection_optimization/external_connect.js \
36
+	$(DEPLOY_DIR)
36 37
 deploy-css:
37 38
 	(cd css; cat $(CSS_FILES)) | $(CLEANCSS) > css/all.css
38 39
 

+ 22
- 28
app.js View File

@@ -1,4 +1,4 @@
1
-/* global $, JitsiMeetJS, config */
1
+/* global $, JitsiMeetJS, config, getRoomName */
2 2
 /* application specific logic */
3 3
 
4 4
 import "babel-polyfill";
@@ -23,40 +23,34 @@ import API from './modules/API/API';
23 23
 
24 24
 import UIEvents from './service/UI/UIEvents';
25 25
 
26
-
26
+/**
27
+ * Builds and returns the room name.
28
+ */
27 29
 function buildRoomName () {
28
-    let path = window.location.pathname;
29
-    let roomName;
30
-
31
-    // determinde the room node from the url
32
-    // TODO: just the roomnode or the whole bare jid?
33
-    if (config.getroomnode && typeof config.getroomnode === 'function') {
34
-        // custom function might be responsible for doing the pushstate
35
-        roomName = config.getroomnode(path);
36
-    } else {
37
-        /* fall back to default strategy
38
-         * this is making assumptions about how the URL->room mapping happens.
39
-         * It currently assumes deployment at root, with a rewrite like the
40
-         * following one (for nginx):
41
-         location ~ ^/([a-zA-Z0-9]+)$ {
42
-         rewrite ^/(.*)$ / break;
43
-         }
44
-        */
45
-        if (path.length > 1) {
46
-            roomName = path.substr(1).toLowerCase();
47
-        } else {
48
-            let word = RoomnameGenerator.generateRoomWithoutSeparator();
49
-            roomName = word.toLowerCase();
50
-            window.history.pushState(
51
-                'VideoChat', `Room: ${word}`, window.location.pathname + word
52
-            );
53
-        }
30
+    let roomName = getRoomName();
31
+
32
+    if(!roomName) {
33
+        let word = RoomnameGenerator.generateRoomWithoutSeparator();
34
+        roomName = word.toLowerCase();
35
+        window.history.pushState(
36
+            'VideoChat', `Room: ${word}`, window.location.pathname + word
37
+        );
54 38
     }
55 39
 
56 40
     return roomName;
57 41
 }
58 42
 
59 43
 const APP = {
44
+    // Used by do_external_connect.js if we receive the attach data after
45
+    // connect was already executed. status property can be "initialized",
46
+    // "ready" or "connecting". We are interested in "ready" status only which
47
+    // means that connect was executed but we have to wait for the attach data.
48
+    // In status "ready" handler property will be set to a function that will
49
+    // finish the connect process when the attach data or error is received.
50
+    connect: {
51
+        status: "initialized",
52
+        handler: null
53
+    },
60 54
     UI,
61 55
     settings,
62 56
     conference,

+ 36
- 2
connection.js View File

@@ -5,6 +5,39 @@ import LoginDialog from './modules/UI/authentication/LoginDialog';
5 5
 const ConnectionEvents = JitsiMeetJS.events.connection;
6 6
 const ConnectionErrors = JitsiMeetJS.errors.connection;
7 7
 
8
+/**
9
+ * Checks if we have data to use attach instead of connect. If we have the data
10
+ * executes attach otherwise check if we have to wait for the data. If we have
11
+ * to wait for the attach data we are setting handler to APP.connect.handler
12
+ * which is going to be called when the attach data is received otherwise
13
+ * executes connect.
14
+ *
15
+ * @param {string} [id] user id
16
+ * @param {string} [password] password
17
+ * @param {string} [roomName] the name of the conference.
18
+ */
19
+function checkForAttachParametersAndConnect(id, password, connection) {
20
+    console.log("call checkForAttachParametersAndConnect");
21
+    if(window.XMPPAttachInfo){
22
+        APP.connect.status = "connecting";
23
+        if(window.XMPPAttachInfo.status === "error") {
24
+            connection.connect({id, password});
25
+            return;
26
+        }
27
+
28
+        var attachOptions = window.XMPPAttachInfo.data;
29
+        if(attachOptions) {
30
+            connection.attach(attachOptions);
31
+        } else {
32
+            connection.connect({id, password});
33
+        }
34
+    } else {
35
+        APP.connect.status = "ready";
36
+        APP.connect.handler = checkForAttachParametersAndConnect.bind(null,
37
+            id, password, connection);
38
+    }
39
+}
40
+
8 41
 /**
9 42
  * Try to open connection using provided credentials.
10 43
  * @param {string} [id]
@@ -18,7 +51,8 @@ function connect(id, password, roomName) {
18 51
     let connectionConfig = config;
19 52
 
20 53
     connectionConfig.bosh += '?room=' + roomName;
21
-    let connection = new JitsiMeetJS.JitsiConnection(null, null, config);
54
+    let connection
55
+        = new JitsiMeetJS.JitsiConnection(null, config.token, config);
22 56
 
23 57
     return new Promise(function (resolve, reject) {
24 58
         connection.addEventListener(
@@ -50,7 +84,7 @@ function connect(id, password, roomName) {
50 84
             reject(err);
51 85
         }
52 86
 
53
-        connection.connect({id, password});
87
+        checkForAttachParametersAndConnect(id, password, connection);
54 88
     });
55 89
 }
56 90
 

+ 0
- 0
connection_optimization/connection_optimization.html View File


+ 79
- 0
connection_optimization/do_external_connect.js View File

@@ -0,0 +1,79 @@
1
+/* global config, getRoomName, getConfigParamsFromUrl */
2
+/* global createConnectionExternally */
3
+/**
4
+ * Implements extrnal connect using createConnectionExtenally function defined
5
+ * in external_connect.js for Jitsi Meet. Parses the room name and token from
6
+ * the url and executes createConnectionExtenally.
7
+ *
8
+ * 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.
10
+ *
11
+ * NOTE: For optimal results this file should be included right after
12
+ * exrnal_connect.js.
13
+ */
14
+
15
+
16
+
17
+ /**
18
+  * Gets the token from the URL.
19
+  */
20
+function buildToken(){
21
+    var params = getConfigParamsFromUrl();
22
+    return params["config.token"] || config.token;
23
+}
24
+
25
+/**
26
+ * Executes createConnectionExternally function.
27
+ */
28
+(function () {
29
+    // FIXME: Add implementation for changing that config from the url for
30
+    // consistency
31
+    var url = config.externalConnectUrl;
32
+
33
+    /**
34
+     * Check if connect from connection.js was executed and executes the handler
35
+     * that is going to finish the connect work.
36
+     */
37
+    function checkForConnectHandlerAndConnect() {
38
+
39
+        if(window.APP && window.APP.connect.status === "ready") {
40
+            window.APP.connect.handler();
41
+        }
42
+    }
43
+
44
+    function error_callback(error){
45
+        console.warn(error);
46
+        // Sets that global variable to be used later by connect method in
47
+        // connection.js
48
+        window.XMPPAttachInfo = {
49
+            status: "error"
50
+        };
51
+        checkForConnectHandlerAndConnect();
52
+    }
53
+
54
+    if(!url || !window.createConnectionExternally) {
55
+        error_callback();
56
+        return;
57
+    }
58
+    var room_name = getRoomName();
59
+    if(!room_name) {
60
+        error_callback();
61
+        return;
62
+    }
63
+
64
+    url += "?room=" + room_name;
65
+
66
+    var token = buildToken();
67
+    if(token)
68
+        url += "&token=" + token;
69
+
70
+    createConnectionExternally(url, function(connectionInfo) {
71
+        // Sets that global variable to be used later by connect method in
72
+        // connection.js
73
+        window.XMPPAttachInfo = {
74
+            status: "success",
75
+            data: connectionInfo
76
+        };
77
+        checkForConnectHandlerAndConnect();
78
+    }, error_callback);
79
+})();

+ 8
- 6
index.html View File

@@ -1,6 +1,13 @@
1 1
 <html itemscope itemtype="http://schema.org/Product" prefix="og: http://ogp.me/ns#" xmlns="http://www.w3.org/1999/html">
2 2
   <head>
3 3
     <!--#include virtual="title.html" -->
4
+    <script>console.log("(TIME) index.html loaded:\t", window.performance.now());</script>
5
+    <script src="config.js?v=15"></script><!-- adapt to your needs, i.e. set hosts and bosh path -->
6
+    <script src="utils.js?v=1"></script>
7
+    <!--#include virtual="connection_optimization/connection_optimization.html" -->
8
+    <script src="interface_config.js?v=6"></script>
9
+    <script src="libs/lib-jitsi-meet.min.js?v=139"></script>
10
+    <script src="libs/app.bundle.min.js?v=139"></script>
4 11
     <link rel="icon" type="image/png" href="/images/favicon.ico?v=1"/>
5 12
     <meta property="og:title" content="Jitsi Meet"/>
6 13
     <meta property="og:image" content="/images/jitsilogo.png?v=1"/>
@@ -9,12 +16,7 @@
9 16
     <meta itemprop="name" content="Jitsi Meet"/>
10 17
     <meta itemprop="description" content="Join a WebRTC video conference powered by the Jitsi Videobridge"/>
11 18
     <meta itemprop="image" content="/images/jitsilogo.png?v=1"/>
12
-      <link rel="stylesheet" href="css/all.css"/>
13
-    <script>console.log("(TIME) index.html loaded:\t", window.performance.now());</script>
14
-    <script src="config.js?v=15"></script><!-- adapt to your needs, i.e. set hosts and bosh path -->
15
-    <script src="interface_config.js?v=6"></script>
16
-    <script src="libs/lib-jitsi-meet.min.js?v=139"></script>
17
-    <script src="libs/app.bundle.min.js?v=139"></script>
19
+    <link rel="stylesheet" href="css/all.css"/>
18 20
     <!--#include virtual="plugin.head.html" -->
19 21
   </head>
20 22
   <body>

+ 2
- 14
modules/config/URLProcessor.js View File

@@ -1,18 +1,6 @@
1
-/* global $, $iq, config, interfaceConfig */
1
+/* global $, $iq, config, interfaceConfig, getConfigParamsFromUrl */
2 2
 var configUtils = require('./Util');
3 3
 var params = {};
4
-function getConfigParamsFromUrl() {
5
-    if (!location.hash)
6
-        return {};
7
-    var hash = location.hash.substr(1);
8
-    var result = {};
9
-    hash.split("&").forEach(function (part) {
10
-        var item = part.split("=");
11
-        result[item[0]] = JSON.parse(
12
-            decodeURIComponent(item[1]).replace(/\\&/, "&"));
13
-    });
14
-    return result;
15
-}
16 4
 
17 5
 params = getConfigParamsFromUrl();
18 6
 
@@ -62,4 +50,4 @@ var URLProcessor = {
62 50
     }
63 51
 };
64 52
 
65
-module.exports = URLProcessor;
53
+module.exports = URLProcessor;

+ 52
- 0
utils.js View File

@@ -0,0 +1,52 @@
1
+/* global config */
2
+
3
+/**
4
+ * Defines some utility methods that are used before the other JS files are
5
+ * loaded.
6
+ */
7
+
8
+
9
+/**
10
+ * Builds and returns the room name.
11
+ */
12
+function getRoomName () {
13
+    var path = window.location.pathname;
14
+    var roomName;
15
+
16
+    // determinde the room node from the url
17
+    // TODO: just the roomnode or the whole bare jid?
18
+    if (config.getroomnode && typeof config.getroomnode === 'function') {
19
+        // custom function might be responsible for doing the pushstate
20
+        roomName = config.getroomnode(path);
21
+    } else {
22
+        /* fall back to default strategy
23
+         * this is making assumptions about how the URL->room mapping happens.
24
+         * It currently assumes deployment at root, with a rewrite like the
25
+         * following one (for nginx):
26
+         location ~ ^/([a-zA-Z0-9]+)$ {
27
+         rewrite ^/(.*)$ / break;
28
+         }
29
+        */
30
+        if (path.length > 1) {
31
+            roomName = path.substr(1).toLowerCase();
32
+        }
33
+    }
34
+
35
+    return roomName;
36
+}
37
+
38
+/**
39
+ * Parses the hash parameters from the URL and returns them as a JS object.
40
+ */
41
+function getConfigParamsFromUrl() {
42
+    if (!location.hash)
43
+        return {};
44
+    var hash = location.hash.substr(1);
45
+    var result = {};
46
+    hash.split("&").forEach(function (part) {
47
+        var item = part.split("=");
48
+        result[item[0]] = JSON.parse(
49
+            decodeURIComponent(item[1]).replace(/\\&/, "&"));
50
+    });
51
+    return result;
52
+}

Loading…
Cancel
Save