Add OnDisconnect event

This commit is contained in:
John Brooks 2016-10-01 15:52:35 -07:00 committed by Sarah Jamie Lewis
parent 733e00d6f9
commit 1c317fc186
3 changed files with 7 additions and 0 deletions

View File

@ -101,6 +101,8 @@ func (r *Ricochet) ProcessMessages(service RicochetService) {
// to process them. // to process them.
func (r *Ricochet) processConnection(oc *OpenConnection, service RicochetService) { func (r *Ricochet) processConnection(oc *OpenConnection, service RicochetService) {
service.OnConnect(oc) service.OnConnect(oc)
defer service.OnDisconnect(oc)
for { for {
if oc.Closed { if oc.Closed {
return return

View File

@ -4,6 +4,7 @@ package goricochet
type RicochetService interface { type RicochetService interface {
OnReady() OnReady()
OnConnect(oc *OpenConnection) OnConnect(oc *OpenConnection)
OnDisconnect(oc *OpenConnection)
// Authentication Management // Authentication Management
OnAuthenticationRequest(oc *OpenConnection, channelID int32, clientCookie [16]byte) OnAuthenticationRequest(oc *OpenConnection, channelID int32, clientCookie [16]byte)

View File

@ -84,6 +84,10 @@ func (srs *StandardRicochetService) OnConnect(oc *OpenConnection) {
} }
} }
// OnDisconnect is called when a connection is closed
func (srs *StandardRicochetService) OnDisconnect(oc *OpenConnection) {
}
// OnAuthenticationRequest is called when a client requests Authentication // OnAuthenticationRequest is called when a client requests Authentication
func (srs *StandardRicochetService) OnAuthenticationRequest(oc *OpenConnection, channelID int32, clientCookie [16]byte) { func (srs *StandardRicochetService) OnAuthenticationRequest(oc *OpenConnection, channelID int32, clientCookie [16]byte) {
oc.ConfirmAuthChannel(channelID, clientCookie) oc.ConfirmAuthChannel(channelID, clientCookie)