我正在使用授权服务器模型构建一个使用Deepstream的多人游戏。我的服务器只是另一个Node.JS客户机。我的服务器是否有任何方法可以确定是否有任何连接客户端断开或关闭了它们的连接?是否有公开的事件或回调?
我可以建立一个心跳系统,但我想知道这是否可以避免。
发布于 2016-10-08 11:14:16
是的,正式的“在场”特征已经完成并正在测试中。但是,您可以通过侦听来模仿它的功能,如本教程 at 这一行代码所示。
一般来说,所有客户都会订阅特定于他们的状态事件。
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 );
}
}这将跟踪任何断开,无论是有意的还是意外的。
https://stackoverflow.com/questions/39929249
复制相似问题