1
我使用Authorative服务器模型与Deepstream构建多人游戏。我的服务器只是另一个Node.JS客户端。有没有办法让我的服务器查明是否有任何连接的客户端断开或关闭了他们的连接?是否存在暴露的事件或回调?Deepstream.io - 客户端断开连接时的服务器回调?
我可以建立一个心跳系统,但我不知道这是否可以避免。
我使用Authorative服务器模型与Deepstream构建多人游戏。我的服务器只是另一个Node.JS客户端。有没有办法让我的服务器查明是否有任何连接的客户端断开或关闭了他们的连接?是否存在暴露的事件或回调?Deepstream.io - 客户端断开连接时的服务器回调?
我可以建立一个心跳系统,但我不知道这是否可以避免。
是的,官方"presence" feature已经功能齐全,并在测试。但是,您可以通过在this tutorial位于this line of code处进行监听来模拟其功能。
一般而言,所有客户端都会订阅特定于他们的状态事件,例如,
ds.event.subscribe('status/' + name);
服务器现在会听,订阅这些事件并推断在线状态:
ds.event.listen('status/.*', this._playerOnlineStatusChanged.bind(this));
_playerOnlineStatusChanged(match, isSubscribed) {
// Extract the player name from the status event
var name = match.replace('status/', '');
if(isSubscribed) {
this.addPlayer(name);
} else {
this.removePlayer(name);
}
}
这会有意或无意
你使用任何的WebSockets保留任何断开的轨道,无论是库(Socket.io)为您的游戏? – Avinash