diff --git a/src/connector.js b/src/connector.js index c311fe1..1b6c554 100644 --- a/src/connector.js +++ b/src/connector.js @@ -10,7 +10,16 @@ class Connector { this.handlers = handlers; const path = this.options.path ? `${this.options.path}` : 'livereload'; const port = this.options.port ? `:${this.options.port}` : ''; - this._uri = `ws${this.options.https ? 's' : ''}://${this.options.host}${port}/${path}`; + let host; + if (typeof window !== 'undefined') { + host = this.options.host || window.location.hostname; + } else { + host = this.options.host; + } + if (host && host.includes(':') && !host.startsWith('[')) { + host = `[${host}]`; + } + this._uri = `ws${this.options.https ? 's' : ''}://${host}${port}/${path}`; this._nextDelay = this.options.mindelay; this._connectionDesired = false;