neko/internal/types/websocket.go

29 lines
539 B
Go
Raw Normal View History

package types
2021-08-30 09:00:51 +12:00
import (
"encoding/json"
"net/http"
)
2021-08-30 09:00:51 +12:00
type WebSocketMessage struct {
Event string `json:"event"`
Payload json.RawMessage `json:"payload"`
}
2021-08-30 09:01:51 +12:00
type WebSocketHandler func(Session, WebSocketMessage) bool
2020-12-13 06:37:19 +13:00
2021-01-24 06:18:14 +13:00
type CheckOrigin func(r *http.Request) bool
2020-11-26 06:36:33 +13:00
type WebSocketPeer interface {
2021-09-02 07:11:07 +12:00
Send(event string, payload interface{})
2021-09-25 01:15:59 +12:00
Ping() error
2021-09-03 07:52:23 +12:00
Destroy(reason string)
}
2020-11-02 04:09:48 +13:00
type WebSocketManager interface {
2020-10-29 08:29:18 +13:00
Start()
Shutdown() error
2021-08-30 09:01:51 +12:00
AddHandler(handler WebSocketHandler)
2021-09-19 00:59:15 +12:00
Upgrade(checkOrigin CheckOrigin) RouterHandler
}