khatru/websocket.go

30 lines
487 B
Go
Raw Normal View History

package khatru
import (
"sync"
2023-06-23 07:10:03 -03:00
"github.com/fasthttp/websocket"
)
type WebSocket struct {
conn *websocket.Conn
mutex sync.Mutex
// nip42
Challenge string
Authed string
WaitingForAuth 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)
}