-
Notifications
You must be signed in to change notification settings - Fork 3
/
type_listener_inner.go
42 lines (34 loc) · 1.02 KB
/
type_listener_inner.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
package pushKit
import (
"github.com/richelieu-yang/chimera/v3/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())
}
// OnMessage 仅针对WebSocket连接
func (listener *innerListener) OnMessage(channel Channel, messageType int, data []byte) {
// 响应 WebSocket客户端 发来的 "ping"
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)
}