Files
khatru/websocket.go
2023-11-29 12:23:21 -03:00

30 lines
490 B
Go

package khatru
import (
"sync"
"github.com/fasthttp/websocket"
)
type WebSocket struct {
conn *websocket.Conn
mutex sync.Mutex
// nip42
Challenge string
AuthedPublicKey string
Authed chan struct{}
}
func (ws *WebSocket) WriteJSON(any any) error {
ws.mutex.Lock()
defer ws.mutex.Unlock()
return ws.conn.WriteJSON(any)
}
func (ws *WebSocket) WriteMessage(t int, b []byte) error {
ws.mutex.Lock()
defer ws.mutex.Unlock()
return ws.conn.WriteMessage(t, b)
}