Skip to content

Commit

Permalink
Release 1.6.15
Browse files Browse the repository at this point in the history
  • Loading branch information
chrismccord committed Oct 26, 2022
1 parent eaa2378 commit bd275cf
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 37 deletions.
27 changes: 17 additions & 10 deletions assets/js/phoenix/socket.js
Expand Up @@ -46,7 +46,7 @@ import Timer from "./timer"
*
* Defaults `DEFAULT_TIMEOUT`
* @param {number} [opts.heartbeatIntervalMs] - The millisec interval to send a heartbeat message
* @param {number} [opts.reconnectAfterMs] - The optional function that returns the millsec
* @param {number} [opts.reconnectAfterMs] - The optional function that returns the millisec
* socket reconnect interval.
*
* Defaults to stepped backoff of:
Expand All @@ -57,7 +57,7 @@ import Timer from "./timer"
* }
* ````
*
* @param {number} [opts.rejoinAfterMs] - The optional function that returns the millsec
* @param {number} [opts.rejoinAfterMs] - The optional function that returns the millisec
* rejoin interval for individual channels.
*
* ```javascript
Expand Down Expand Up @@ -143,6 +143,7 @@ export default class Socket {
this.params = closure(opts.params || {})
this.endPoint = `${endPoint}/${TRANSPORTS.websocket}`
this.vsn = opts.vsn || DEFAULT_VSN
this.heartbeatTimeoutTimer = null
this.heartbeatTimer = null
this.pendingHeartbeatRef = null
this.reconnectTimer = new Timer(() => {
Expand Down Expand Up @@ -181,7 +182,7 @@ export default class Socket {
protocol(){ return location.protocol.match(/^https/) ? "wss" : "ws" }

/**
* The fully qualifed socket url
* The fully qualified socket url
*
* @returns {string}
*/
Expand Down Expand Up @@ -317,6 +318,12 @@ export default class Socket {
/**
* @private
*/

clearHeartbeats(){
clearTimeout(this.heartbeatTimer)
clearTimeout(this.heartbeatTimeoutTimer)
}

onConnOpen(){
if(this.hasLogger()) this.log("transport", `connected to ${this.endPointURL()}`)
this.closeWasClean = false
Expand Down Expand Up @@ -344,8 +351,8 @@ export default class Socket {
resetHeartbeat(){
if(this.conn && this.conn.skipHeartbeat){ return }
this.pendingHeartbeatRef = null
clearTimeout(this.heartbeatTimer)
setTimeout(() => this.sendHeartbeat(), this.heartbeatIntervalMs)
this.clearHeartbeats()
this.heartbeatTimer = setTimeout(() => this.sendHeartbeat(), this.heartbeatIntervalMs)
}

teardown(callback, code, reason){
Expand Down Expand Up @@ -398,7 +405,7 @@ export default class Socket {
let closeCode = event && event.code
if(this.hasLogger()) this.log("transport", "close", event)
this.triggerChanError()
clearTimeout(this.heartbeatTimer)
this.clearHeartbeats()
if(!this.closeWasClean && closeCode !== 1000){
this.reconnectTimer.scheduleTimeout()
}
Expand Down Expand Up @@ -516,7 +523,7 @@ export default class Socket {
if(this.pendingHeartbeatRef && !this.isConnected()){ return }
this.pendingHeartbeatRef = this.makeRef()
this.push({topic: "phoenix", event: "heartbeat", payload: {}, ref: this.pendingHeartbeatRef})
this.heartbeatTimer = setTimeout(() => this.heartbeatTimeout(), this.heartbeatIntervalMs)
this.heartbeatTimeoutTimer = setTimeout(() => this.heartbeatTimeout(), this.heartbeatIntervalMs)
}

flushSendBuffer(){
Expand All @@ -530,9 +537,9 @@ export default class Socket {
this.decode(rawMessage.data, msg => {
let {topic, event, payload, ref, join_ref} = msg
if(ref && ref === this.pendingHeartbeatRef){
clearTimeout(this.heartbeatTimer)
this.clearHeartbeats()
this.pendingHeartbeatRef = null
setTimeout(() => this.sendHeartbeat(), this.heartbeatIntervalMs)
this.heartbeatTimer = setTimeout(() => this.sendHeartbeat(), this.heartbeatIntervalMs)
}

if(this.hasLogger()) this.log("receive", `${payload.status || ""} ${topic} ${event} ${ref && "(" + ref + ")" || ""}`, payload)
Expand All @@ -557,4 +564,4 @@ export default class Socket {
dupChannel.leave()
}
}
}
}
5 changes: 1 addition & 4 deletions assets/test/socket_test.js
Expand Up @@ -691,8 +691,6 @@ describe("with transports", function(){

assert.ok(!spy.calledWith("phx_error"))
})
<<<<<<< HEAD
=======

it("does not send heartbeat after explicit disconnect", function(done){
let clock = sinon.useFakeTimers()
Expand All @@ -716,7 +714,6 @@ describe("with transports", function(){
clock.restore()
done()
})
>>>>>>> 1a0e70a7 (Fix reconnecting websockets on heartbeat timeout (#4921))
})

describe("onConnError", function(){
Expand Down Expand Up @@ -972,4 +969,4 @@ describe("with transports", function(){

})
window.XMLHttpRequest = sinon.useFakeXMLHttpRequest()
window.WebSocket = WebSocket
window.WebSocket = WebSocket
17 changes: 11 additions & 6 deletions priv/static/phoenix.cjs.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions priv/static/phoenix.cjs.js.map

Large diffs are not rendered by default.

17 changes: 11 additions & 6 deletions priv/static/phoenix.js
Expand Up @@ -843,6 +843,7 @@ var Phoenix = (() => {
this.params = closure(opts.params || {});
this.endPoint = `${endPoint}/${TRANSPORTS.websocket}`;
this.vsn = opts.vsn || DEFAULT_VSN;
this.heartbeatTimeoutTimer = null;
this.heartbeatTimer = null;
this.pendingHeartbeatRef = null;
this.reconnectTimer = new Timer(() => {
Expand Down Expand Up @@ -941,6 +942,10 @@ var Phoenix = (() => {
});
return true;
}
clearHeartbeats() {
clearTimeout(this.heartbeatTimer);
clearTimeout(this.heartbeatTimeoutTimer);
}
onConnOpen() {
if (this.hasLogger())
this.log("transport", `connected to ${this.endPointURL()}`);
Expand All @@ -967,8 +972,8 @@ var Phoenix = (() => {
return;
}
this.pendingHeartbeatRef = null;
clearTimeout(this.heartbeatTimer);
setTimeout(() => this.sendHeartbeat(), this.heartbeatIntervalMs);
this.clearHeartbeats();
this.heartbeatTimer = setTimeout(() => this.sendHeartbeat(), this.heartbeatIntervalMs);
}
teardown(callback, code, reason) {
if (!this.conn) {
Expand Down Expand Up @@ -1021,7 +1026,7 @@ var Phoenix = (() => {
if (this.hasLogger())
this.log("transport", "close", event);
this.triggerChanError();
clearTimeout(this.heartbeatTimer);
this.clearHeartbeats();
if (!this.closeWasClean && closeCode !== 1e3) {
this.reconnectTimer.scheduleTimeout();
}
Expand Down Expand Up @@ -1103,7 +1108,7 @@ var Phoenix = (() => {
}
this.pendingHeartbeatRef = this.makeRef();
this.push({ topic: "phoenix", event: "heartbeat", payload: {}, ref: this.pendingHeartbeatRef });
this.heartbeatTimer = setTimeout(() => this.heartbeatTimeout(), this.heartbeatIntervalMs);
this.heartbeatTimeoutTimer = setTimeout(() => this.heartbeatTimeout(), this.heartbeatIntervalMs);
}
flushSendBuffer() {
if (this.isConnected() && this.sendBuffer.length > 0) {
Expand All @@ -1115,9 +1120,9 @@ var Phoenix = (() => {
this.decode(rawMessage.data, (msg) => {
let { topic, event, payload, ref, join_ref } = msg;
if (ref && ref === this.pendingHeartbeatRef) {
clearTimeout(this.heartbeatTimer);
this.clearHeartbeats();
this.pendingHeartbeatRef = null;
setTimeout(() => this.sendHeartbeat(), this.heartbeatIntervalMs);
this.heartbeatTimer = setTimeout(() => this.sendHeartbeat(), this.heartbeatIntervalMs);
}
if (this.hasLogger())
this.log("receive", `${payload.status || ""} ${topic} ${event} ${ref && "(" + ref + ")" || ""}`, payload);
Expand Down
2 changes: 1 addition & 1 deletion priv/static/phoenix.min.js

Large diffs are not rendered by default.

17 changes: 11 additions & 6 deletions priv/static/phoenix.mjs
Expand Up @@ -814,6 +814,7 @@ var Socket = class {
this.params = closure(opts.params || {});
this.endPoint = `${endPoint}/${TRANSPORTS.websocket}`;
this.vsn = opts.vsn || DEFAULT_VSN;
this.heartbeatTimeoutTimer = null;
this.heartbeatTimer = null;
this.pendingHeartbeatRef = null;
this.reconnectTimer = new Timer(() => {
Expand Down Expand Up @@ -912,6 +913,10 @@ var Socket = class {
});
return true;
}
clearHeartbeats() {
clearTimeout(this.heartbeatTimer);
clearTimeout(this.heartbeatTimeoutTimer);
}
onConnOpen() {
if (this.hasLogger())
this.log("transport", `connected to ${this.endPointURL()}`);
Expand All @@ -938,8 +943,8 @@ var Socket = class {
return;
}
this.pendingHeartbeatRef = null;
clearTimeout(this.heartbeatTimer);
setTimeout(() => this.sendHeartbeat(), this.heartbeatIntervalMs);
this.clearHeartbeats();
this.heartbeatTimer = setTimeout(() => this.sendHeartbeat(), this.heartbeatIntervalMs);
}
teardown(callback, code, reason) {
if (!this.conn) {
Expand Down Expand Up @@ -992,7 +997,7 @@ var Socket = class {
if (this.hasLogger())
this.log("transport", "close", event);
this.triggerChanError();
clearTimeout(this.heartbeatTimer);
this.clearHeartbeats();
if (!this.closeWasClean && closeCode !== 1e3) {
this.reconnectTimer.scheduleTimeout();
}
Expand Down Expand Up @@ -1074,7 +1079,7 @@ var Socket = class {
}
this.pendingHeartbeatRef = this.makeRef();
this.push({ topic: "phoenix", event: "heartbeat", payload: {}, ref: this.pendingHeartbeatRef });
this.heartbeatTimer = setTimeout(() => this.heartbeatTimeout(), this.heartbeatIntervalMs);
this.heartbeatTimeoutTimer = setTimeout(() => this.heartbeatTimeout(), this.heartbeatIntervalMs);
}
flushSendBuffer() {
if (this.isConnected() && this.sendBuffer.length > 0) {
Expand All @@ -1086,9 +1091,9 @@ var Socket = class {
this.decode(rawMessage.data, (msg) => {
let { topic, event, payload, ref, join_ref } = msg;
if (ref && ref === this.pendingHeartbeatRef) {
clearTimeout(this.heartbeatTimer);
this.clearHeartbeats();
this.pendingHeartbeatRef = null;
setTimeout(() => this.sendHeartbeat(), this.heartbeatIntervalMs);
this.heartbeatTimer = setTimeout(() => this.sendHeartbeat(), this.heartbeatIntervalMs);
}
if (this.hasLogger())
this.log("receive", `${payload.status || ""} ${topic} ${event} ${ref && "(" + ref + ")" || ""}`, payload);
Expand Down
4 changes: 2 additions & 2 deletions priv/static/phoenix.mjs.map

Large diffs are not rendered by default.

0 comments on commit bd275cf

Please sign in to comment.