presence-room-42
实时聊天
建立在 presence 频道上的房间、成员与正在输入的提示。
应用场景
做轮询的仪表盘在两次请求之间一直是错的,而且你容忍多少错,它就贵多少。改成变化时 publish,就把这件事反了过来。
每秒动几百次的指标,应当在 publish 之前先做批量或采样。这个判断属于有语义的那一侧——你这一侧。
// Start the aggregation when the first viewer arrives,// stop it when the last one leaves.for (const event of hook.getEvents()) { if (event.name === 'channel_occupied') startAggregation(event.channel) if (event.name === 'channel_vacated') stopAggregation(event.channel)}用官方的 Pusher 库写成,未作任何修改——没有 PushCaster 的包要装。 完整文档