Giter VIP home page Giter VIP logo

Comments (5)

krtl avatar krtl commented on August 22, 2024 2

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 {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.

krtl avatar krtl commented on August 22, 2024

I figured out how to do it

from stompbrokerjs.

bjdash avatar bjdash commented on August 22, 2024

@krtl Could you please share how you did it?

from stompbrokerjs.

krtl avatar krtl commented on August 22, 2024

from stompbrokerjs.

bjdash avatar bjdash commented on August 22, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.