-
Notifications
You must be signed in to change notification settings - Fork 2
/
hook.go
57 lines (42 loc) · 1.39 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
package mqtt
import (
"github.com/snple/mqtt/packets"
)
// Hook is the server hook interface.
type Hook interface {
// When the client connects to the server
// If the return is false, the client will be rejected.
Connect(*Server, *Client) bool
// When the client disconnects
DisConnect(*Server, *Client, error)
// When the server receives a packet.
// If the return is false, it will cancel the operation.
Recv(*Server, *Client, *packets.Packet) bool
// When the server sends a packet.
// If the return is false, it will cancel the operation.
Send(*Server, *Client, *packets.Packet) bool
// When the server receives a message from the client publish.
// If the return is false, it will cancel the operation.
Emit(*Server, *Client, *packets.Packet) bool
// When the server pushes a message to the client
// If the return is false, it will cancel the operation.
Push(*Server, *Client, *packets.Packet) bool
}
var _ Hook = (*NilHook)(nil)
type NilHook struct{}
func (*NilHook) Connect(*Server, *Client) bool {
return true
}
func (*NilHook) DisConnect(*Server, *Client, error) {}
func (*NilHook) Recv(*Server, *Client, *packets.Packet) bool {
return true
}
func (*NilHook) Send(*Server, *Client, *packets.Packet) bool {
return true
}
func (*NilHook) Emit(*Server, *Client, *packets.Packet) bool {
return true
}
func (*NilHook) Push(*Server, *Client, *packets.Packet) bool {
return true
}