forked from jitsi/jitsi-meet
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implements server side connection establishment
- Loading branch information
1 parent
0bde7de
commit bf9c4ea
Showing
8 changed files
with
202 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* global config, getRoomName, getConfigParamsFromUrl */ | ||
/* global createConnectionExternally */ | ||
/** | ||
* Implements extrnal connect using createConnectionExtenally function defined | ||
* in external_connect.js for Jitsi Meet. Parses the room name and token from | ||
* the url and executes createConnectionExtenally. | ||
* | ||
* 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 | ||
* exrnal_connect.js. | ||
*/ | ||
|
||
|
||
|
||
/** | ||
* Gets the token from the URL. | ||
*/ | ||
function buildToken(){ | ||
var params = getConfigParamsFromUrl(); | ||
return params["config.token"] || config.token; | ||
} | ||
|
||
/** | ||
* Executes createConnectionExternally function. | ||
*/ | ||
(function () { | ||
// FIXME: Add implementation for changing that config from the url for | ||
// consistency | ||
var url = config.externalConnectUrl; | ||
|
||
/** | ||
* Check if connect from connection.js was executed and executes the handler | ||
* that is going to finish the connect work. | ||
*/ | ||
function checkForConnectHandlerAndConnect() { | ||
|
||
if(window.APP && window.APP.connect.status === "ready") { | ||
window.APP.connect.handler(); | ||
} | ||
} | ||
|
||
function error_callback(error){ | ||
console.warn(error); | ||
// Sets that global variable to be used later by connect method in | ||
// connection.js | ||
window.XMPPAttachInfo = { | ||
status: "error" | ||
}; | ||
checkForConnectHandlerAndConnect(); | ||
} | ||
|
||
if(!url || !window.createConnectionExternally) { | ||
error_callback(); | ||
return; | ||
} | ||
var room_name = getRoomName(); | ||
if(!room_name) { | ||
error_callback(); | ||
return; | ||
} | ||
|
||
url += "?room=" + room_name; | ||
|
||
var token = buildToken(); | ||
if(token) | ||
url += "&token=" + token; | ||
|
||
createConnectionExternally(url, function(connectionInfo) { | ||
// Sets that global variable to be used later by connect method in | ||
// connection.js | ||
window.XMPPAttachInfo = { | ||
status: "success", | ||
data: connectionInfo | ||
}; | ||
checkForConnectHandlerAndConnect(); | ||
}, error_callback); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* global config */ | ||
|
||
/** | ||
* Defines some utility methods that are used before the other JS files are | ||
* loaded. | ||
*/ | ||
|
||
|
||
/** | ||
* Builds and returns the room name. | ||
*/ | ||
function getRoomName () { | ||
var path = window.location.pathname; | ||
var roomName; | ||
|
||
// determinde the room node from the url | ||
// TODO: just the roomnode or the whole bare jid? | ||
if (config.getroomnode && typeof config.getroomnode === 'function') { | ||
// custom function might be responsible for doing the pushstate | ||
roomName = config.getroomnode(path); | ||
} else { | ||
/* fall back to default strategy | ||
* this is making assumptions about how the URL->room mapping happens. | ||
* It currently assumes deployment at root, with a rewrite like the | ||
* following one (for nginx): | ||
location ~ ^/([a-zA-Z0-9]+)$ { | ||
rewrite ^/(.*)$ / break; | ||
} | ||
*/ | ||
if (path.length > 1) { | ||
roomName = path.substr(1).toLowerCase(); | ||
} | ||
} | ||
|
||
return roomName; | ||
} | ||
|
||
/** | ||
* Parses the hash parameters from the URL and returns them as a JS object. | ||
*/ | ||
function getConfigParamsFromUrl() { | ||
if (!location.hash) | ||
return {}; | ||
var hash = location.hash.substr(1); | ||
var result = {}; | ||
hash.split("&").forEach(function (part) { | ||
var item = part.split("="); | ||
result[item[0]] = JSON.parse( | ||
decodeURIComponent(item[1]).replace(/\\&/, "&")); | ||
}); | ||
return result; | ||
} |