对于每个公共配置文件都有唯一的频道名称,例如<user_name>-profile
。
每当用户user_name
的配置文件发生更新时,都会在用户的频道上触发事件,并传递更新的数据。
data = update_profile()
Pusher.trigger('<user_name>-profile', 'profile-updated', {:profile => data})
在运行的浏览器有听只更新相关通道代码中的个人资料页:
var pusher = new Pusher(APP_KEY);
var channel = pusher.subscribe('<user_name>-profile');
channel.bind('profile-updated', function(update) {
// Update UI to show new profile information
// Show something to indicate that an update has occurred
});
这里的一个问题是,你会即使无人触发事件正在查看公共个人资料。如果您想解决该问题,则需要使用WebHooks并跟踪配置文件频道是否为occupied
,并且只有在该情况下才触发该事件。
非常感谢提示!我将进一步研究这一点! – dennismonsewicz