mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-21 04:35:49 +00:00
JS: Fix server requests to use self.
This commit is contained in:
committed by
Stefan Thomas
parent
79338621f9
commit
957513c14c
@@ -152,30 +152,35 @@ Server.prototype.disconnect = function ()
|
|||||||
*/
|
*/
|
||||||
Server.prototype.request = function (request)
|
Server.prototype.request = function (request)
|
||||||
{
|
{
|
||||||
// Only bother if we are still connected.
|
var self = this;
|
||||||
if (this._ws) {
|
|
||||||
request.message.id = this._id;
|
|
||||||
|
|
||||||
this._requests[request.message.id] = request;
|
// Only bother if we are still connected.
|
||||||
|
if (self._ws) {
|
||||||
|
request.message.id = self._id;
|
||||||
|
|
||||||
|
self._requests[request.message.id] = request;
|
||||||
|
|
||||||
// Advance message ID
|
// Advance message ID
|
||||||
this._id++;
|
self._id++;
|
||||||
|
|
||||||
if (this._state === "online" ||
|
if (self._state === "online" ||
|
||||||
(request.message.command === "subscribe" && this._ws.readyState === 1)) {
|
(request.message.command === "subscribe" && self._ws.readyState === 1)) {
|
||||||
if (this._remote.trace) {
|
if (self._remote.trace) {
|
||||||
utils.logObject("server: request: %s", request.message);
|
utils.logObject("server: request: %s", request.message);
|
||||||
}
|
}
|
||||||
|
|
||||||
this._ws.send(JSON.stringify(request.message));
|
self._ws.send(JSON.stringify(request.message));
|
||||||
} else {
|
} else {
|
||||||
// XXX There are many ways to make this smarter.
|
// XXX There are many ways to make self smarter.
|
||||||
this.once('connect', function () {
|
self.once('connect', function () {
|
||||||
this._ws.send(JSON.stringify(request.message));
|
if (self._remote.trace) {
|
||||||
|
utils.logObject("server: request: %s", request.message);
|
||||||
|
}
|
||||||
|
self._ws.send(JSON.stringify(request.message));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (this._remote.trace) {
|
if (self._remote.trace) {
|
||||||
utils.logObject("server: request: DROPPING: %s", request.message);
|
utils.logObject("server: request: DROPPING: %s", request.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -241,3 +246,5 @@ Server.prototype._handle_response_subscribe = function (message)
|
|||||||
};
|
};
|
||||||
|
|
||||||
exports.Server = Server;
|
exports.Server = Server;
|
||||||
|
|
||||||
|
// vim:sw=2:sts=2:ts=8:et
|
||||||
|
|||||||
Reference in New Issue
Block a user