Update stomp.js to support messages from implicit subscriptions

This commit is contained in:
Emile Joubert 2013-08-07 16:06:26 +01:00
parent 02ed60d4e8
commit c9b4ae4e8c
1 changed files with 35 additions and 9 deletions

View File

@ -1,4 +1,9 @@
// Generated by CoffeeScript 1.3.3
// Generated by CoffeeScript 1.6.3
/*
Stomp Over WebSocket http://www.jmesnil.net/stomp-websocket/doc/ | Apache License V2.0
*/
(function() {
var Byte, Client, Frame, Stomp,
__hasProp = {}.hasOwnProperty;
@ -9,7 +14,6 @@
};
Frame = (function() {
function Frame(command, headers, body) {
this.command = command;
this.headers = headers != null ? headers : {};
@ -92,7 +96,6 @@
})();
Client = (function() {
function Client(ws) {
this.ws = ws;
this.ws.binaryType = "arraybuffer";
@ -102,16 +105,32 @@
outgoing: 10000,
incoming: 10000
};
this.maxWebSocketFrameSize = 16 * 1024;
this.subscriptions = {};
}
Client.prototype.debug = function(message) {
var _ref;
return typeof window !== "undefined" && window !== null ? (_ref = window.console) != null ? _ref.log(message) : void 0 : void 0;
};
Client.prototype._transmit = function(command, headers, body) {
var out;
out = Frame.marshall(command, headers, body);
if (typeof this.debug === "function") {
this.debug(">>> " + out);
}
return this.ws.send(out);
while (true) {
if (out.length > this.maxWebSocketFrameSize) {
this.ws.send(out.substring(0, this.maxWebSocketFrameSize));
out = out.substring(this.maxWebSocketFrameSize);
if (typeof this.debug === "function") {
this.debug("remaining = " + out.length);
}
} else {
return this.ws.send(out);
}
}
};
Client.prototype._setupHeartbeat = function(headers) {
@ -152,7 +171,7 @@
if (typeof _this.debug === "function") {
_this.debug("did not receive server activity for the last " + delta + "ms");
}
return _this._cleanUp();
return _this.ws.close();
}
}, ttl) : void 0;
}
@ -199,8 +218,12 @@
_results.push(typeof _this.connectCallback === "function" ? _this.connectCallback(frame) : void 0);
break;
case "MESSAGE":
onreceive = _this.subscriptions[frame.headers.subscription];
_results.push(typeof onreceive === "function" ? onreceive(frame) : void 0);
onreceive = _this.subscriptions[frame.headers.subscription] || _this.onreceive;
if (onreceive) {
_results.push(onreceive(frame));
} else {
_results.push(typeof _this.debug === "function" ? _this.debug("Unhandled received MESSAGE: " + frame) : void 0);
}
break;
case "RECEIPT":
_results.push(typeof _this.onreceipt === "function" ? _this.onreceipt(frame) : void 0);
@ -220,6 +243,7 @@
if (typeof _this.debug === "function") {
_this.debug(msg);
}
_this._cleanUp();
return typeof errorCallback === "function" ? errorCallback(msg) : void 0;
};
return this.ws.onopen = function() {
@ -247,12 +271,12 @@
Client.prototype.disconnect = function(disconnectCallback) {
this._transmit("DISCONNECT");
this.ws.onclose = null;
this.ws.close();
this._cleanUp();
return typeof disconnectCallback === "function" ? disconnectCallback() : void 0;
};
Client.prototype._cleanUp = function() {
this.ws.close();
this.connected = false;
if (this.pinger) {
if (typeof window !== "undefined" && window !== null) {
@ -362,9 +386,11 @@
if (typeof window !== "undefined" && window !== null) {
window.Stomp = Stomp;
} else {
} else if (typeof exports !== "undefined" && exports !== null) {
exports.Stomp = Stomp;
Stomp.WebSocketClass = require('./test/server.mock.js').StompServerMock;
} else {
self.Stomp = Stomp;
}
}).call(this);