mirror of
https://github.com/bettercap/bettercap
synced 2025-07-30 11:40:33 -07:00
fix: fixed events buffering, now no event is lost with multiple listeners (fixes #266)
This commit is contained in:
parent
e9fa015962
commit
9f0b4a9502
3 changed files with 25 additions and 21 deletions
|
@ -68,6 +68,8 @@ func (api *RestAPI) streamWriter(ws *websocket.Conn, w http.ResponseWriter, r *h
|
|||
log.Debug("Listening for events and streaming to ws endpoint ...")
|
||||
|
||||
pingTicker := time.NewTicker(pingPeriod)
|
||||
listener := session.I.Events.Listen()
|
||||
defer session.I.Events.Unlisten(listener)
|
||||
|
||||
for {
|
||||
select {
|
||||
|
@ -75,7 +77,7 @@ func (api *RestAPI) streamWriter(ws *websocket.Conn, w http.ResponseWriter, r *h
|
|||
if err := api.sendPing(ws); err != nil {
|
||||
return
|
||||
}
|
||||
case event := <-api.eventListener:
|
||||
case event := <-listener:
|
||||
if err := api.streamEvent(ws, event); err != nil {
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue