推送
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.0 KiB

package hasaki_push
import (
"git.ouxuan.net/hasaki-service/hasaki-sdk/hskgin"
"git.ouxuan.net/hasaki-service/hasaki-sdk/hskutils"
"git.ouxuan.net/tommy/melody"
)
func Initialize(router *hskgin.GinHelper) {
node := NewNode()
// PAD_MESSAGE
router.Any("/push/message", func(ctx *hskgin.GinContextHelper) {
err := node.HandleRequest(ctx.GinContext.Writer, ctx.GinContext.Request)
ctx.CheckErrDisplayByError(err)
})
// 连接
node.HandleConnect(func(session *melody.Session) {
node.SetSession("unknown-"+hskutils.CreateUUID(), NewSession(session)) // 连接
})
// 断连
node.HandleDisconnect(func(session *melody.Session) {
})
// 接收信息
node.HandleMessage(func(session *melody.Session, message []byte) {
// 根据消息类型进行各种
})
// 发送消息
node.HandleSentMessage(func(session *melody.Session, bytes []byte) {
// 设置发送状态
})
// 错误
node.HandleError(func(session *melody.Session, err error) {
})
// 关闭
node.HandleClose(func(session *melody.Session, i int, s string) error {
return nil
})
}