forked from Monibuca/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hook.go
95 lines (74 loc) · 1.86 KB
/
hook.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package engine
var AuthHooks = make(AuthHook, 0)
type AuthHook []func(string) error
func (h AuthHook) AddHook(hook func(string) error) {
AuthHooks = append(h, hook)
}
func (h AuthHook) Trigger(sign string) error {
for _, f := range h {
if err := f(sign); err != nil {
return err
}
}
return nil
}
var OnPublishHooks = make(OnPublishHook, 0)
type OnPublishHook []func(r *Stream)
func (h OnPublishHook) AddHook(hook func(r *Stream)) {
OnPublishHooks = append(h, hook)
}
func (h OnPublishHook) Trigger(r *Stream) {
for _, f := range h {
f(r)
}
}
var OnSubscribeHooks = make(OnSubscribeHook, 0)
type OnSubscribeHook []func(s *Subscriber)
func (h OnSubscribeHook) AddHook(hook func(s *Subscriber)) {
OnSubscribeHooks = append(h, hook)
}
func (h OnSubscribeHook) Trigger(s *Subscriber) {
for _, f := range h {
f(s)
}
}
var OnUnSubscribeHooks = make(OnUnSubscribeHook, 0)
type OnUnSubscribeHook []func(s *Subscriber)
func (h OnUnSubscribeHook) AddHook(hook func(s *Subscriber)) {
OnUnSubscribeHooks = append(h, hook)
}
func (h OnUnSubscribeHook) Trigger(s *Subscriber) {
for _, f := range h {
f(s)
}
}
var OnDropHooks = make(OnDropHook, 0)
type OnDropHook []func(s *Subscriber)
func (h OnDropHook) AddHook(hook func(s *Subscriber)) {
OnDropHooks = append(h, hook)
}
func (h OnDropHook) Trigger(s *Subscriber) {
for _, f := range h {
f(s)
}
}
var OnSummaryHooks = make(OnSummaryHook, 0)
type OnSummaryHook []func(bool)
func (h OnSummaryHook) AddHook(hook func(bool)) {
OnSummaryHooks = append(h, hook)
}
func (h OnSummaryHook) Trigger(v bool) {
for _, f := range h {
f(v)
}
}
var OnStreamClosedHooks = make(OnStreamClosedHook, 0)
type OnStreamClosedHook []func(*Stream)
func (h OnStreamClosedHook) AddHook(hook func(*Stream)) {
OnStreamClosedHooks = append(h, hook)
}
func (h OnStreamClosedHook) Trigger(v *Stream) {
for _, f := range h {
f(v)
}
}