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