2023-08-10 14:32:11 -03:00
|
|
|
package khatru
|
2022-01-11 16:00:19 -03:00
|
|
|
|
|
|
|
import (
|
|
|
|
"sync"
|
|
|
|
|
2023-06-23 07:10:03 -03:00
|
|
|
"github.com/fasthttp/websocket"
|
2022-01-11 16:00:19 -03:00
|
|
|
)
|
|
|
|
|
|
|
|
type WebSocket struct {
|
|
|
|
conn *websocket.Conn
|
|
|
|
mutex sync.Mutex
|
2023-01-15 22:38:24 -03:00
|
|
|
|
|
|
|
// nip42
|
2023-08-10 14:32:11 -03:00
|
|
|
Challenge string
|
|
|
|
Authed string
|
|
|
|
WaitingForAuth chan struct{}
|
2022-01-11 16:00:19 -03:00
|
|
|
}
|
|
|
|
|
2023-08-10 14:32:11 -03:00
|
|
|
func (ws *WebSocket) WriteJSON(any any) error {
|
2022-01-11 16:00:19 -03:00
|
|
|
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)
|
|
|
|
}
|