Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion assets/js/phoenix/socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import Timer from "./timer"
*
* Defaults `DEFAULT_TIMEOUT`
* @param {number} [opts.heartbeatIntervalMs] - The millisec interval to send a heartbeat message
* @param {number} [opts.heartbeatTimeoutMs] - The default timeout in milliseconds to trigger heartbeat timeouts
* @param {Function} [opts.reconnectAfterMs] - The optional function that returns the
* socket reconnect interval, in milliseconds.
*
Expand Down Expand Up @@ -148,6 +149,7 @@ export default class Socket {
})
}
this.heartbeatIntervalMs = opts.heartbeatIntervalMs || 30000
this.heartbeatTimeoutMs = opts.heartbeatTimeoutMs || this.heartbeatIntervalMs
this.rejoinAfterMs = (tries) => {
if(opts.rejoinAfterMs){
return opts.rejoinAfterMs(tries)
Expand Down Expand Up @@ -600,11 +602,14 @@ export default class Socket {
return this.ref.toString()
}

/**
* Send heat beat message. If the response timeout, Attempting to re-establish connection
*/
sendHeartbeat(){
if(this.pendingHeartbeatRef && !this.isConnected()){ return }
this.pendingHeartbeatRef = this.makeRef()
this.push({topic: "phoenix", event: "heartbeat", payload: {}, ref: this.pendingHeartbeatRef})
this.heartbeatTimeoutTimer = setTimeout(() => this.heartbeatTimeout(), this.heartbeatIntervalMs)
this.heartbeatTimeoutTimer = setTimeout(() => this.heartbeatTimeout(), this.heartbeatTimeoutMs)
}

flushSendBuffer(){
Expand Down