Use current location if URL not provided (for browsers).

This commit is contained in:
Julien Fontanet 2015-02-10 18:21:07 +01:00
parent 0b4f808b2d
commit 1e1e079b65

View File

@ -92,6 +92,18 @@ exports.fixUrl = fixUrl;
//==================================================================== //====================================================================
function getCurrentUrl() {
/* global window: false */
if (typeof window === undefined) {
throw new Error('cannot get current URL');
}
return window.location.host + window.location.pathname;
}
//====================================================================
var ConnectionLost = makeError('ConnectionLost'); var ConnectionLost = makeError('ConnectionLost');
// Low level interface to XO. // Low level interface to XO.
@ -100,7 +112,7 @@ function Api(url) {
EventEmitter.call(this); EventEmitter.call(this);
// Fix the URL (ensure correct protocol and /api/ path). // Fix the URL (ensure correct protocol and /api/ path).
this._url = fixUrl(url); this._url = fixUrl(url || getCurrentUrl());
// Will contains the WebSocket. // Will contains the WebSocket.
this._socket = null; this._socket = null;