Comments (5)
ok, I made two things:
-
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}); -
add following func to original stompServer.js
/** SendIndividual message to specific client
- @param {socket} client
- @param {object} headers Message headers
- @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);
});
from stompbrokerjs.
I figured out how to do it
from stompbrokerjs.
@krtl Could you please share how you did it?
from stompbrokerjs.
from stompbrokerjs.
@krtl Will you be able to share any code snippets or the general idea/login on what changes you made, just an overview
from stompbrokerjs.
Related Issues (17)
- Can I Create Stomp-Server Over WebSocket here HOT 3
- Proposition: Use GitHub releases HOT 1
- ReferenceError: headers is not defined HOT 3
- The SockJS example is not working HOT 2
- Please, refresh package in npm. HOT 6
- Validate headers during connect HOT 1
- Simple connection attempt from browser does not work HOT 3
- Subscribe and publish HOT 5
- Does anyone know how to use this plugin in nestjs? HOT 1
- stompServer.send will lose the last 10 characters HOT 1
- TypeError: Cannot read property '0' of undefined
- Cannot use with noServer: true HOT 1
- Request for feature of heartbeatOn both server and client
- Server messages don't have destination header.
- HeartBeatOn does not work
- Wrong module name in example HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from stompbrokerjs.