app.js (goaccess-1.7.1) | : | app.js (goaccess-1.7.2) | ||
---|---|---|---|---|
skipping to change at line 102 | skipping to change at line 102 | |||
reconnect: function (wsConn) { | reconnect: function (wsConn) { | |||
if (this.retries >= this.maxRetries) | if (this.retries >= this.maxRetries) | |||
return window.clearTimeout(this.wsTimer); | return window.clearTimeout(this.wsTimer); | |||
this.retries++; | this.retries++; | |||
if (this.currDelay < this.maxDelay) | if (this.currDelay < this.maxDelay) | |||
this.currDelay *= 2; // Exponential backoff | this.currDelay *= 2; // Exponential backoff | |||
this.setWebSocket(wsConn); | this.setWebSocket(wsConn); | |||
}, | }, | |||
buildWSURI: function (wsConn) { | ||||
var url = null; | ||||
if (!wsConn.url || !wsConn.port) | ||||
return null; | ||||
url = /^wss?:\/\//i.test(wsConn.url) ? wsConn.url : window.locati | ||||
on.protocol === "https:" ? 'wss://' + wsConn.url : 'ws://' + wsConn.url; | ||||
return new URL(url).protocol + '//' + new URL(url).hostname + ':' | ||||
+ wsConn.port + new URL(url).pathname; | ||||
}, | ||||
setWebSocket: function (wsConn) { | setWebSocket: function (wsConn) { | |||
var host = null, pingId = null; | var host = null, pingId = null, uri = null, defURI = null, str = | |||
host = wsConn.url ? wsConn.url : window.location.hostname ? windo | null; | |||
w.location.hostname : "localhost"; | ||||
var str = /^(wss?:\/\/)?[^\/]+:[0-9]{1,5}\//.test(host + "/") ? h | defURI = window.location.hostname ? window.location.hostname + ': | |||
ost : String(host + ':' + wsConn.port); | ' + wsConn.port : "localhost" + ':' + wsConn.port; | |||
uri = wsConn.url && /^(wss?:\/\/)?[^\/]+:[0-9]{1,5}/.test(wsConn. | ||||
url) ? wsConn.url : this.buildWSURI(wsConn); | ||||
str = uri || defURI; | ||||
str = !/^wss?:\/\//i.test(str) ? (window.location.protocol === "h ttps:" ? 'wss://' : 'ws://') + str : str; | str = !/^wss?:\/\//i.test(str) ? (window.location.protocol === "h ttps:" ? 'wss://' : 'ws://') + str : str; | |||
var socket = new WebSocket(str); | var socket = new WebSocket(str); | |||
socket.onopen = function (event) { | socket.onopen = function (event) { | |||
this.currDelay = this.wsDelay; | this.currDelay = this.wsDelay; | |||
this.retries = 0; | this.retries = 0; | |||
// attempt to keep connection alive (e.g., ping/pong) | // attempt to keep connection alive (e.g., ping/pong) | |||
if (wsConn.ping_interval) | if (wsConn.ping_interval) | |||
pingId = setInterval(() => { socket.send('ping'); }, wsConn.ping_interval * 1E3); | pingId = setInterval(() => { socket.send('ping'); }, wsConn.ping_interval * 1E3); | |||
End of changes. 2 change blocks. | ||||
5 lines changed or deleted | 19 lines changed or added |