mirror of https://github.com/jitsi/jitsi-meet
parent
0bde7de37b
commit
bf9c4ea444
@ -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); |
||||
})(); |
@ -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; |
||||
} |
Loading…
Reference in new issue