Reputation: 12172
I am using Stomp / Orbited for Comet functionality.
In order to deal with multiple channels, I end up doing this:
stomp.onmessageframe = function(frame) {
if (frame.headers['destination'] == '/thisFeed/') { //handle thisFeed }
if (frame.headers['destination'] == '/thatFeed/') { //handle thatFeed }
....which is OK, I guess. But what if I don't know, at load time, how I want to handle a feed? I want to be able to do something like this:
stomp.subscribe('someOtherFeed', someOtherFeedHandler);
That way, when I subscribe, I can define the handler then and only then.
Upvotes: 1
Views: 832
Reputation: 12172
I have come up with one solution, but it's so very far from pretty.
When I create the stomp message, I add a "handler" property as a header, like so in python:
conn.send('Frank the Wonder Llama", destination="/infoAboutLlamas/", handler='llamas')
Then, in the javascript:
stomp.onmessageframe = function(frame) {
window[frame.headers['handler']]() //Execute the function named by the handler
}
...so then, the function llamas() gets called. I can then define (and redefine) llamas anywhere I want.
Now I'm sure this can't be the optimal solution. I do, on the other hand, like that it gives me a bit of flexibility to specify the handler I want to use right in python. But seriously, I'm thinking there is a better way.
Upvotes: 0