mirror of
https://github.com/fiatjaf/khatru.git
synced 2025-03-18 13:53:03 +01:00
34 lines
547 B
Go
34 lines
547 B
Go
package khatru
|
|
|
|
import (
|
|
"net/http"
|
|
"sync"
|
|
|
|
"github.com/fasthttp/websocket"
|
|
)
|
|
|
|
type WebSocket struct {
|
|
conn *websocket.Conn
|
|
mutex sync.Mutex
|
|
|
|
// original request
|
|
Request *http.Request
|
|
|
|
// 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)
|
|
}
|