working websocket implementation
This commit is contained in:
54
ws/structs.go
Normal file
54
ws/structs.go
Normal file
@@ -0,0 +1,54 @@
|
||||
package ws
|
||||
|
||||
import (
|
||||
"log/slog"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
)
|
||||
|
||||
type WebsocketGateway struct {
|
||||
port int
|
||||
apiKey string
|
||||
bodySizeBytes int64
|
||||
|
||||
upgrader websocket.Upgrader
|
||||
modConnsMu sync.Mutex
|
||||
modConns map[*websocket.Conn]struct{}
|
||||
|
||||
botConnsMu sync.Mutex
|
||||
botConns map[*websocket.Conn]*sync.Mutex
|
||||
outgoingCh chan GatewayMessageOut
|
||||
|
||||
logger *slog.Logger
|
||||
closefn func() error
|
||||
}
|
||||
|
||||
type User struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
type GatewayMessageIn struct {
|
||||
MsgID string `json:"msg_id"`
|
||||
Server string `json:"server"`
|
||||
User User `json:"user"`
|
||||
Content string `json:"content"`
|
||||
Meta map[string]interface{} `json:"meta,omitempty"`
|
||||
Ts string `json:"ts,omitempty"`
|
||||
ReceivedAt time.Time `json:"-"` // ReceivedAt is populated by gateway (not from mod)
|
||||
}
|
||||
|
||||
type GatewayMessageOut struct {
|
||||
Type string `json:"type"` // "message"
|
||||
Payload GatewayMessageIn `json:"payload"`
|
||||
ForwardedBy string `json:"forwarded_by"` // "ws"/"http"
|
||||
ForwardedAt time.Time `json:"forwarded_at"`
|
||||
}
|
||||
|
||||
type BotAck struct {
|
||||
Type string `json:"type"` // "acknowledge"
|
||||
MsgID string `json:"msg_id"`
|
||||
Status string `json:"status,omitempty"` // "queued"/"sent"
|
||||
}
|
||||
Reference in New Issue
Block a user