Skip to content

Commit

Permalink
Merge pull request #1054 from mesg-foundation/feature/eventsdk-GetStream
Browse files Browse the repository at this point in the history
sdk/eventsdk: add GetStream() API
  • Loading branch information
antho1404 authored Jun 18, 2019
2 parents 9bf6e02 + 0911227 commit f948174
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion sdk/event/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import (
)

const (
topic = "Event"
// streamTopic is topic used to broadcast events.
streamTopic = "event-stream"
topic = "Event"
)

// Event exposes event APIs of MESG.
Expand Down Expand Up @@ -36,10 +38,18 @@ func (e *Event) Emit(token, eventKey string, eventData map[string]interface{}) e
return err
}

go e.ps.Pub(ev, streamTopic)
go e.ps.Pub(ev, subTopic(s.Hash))
return nil
}

// GetStream broadcasts all events.
func (e *Event) GetStream(f *Filter) *Listener {
l := NewListener(e.ps, streamTopic, f)
go l.Listen()
return l
}

// Listen listens events matches with eventFilter on serviceID.
func (e *Event) Listen(service string, f *Filter) (*Listener, error) {
s, err := e.db.Get(service)
Expand Down

0 comments on commit f948174

Please sign in to comment.