mirror of
https://github.com/bettercap/bettercap
synced 2025-08-21 05:53:20 -07:00
new: implemented optional websocket for /api/events
This commit is contained in:
parent
b243e67828
commit
5ad1a17118
4 changed files with 66 additions and 36 deletions
|
@ -57,7 +57,7 @@ func NewEventPool(debug bool, silent bool) *EventPool {
|
|||
func (p *EventPool) Listen() <-chan Event {
|
||||
p.Lock()
|
||||
defer p.Unlock()
|
||||
l := make(chan Event)
|
||||
l := make(chan Event, 1)
|
||||
p.listeners = append(p.listeners, l)
|
||||
return l
|
||||
}
|
||||
|
@ -77,12 +77,16 @@ func (p *EventPool) SetDebug(d bool) {
|
|||
func (p *EventPool) Add(tag string, data interface{}) {
|
||||
p.Lock()
|
||||
defer p.Unlock()
|
||||
|
||||
e := NewEvent(tag, data)
|
||||
p.events = append([]Event{e}, p.events...)
|
||||
|
||||
// broadcast the event to every listener
|
||||
for _, l := range p.listeners {
|
||||
l <- e
|
||||
select {
|
||||
case l <- e:
|
||||
default:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue