Closed krtl closed 6 years ago
I figured out how to do it
@krtl Could you please share how you did it?
Unfortunately, I've done this by amending stompServer.js
2018-08-01 14:07 GMT+03:00 Bijay Dash notifications@github.com:
@krtl https://github.com/krtl Could you please share how you did it?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/4ib3r/StompBrokerJS/issues/5#issuecomment-409538523, or mute the thread https://github.com/notifications/unsubscribe-auth/Ab6oZlzvq7vuxbnNu8ctxKGBrsgLfG_Iks5uMYvxgaJpZM4QwFZD .
@krtl Will you be able to share any code snippets or the general idea/login on what changes you made, just an overview
ok, I made two things:
1) add socket param to emit of 'send' event line 112 in original stompServer.js: this.emit('send', {frame: {headers: frame.headers, body: bodyObj}, dest: args.dest, socket});
2) add following func to original stompServer.js
/** SendIndividual message to specific client
@param {string} body Message body */ this.sendIndividual = function (socket, topic, headers, body) { var _headers = {}; if (headers) { for (var key in headers) { _headers[key] = headers[key]; } } var frame = { body: body, headers: _headers }; var args = { dest: topic, frame: this.frameParser(frame) };
var bodyObj = args.frame.body; var frame = this.frameSerializer(args.frame); var headers = { //default headers 'message-id': stomp.genId("msg"), 'content-type': 'text/plain' }; if (frame.body !== undefined) { if (typeof frame.body !== 'string') throw "Message body is not string"; frame.headers["content-length"] = frame.body.length; } if (frame.headers) { for (var key in frame.headers) { headers[key] = frame.headers[key]; } }
for (var i in this.subscribes) { var sub = this.subscribes[i]; if (socket.sessionId !== sub.sessionId) { continue; } var match = this._checkSubMatchDest(sub, args); if (match) { args.frame.headers.subscription = sub.id; frame.command = "MESSAGE"; if (socket !== undefined) { StompUtils.sendFrame(socket, frame); } } } };
Usage: In my project I needed only to reply to individuals:
stompServer.on('send', (ev) => { //... stompServer.sendIndividual(ev.socket, TOPIC_NAME, {}, REPLY_TEXT); });
the same code for reply on subscribe:
stompServer.on('subscribe', (ev) => { //... stompServer.sendIndividual(ev.socket, TOPIC_NAME, {}, REPLY_TEXT); });
Please implement sending of individual messages to stomp client. Great thanks for your work!