repo: janusweb action: commit revision: path_from: revision_from: 1a2edb4c515f1d2bdd43958831afbcba63ffae16: path_to: revision_to:
commit 1a2edb4c515f1d2bdd43958831afbcba63ffae16 Author: James BaicoianuDate: Fri Jul 26 14:03:39 2024 -0700 Improved server reconnect logic diff --git a/scripts/external/JanusClientConnection.js b/scripts/external/JanusClientConnection.js
--- a/scripts/external/JanusClientConnection.js
+++ b/scripts/external/JanusClientConnection.js
@@ -336,8 +336,8 @@ JanusClientConnection.prototype.connect = function() {
this._websocket.onclose = function() {
this.status = 0;
this.dispatchEvent({type: 'disconnect'});
- if (this.pendingReconnect) {
- this.connect();
+ if (!this.pendingReconnect) {
+ this.reconnect();
}
}.bind(this);
@@ -346,10 +346,10 @@ JanusClientConnection.prototype.connect = function() {
JanusClientConnection.prototype.reconnect = function(force) {
var now = new Date().getTime();
if (force || this.lastattempt + this.reconnectdelay <= now) {
+ this.pendingReconnect = true;
if (this._websocket.readyState == this._websocket.OPEN) {
console.log('Socket already connected, disconnecting');
this.disconnect();
- this.pendingReconnect = true;
} else {
console.log('Reconnecting...');
this.connect();
@@ -392,12 +392,18 @@ JanusClientConnection.prototype.setUserId = function(userId) {
};
JanusClientConnection.prototype.send = function(msg) {
- try {
- this._websocket.send(JSON.stringify(msg) + '\r\n');
- } catch (e) {
+ if (this._websocket.readyState == 3) {
this.msgQueue.push(msg);
+ if (!this.pendingReconnect) {
+ this.reconnect();
+ }
+ } else {
+ try {
+ this._websocket.send(JSON.stringify(msg) + '\r\n');
+ } catch (e) {
+ this.msgQueue.push(msg);
+ }
}
- //this.reconnect();
};
JanusClientConnection.prototype.onMessage = function(msg) {
-----END OF PAGE-----