repo: janusweb
action: commit
revision: 
path_from: 
revision_from: 0f48d649b5f88f0570bdc18964bf463ee1fe28a2:
path_to: 
revision_to: 
git.thebackupbox.net
janusweb
git clone git://git.thebackupbox.net/janusweb
commit 0f48d649b5f88f0570bdc18964bf463ee1fe28a2
Author: James Baicoianu 
Date:   Mon May 9 02:29:23 2016 -0700

    Queue messages that are sent when client is still in connecting state

diff --git a/scripts/external/JanusClientConnection.js b/scripts/external/JanusClientConnection.js
index 8a04c427c31d4cae8802245ef806d8bdcb0788af..
index ..0f5d37189f0cc8c43e658f71b2c60dfd866c39e0 100644
--- a/scripts/external/JanusClientConnection.js
+++ b/scripts/external/JanusClientConnection.js
@@ -304,9 +304,12 @@ var JanusClientConnection = function(opts)
   this._roomUrl = opts.roomUrl;
   this._version = opts.version;
   this._websocket = new WebSocket(opts.host, 'binary');
+  this.msgQueue = [];
   this._websocket.onopen = function() {
     this.sendLogon();
-    this.subscribe(this._roomUrl);
+    while (this.msgQueue.length > 0) {
+      this.send(this.msgQueue.shift());
+    }
     this.dispatchEvent({type: 'connect'});
   }.bind(this)
   this._websocket.onmessage = this.onMessage.bind(this)  
@@ -327,7 +330,11 @@ JanusClientConnection.prototype.sendLogon = function() {
 };

 JanusClientConnection.prototype.send = function(msg) {
-  this._websocket.send(JSON.stringify(msg) + '\r\n');
+  if (this._websocket.readyState == 0) {
+    this.msgQueue.push(msg);
+  } else if (this._websocket.readyState == 1) {
+    this._websocket.send(JSON.stringify(msg) + '\r\n');
+  }
 };

 JanusClientConnection.prototype.onMessage = function(msg) {

-----END OF PAGE-----