2016-01-20 34 views
0

在我的項目後端發送了很多消息發佈到不同的渠道。
我可以從瀏覽器控制檯看到消息到達了channel屬性。 但問題是傳遞給swampdragon.onChannelMessage的回調沒有得到那個通道信息。它會得到奇怪的頻道列表。
所以當一個消息到達(在瀏覽器中)我無法弄清楚它發佈到的頻道,因此正確處理它。Swampdragon:如何確定消息發佈到的頻道?

我發現其中信道信息被剝離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; 
} 

所以我的問題是前端開發人員如何找出通道的信息到達是爲了能夠處理的消息發佈到代碼正常嗎?

回答

0

有點晚了,但如果你不能夠解決這個問題:

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 
    } 
}); 

onChannelMessagechannels說法是渠道傳入的消息被髮送到一個數組。您可以使用indexOf檢查您感興趣的頻道是否存在於列表中。

相關問題