JS: Hold requests until connection is established.

This will have to change when we add multiple server support, but it does the
trick for now.
This commit is contained in:
Stefan Thomas
2013-03-13 19:15:37 +01:00
parent b075f2623f
commit cc5c839cde

View File

@@ -161,11 +161,19 @@ Server.prototype.request = function (request)
// Advance message ID
this._id++;
if (this._remote.trace) {
utils.logObject("server: request: %s", request.message);
}
if (this._state === "online" ||
(request.message.command === "subscribe" && this._ws.readyState === 1)) {
if (this._remote.trace) {
utils.logObject("server: request: %s", request.message);
}
this._ws.send(JSON.stringify(request.message));
this._ws.send(JSON.stringify(request.message));
} else {
// XXX There are many ways to make this smarter.
this.once('connect', function () {
this._ws.send(JSON.stringify(request.message));
});
}
} else {
if (this._remote.trace) {
utils.logObject("server: request: DROPPING: %s", request.message);