Add the option to pass ICE servers with an async WebRTC offer #1408

This commit is contained in:
Alex X
2024-10-24 23:31:21 +03:00
parent 9d709f0db8
commit 16e4831499
2 changed files with 46 additions and 30 deletions
+14 -14
View File
@@ -1,6 +1,7 @@
package ws
import (
"encoding/json"
"io"
"net/http"
"net/url"
@@ -36,22 +37,16 @@ var log zerolog.Logger
type Message struct {
Type string `json:"type"`
Value any `json:"value,omitempty"`
Raw []byte `json:"-"`
}
func (m *Message) String() string {
if s, ok := m.Value.(string); ok {
return s
}
return ""
func (m *Message) String() (value string) {
_ = json.Unmarshal(m.Raw, &value)
return
}
func (m *Message) GetString(key string) string {
if v, ok := m.Value.(map[string]any); ok {
if s, ok := v[key].(string); ok {
return s
}
}
return ""
func (m *Message) Unmarshal(v any) error {
return json.Unmarshal(m.Raw, v)
}
type WSHandler func(tr *Transport, msg *Message) error
@@ -118,8 +113,11 @@ func apiWS(w http.ResponseWriter, r *http.Request) {
})
for {
msg := new(Message)
if err = ws.ReadJSON(msg); err != nil {
var raw struct {
Type string `json:"type"`
Value json.RawMessage `json:"value"`
}
if err = ws.ReadJSON(&raw); err != nil {
if !websocket.IsCloseError(err, websocket.CloseNoStatusReceived) {
log.Trace().Err(err).Caller().Send()
}
@@ -127,6 +125,8 @@ func apiWS(w http.ResponseWriter, r *http.Request) {
break
}
msg := &Message{Type: raw.Type, Raw: raw.Value}
log.Trace().Str("type", msg.Type).Msg("[api] ws msg")
if handler := wsHandlers[msg.Type]; handler != nil {