From 1c317fc1860c4bb9751244a687521e6cf4f05cff Mon Sep 17 00:00:00 2001 From: John Brooks Date: Sat, 1 Oct 2016 15:52:35 -0700 Subject: [PATCH] Add OnDisconnect event --- ricochet.go | 2 ++ ricochetservice.go | 1 + standardricochetservice.go | 4 ++++ 3 files changed, 7 insertions(+) diff --git a/ricochet.go b/ricochet.go index 66d9642..69a5c12 100644 --- a/ricochet.go +++ b/ricochet.go @@ -101,6 +101,8 @@ func (r *Ricochet) ProcessMessages(service RicochetService) { // to process them. func (r *Ricochet) processConnection(oc *OpenConnection, service RicochetService) { service.OnConnect(oc) + defer service.OnDisconnect(oc) + for { if oc.Closed { return diff --git a/ricochetservice.go b/ricochetservice.go index 6bc075e..e3151fd 100644 --- a/ricochetservice.go +++ b/ricochetservice.go @@ -4,6 +4,7 @@ package goricochet type RicochetService interface { OnReady() OnConnect(oc *OpenConnection) + OnDisconnect(oc *OpenConnection) // Authentication Management OnAuthenticationRequest(oc *OpenConnection, channelID int32, clientCookie [16]byte) diff --git a/standardricochetservice.go b/standardricochetservice.go index 0ade7dc..11de4a0 100644 --- a/standardricochetservice.go +++ b/standardricochetservice.go @@ -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 func (srs *StandardRicochetService) OnAuthenticationRequest(oc *OpenConnection, channelID int32, clientCookie [16]byte) { oc.ConfirmAuthChannel(channelID, clientCookie)