a function to send an event directly to a specific connection.

This commit is contained in:
fiatjaf
2024-10-13 12:42:36 -03:00
parent 39d882857c
commit e9c9d0c3a7
2 changed files with 9 additions and 1 deletions

View File

@@ -140,7 +140,7 @@ func (rl *Relay) notifyListeners(event *nostr.Event) {
return
}
}
listener.ws.WriteJSON(nostr.EventEnvelope{SubscriptionID: &listener.id, Event: *event})
listener.ws.SendEvent(listener.id, *event)
}
}
}

View File

@@ -5,6 +5,7 @@ import (
"sync"
"github.com/fasthttp/websocket"
"github.com/nbd-wtf/go-nostr"
)
type WebSocket struct {
@@ -33,3 +34,10 @@ func (ws *WebSocket) WriteMessage(t int, b []byte) error {
defer ws.mutex.Unlock()
return ws.conn.WriteMessage(t, b)
}
func (ws *WebSocket) SendEvent(subscriptionId string, event nostr.Event) error {
return ws.WriteJSON(nostr.EventEnvelope{
SubscriptionID: &subscriptionId,
Event: event,
})
}