almstrand / lib_socks

Dart client and server package for building and consuming HTTP/1.1 web services including RESTful services, WebSocket services, and STOMP 1.2 WebSocket services.
https://pub.dartlang.org/packages/socks
MIT License
2 stars 0 forks source link

How to send stomp message #1

Open SatWiz opened 9 years ago

SatWiz commented 9 years ago

I am just discovering this and get your samples running for the stomp ws. I see that the server can handle subscriptions but can't see how it is sending custom messages back to the subscriber. Is it implement already, I don't see which methode to use. Can you please give a hint or example? Thanks.

almstrand commented 9 years ago

Did the sample code work? Specifically, are you able to run the "WebSocket Stomp Server" and "WebSocket STOMP Client" sample code?

That server sample code shows how a server can register a STOMP destination (named "kitchen".) The client sample code sends a STOMP message to that destination, and all clients (including the sending client) will receive the message via the onMessage stream.

SatWiz commented 9 years ago

Sample code work as it is but I want to extend it with a custom message reply. Is there a response.send methode which I can create my own reply function?

almstrand commented 9 years ago

I see. So you are looking for a way to modify a message before forwarding to subscribed clients?

Something like this?

  1. Clients A, B, and C subscribes to destination D on server S
  2. Client A sends a message M to D on S
  3. Before S forwards M to A, B, and C, the message is modified to (e.g.) have a different body

If so, perhaps _onSendFrame(...) in StompRequestHandler.dart can be made public to allow for optional processing of the received message prior to forwarding to subscribers. In the server example, it would look something like:

// Create WebSocket STOMP request handler.
@server.UriPath("/stomp")
class MyWebSocketStompHandler extends server.StompRequestHandler {
  MyWebSocketStompHandler() {
    addDestination(new MyKitchen());

    // This function can be overridden as shown here to modify the frame receive
    // before sending it to subscribed clients
    Future<shared.SendFrame> onSendFrame(shared.SendFrame sendFrame, WebSocketStompConnection connection) {
      sendFrame.body = "Custom message";
      return onSendFrame(sendFrame, connection);
    }
  }
}

Would that work?