沼泽龙:如何确定消息发布到的频道
Swampdragon: how to determine a channel the message was published to?
在我的项目中,后端会发送大量发布到不同频道的消息。
我可以从浏览器控制台看到到达的消息具有channel
属性。但问题是传递给swampdragon.onChannelMessage
的回调没有获得该通道信息。它反而会得到奇怪的频道列表。
因此,当消息到达(在浏览器中)时,我无法弄清楚它发布到的频道,因此无法正确处理它。
我找到了从频道信息中删除的代码 https://github.com/jonashagstedt/swampdragon/blob/master/swampdragon/static/swampdragon/js/dist/swampdragon.js#L261
if ('channel' in e.data) {
var channel = swampDragon.channels[e.data.channel];
delete(e.data['channel']);
swampDragon.settings.onchannelmessage(channel, e.data);
return;
}
所以我的问题是前端开发人员如何确定到达的消息发布到哪个渠道,以便能够正确处理消息?
有点
晚了,但如果你无法解决这个问题:
swampdragon.open(function() {
swampdragon.subscribe('notification', 'notification', null, function (context, data) {
// Successfully subscribed to the notification channel
}, function () {
console.error('Error', arguments);
});
});
swampdragon.onChannelMessage(function(channels, message) {
if (channels.indexOf('notification') > -1) {
// Message sent on the notification channel
}
});
在onChannelMessage
中,channels
参数是传入消息发送到的通道数组。您可以使用indexOf
检查列表中是否存在您感兴趣的频道。
相关文章:
- Ajax聊天消息重复而不仅仅是更新
- 将电视直播频道从网站嵌入我的网站
- 如果localstorage为空,则显示欢迎消息
- 绑定时将Parsley minlength消息作为选项传递时,未对其进行自定义
- 离开页面时弹出消息
- 有没有一种方法可以在控制台关闭的情况下让console.log()在IE中记录消息
- 消息显示之外的淘汰验证
- 选项卡侦听器未被来自后台脚本的消息激活
- jQuery在输入下验证post错误消息
- Scipt未在选定选项卡中执行以发送和接收消息
- 检查xmlhttprequest问题的消息
- AngularJs对ng消息的自定义替换
- ng消息仅在触摸时显示错误,并在错误的初始显示上转换
- 如何不向频道的所有订阅者发送消息
- 获取频道中的消息数,而无需在 Twilio IP 消息传递中检索它们
- 有消息频道和没有消息频道的网络消息有什么区别
- 沼泽龙:如何确定消息发布到的频道
- 消息:'禁止'尝试将频道添加到PubNub中的频道组时
- 无法使用Hubot向Slack中的特定频道发送消息- slackrterror:没有频道id
- 如何使用CometD向频道的所有Javascript订阅者发布消息?