如何让客户端事件与基于每个用户的动态频道一起使用?
我有一个监听控制器,它监听从后端定义的事件:
聆听控制器
export default Ember.ObjectController.extend(window.EmberPusher.Bindings, window.EmberPusher.ClientEvents, {
init: function(){
var channel = this.get('pusher.connection').subscribe('channel_'+this.get('session').user_id);
PUSHER_SUBSCRIPTIONS: {channel: ['message_received']}
},
actions: {
messageReceived: function(){
alert("client user messages is working!");
}
}
});
后端正在触发这样的事件:
$channel_name = "channel_".(string)$receiver_id;
$pusher->trigger($channel_name, (string)$n_type, $data);
调试问题很难,因为什么都没发生。推进器流的处理方式是否存在明显错误?
答案 0 :(得分:2)
想出来。我没有使用PUSHER_SUBSCRIPTIONS哈希,但它的工作原理相同。
init: function(){
var channel = this.get('pusher.connection').subscribe('channel_'+this.get('session').user_id);
channel.bind('message_received', function(data){
alert(data);
});
}