From 3a5abfba38995bf85bd6da74497f255af0e3a5b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0lker=20G=C3=B6ktu=C4=9F=20=C3=96zt=C3=BCrk?= Date: Fri, 14 Jun 2019 21:27:07 +0000 Subject: [PATCH] sdk/eventsdk: add GetStream() API it broadcasts all events. --- sdk/event/event.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/sdk/event/event.go b/sdk/event/event.go index 559fa7bfd..ff47e69cb 100644 --- a/sdk/event/event.go +++ b/sdk/event/event.go @@ -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. @@ -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)