-
Notifications
You must be signed in to change notification settings - Fork 3
/
typeInnerListener.go
41 lines (33 loc) · 992 Bytes
/
typeInnerListener.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
package pushKit
import (
"github.com/richelieu-yang/chimera/v2/src/core/bytesKit"
"net/http"
)
type innerListener struct {
Listener
}
func (listener *innerListener) OnFailure(w http.ResponseWriter, r *http.Request, failureInfo string) {
}
func (listener *innerListener) OnHandshake(w http.ResponseWriter, r *http.Request, channel Channel) {
// 加入管理
BindId(channel, channel.GetId())
}
func (listener *innerListener) OnMessage(channel Channel, messageType int, data []byte) {
// 仅针对WebSocket连接
if bytesKit.Equals(data, PingData) {
if err := channel.Push(PongData); err != nil {
logger.WithError(err).Error("Fail to pong")
return
}
}
}
func (listener *innerListener) BeforeClosedByBackend(channel Channel, closeInfo string) {
}
func (listener *innerListener) OnClose(channel Channel, closeInfo string, bsid, user, group string) {
channel.Dispose()
// 移除管理
UnbindId(channel)
UnbindBsid(channel)
UnbindUser(channel)
UnbindGroup(channel)
}