53 lines
1.4 KiB
Go
53 lines
1.4 KiB
Go
|
// Package ws -----------------------------
|
||
|
// @file : consts.go
|
||
|
// @author : JJXu
|
||
|
// @contact : wavingbear@163.com
|
||
|
// @time : 2025/6/14 09:44
|
||
|
// -------------------------------------------
|
||
|
package ws
|
||
|
|
||
|
// websocket 消息类型
|
||
|
type WsType int
|
||
|
|
||
|
const (
|
||
|
RegisterType WsType = iota //用户注册消息
|
||
|
ErrorType //错误消息
|
||
|
TestType //测试消息
|
||
|
ChatType //聊天消息
|
||
|
NewChatMsgType //新消息通知
|
||
|
AuthorizationType //token校验通知
|
||
|
)
|
||
|
|
||
|
// 事件总线中的事件类型
|
||
|
type EventType string
|
||
|
|
||
|
const (
|
||
|
EventConnection EventType = "connection" //websocket连接事件
|
||
|
EventUserJoin EventType = "user_join" //用户/客服加入聊天事件
|
||
|
EventUserLeave EventType = "user_leave" //用户离开事件
|
||
|
EventChatMessage EventType = "chat_message" //聊天消息传递事件
|
||
|
)
|
||
|
|
||
|
// before
|
||
|
type EventProgress string
|
||
|
|
||
|
const (
|
||
|
EventProgressBefore EventProgress = "before"
|
||
|
EventProgressAfter EventProgress = "after"
|
||
|
)
|
||
|
|
||
|
type ListenEvent struct {
|
||
|
EventType EventType `json:"type"`
|
||
|
ProgressType EventProgress `json:"progress"`
|
||
|
}
|
||
|
type ListenEventData struct {
|
||
|
ListenEvent
|
||
|
Data interface{}
|
||
|
}
|
||
|
type ListenEventChan chan ListenEventData
|
||
|
type EventListener struct {
|
||
|
Name string
|
||
|
ListenEvents []ListenEvent //需要监听的事件列表
|
||
|
Chan ListenEventChan
|
||
|
}
|