mirror of
https://github.com/AynaLivePlayer/AynaLivePlayer.git
synced 2026-03-15 14:03:17 +08:00
migrate to eventbus, add support to macos
This commit is contained in:
@@ -191,7 +191,7 @@ func (b *bus) SubscribeAny(eventId, handlerName string, fn HandlerFunc) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *bus) SubscribeOnce(eventId, handlerName string, fn HandlerFunc) error {
|
||||
func (b *bus) SubscribeOnce(channel, eventId, handlerName string, fn HandlerFunc) error {
|
||||
if eventId == "" || handlerName == "" || fn == nil {
|
||||
return errors.New("invalid SubscribeOnce args")
|
||||
}
|
||||
@@ -202,7 +202,7 @@ func (b *bus) SubscribeOnce(eventId, handlerName string, fn HandlerFunc) error {
|
||||
m = make(map[string]handlerRec)
|
||||
b.handlers[eventId] = m
|
||||
}
|
||||
m[handlerName] = handlerRec{name: handlerName, fn: fn, once: true}
|
||||
m[handlerName] = handlerRec{channel: channel, name: handlerName, fn: fn, once: true}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -225,6 +225,10 @@ func (b *bus) Publish(eventId string, data interface{}) error {
|
||||
return b.PublishEvent(&Event{Id: eventId, Data: data})
|
||||
}
|
||||
|
||||
func (b *bus) PublishToChannel(channel string, eventId string, data interface{}) error {
|
||||
return b.PublishEvent(&Event{Id: eventId, Channel: channel, Data: data})
|
||||
}
|
||||
|
||||
func (b *bus) PublishEvent(ev *Event) error {
|
||||
if ev == nil || ev.Id == "" {
|
||||
return errors.New("invalid PublishEvent args")
|
||||
@@ -327,6 +331,15 @@ func (b *bus) Call(eventId string, data interface{}, subEvtId string) (*Event, e
|
||||
}
|
||||
}
|
||||
|
||||
func (b *bus) Reply(req *Event, eventId string, data interface{}) error {
|
||||
return b.PublishEvent(&Event{
|
||||
Id: eventId,
|
||||
Channel: req.Channel,
|
||||
EchoId: req.EchoId,
|
||||
Data: data,
|
||||
})
|
||||
}
|
||||
|
||||
func (b *bus) nextEchoId() string {
|
||||
x := b.idCtr.Add(1)
|
||||
return fmt.Sprintf("echo-%d-%d", time.Now().UnixNano(), x)
|
||||
|
||||
Reference in New Issue
Block a user