From c0bbe7be0e39ee37642562a1a351fcdc5ac88402 Mon Sep 17 00:00:00 2001 From: Charlie Edwards III Date: Thu, 28 Jan 2021 12:39:52 -0500 Subject: [PATCH] added call to onCompletedCallback in WSSource --- src/websocket.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/websocket.js b/src/websocket.js index 576ea8a3..074359bf 100644 --- a/src/websocket.js +++ b/src/websocket.js @@ -21,7 +21,7 @@ var WSSource = function(url, options) { this.reconnectTimeoutId = 0; this.onEstablishedCallback = options.onSourceEstablished; - this.onCompletedCallback = options.onSourceCompleted; // Never used + this.onCompletedCallback = options.onSourceCompleted; }; WSSource.prototype.connect = function(destination) { @@ -38,7 +38,7 @@ WSSource.prototype.start = function() { this.shouldAttemptReconnect = !!this.reconnectInterval; this.progress = 0; this.established = false; - + this.socket = new WebSocket(this.url, this.options.protocols || null); this.socket.binaryType = 'arraybuffer'; this.socket.onmessage = this.onMessage.bind(this); @@ -59,9 +59,12 @@ WSSource.prototype.onClose = function() { if (this.shouldAttemptReconnect) { clearTimeout(this.reconnectTimeoutId); this.reconnectTimeoutId = setTimeout(function(){ - this.start(); + this.start(); }.bind(this), this.reconnectInterval*1000); } + if (this.onCompletedCallback) { + this.onCompletedCallback(this); + } }; WSSource.prototype.onMessage = function(ev) { @@ -80,4 +83,3 @@ WSSource.prototype.onMessage = function(ev) { return WSSource; })(); -