-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[frontend] How to handle arriving messages published to concrete channel #192
Comments
You should be able to access the channel information by using swampdragon.onChannelMessage(function (channels, message) {
for(var i in channels) {
if (channels[i] == "your_channel") {
// your code goes here
}
}
} and |
@AlexejStukov swampdragon.subscribe("my_route", "my_channel_1", ...)
swampdragon.subscribe("my_route", "my_channel_2", ...)
swampdragon.subscribe("my_route", "my_channel_3", ...) then if I have the suggested solution:
Then each of the callbacks |
@aantipov
// ...
if (channels[i] == "my_channel") {
if ("something" in message.data) {
// your code
}
}
swampdragon.subscribe('your_route', "channel_1", {"something":"value_1"}, function (context, data) {
// subscription success
}, function (context, data) {
// subscription fail
});
I would use the first option, if it's the same source sending you different kinds of information, the second approach, if it's the same kind of data, but from different sources and the third if you have different sources. Also you can mix and match that to your liking. |
@AlexejStukov Thanks for helping. |
@aantipov |
@aantipov swampdragon.open(function() {
{% for object in object_list %}
swampdragon.subscribe('object-route', "object", {"pk":"{{ object.pk }}"}, function (context, data) {
}, function (context, data) {
});
{% endfor %} {# edit #}
}); in my template and def get_subscription_contexts(self, **kwargs):
obj = self.get_object(**kwargs)
return {"object": kwargs["pk"]} in my routers.py. With this you can also add authentication (with swampdragon-auth) pretty easy (with an if in both files). |
Hi
I'm a frontend developer.
Backend sends a lot of messages published to different channels.
I can see from browser console the message arrived has
channel
property.But the problem is a callback passed to
swampdragon.onChannelMessage
doesn't get that channel information. It gets strangechannels
list instead.So when a message arrives I can't figure out the channel it was published to and therefore handle it properly.
I found the code where that channel info is stripped off https://github.com/jonashagstedt/swampdragon/blob/master/swampdragon/static/swampdragon/js/dist/swampdragon.js#L261
So my question is how to figure out what channel the message arrived was published to in order to be able to handle the message properly?
The text was updated successfully, but these errors were encountered: