add OnDisconnect() handlers.

This commit is contained in:
fiatjaf
2023-12-09 09:00:11 -03:00
parent d3a0c545d2
commit 3ec0020baa
2 changed files with 5 additions and 0 deletions

View File

@@ -61,6 +61,10 @@ func (rl *Relay) HandleWebsocket(w http.ResponseWriter, r *http.Request) {
)
kill := func() {
for _, ondisconnect := range rl.OnDisconnect {
ondisconnect(ctx)
}
ticker.Stop()
cancel()
if _, ok := rl.clients.Load(conn); ok {

View File

@@ -56,6 +56,7 @@ type Relay struct {
CountEvents []func(ctx context.Context, filter nostr.Filter) (int64, error)
OnAuth []func(ctx context.Context, pubkey string)
OnConnect []func(ctx context.Context)
OnDisconnect []func(ctx context.Context)
OnEventSaved []func(ctx context.Context, event *nostr.Event)
// editing info will affect