Deepstream.io – 客户端断开连接时的服务器callback?

我正在使用Authorative服务器模型与Deepstream构build多人游戏。 我的服务器只是另一个Node.JS客户端。 有没有办法让我的服务器找出是否有任何连接的客户端断开或closures他们的连接? 是否有事件或callback被暴露?

我可以build立一个心跳系统,但我想知道这是否可以避免。

是的,官方的“存在”function已经完成并在testing中。 但是,您可以通过在本教程中以此代码行的方式进行侦听来模仿其function。

一般来说,所有的客户都会订阅特定的状态事件,例如

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 ); } } 

这将跟踪任何断开,无论是有意或无意的