cryptpad/www/common/outer/network-config.js

25 lines
656 B
JavaScript
Raw Normal View History

2017-11-23 11:28:49 +00:00
define([
'/api/config'
], function (ApiConfig) {
var Config = {};
2019-12-17 09:57:13 +00:00
Config.getWebsocketURL = function (origin) {
2017-11-23 11:28:49 +00:00
if (!ApiConfig.websocketPath) { return ApiConfig.websocketURL; }
var path = ApiConfig.websocketPath;
if (/^ws{1,2}:\/\//.test(path)) { return path; }
2019-12-17 09:57:13 +00:00
var l = window.location;
if (origin && window && window.document) {
var l = document.createElement("a");
l.href = origin;
}
var protocol = l.protocol.replace(/http/, 'ws');
var host = l.host;
2017-11-23 11:28:49 +00:00
var url = protocol + '//' + host + path;
return url;
};
return Config;
});