Fix WebRTC async candidates processing

This commit is contained in:
Alexey Khit
2023-02-24 12:22:32 +03:00
parent 4328d2a573
commit f5892e4cfc
3 changed files with 45 additions and 12 deletions
+15 -2
View File
@@ -104,6 +104,8 @@ func apiWS(w http.ResponseWriter, r *http.Request) {
break
}
log.Trace().Str("type", msg.Type).Msg("[api.ws] msg")
if handler := wsHandlers[msg.Type]; handler != nil {
go func() {
if err = handler(tr, msg); err != nil {
@@ -119,8 +121,9 @@ func apiWS(w http.ResponseWriter, r *http.Request) {
var wsUp *websocket.Upgrader
type Transport struct {
Request *http.Request
Consumer interface{} // TODO: rewrite
Request *http.Request
ctx map[any]any
closed bool
mx sync.Mutex
@@ -170,3 +173,13 @@ func (t *Transport) OnClose(f func()) {
}
t.mx.Unlock()
}
// WithContext - run function with Context variable
func (t *Transport) WithContext(f func(ctx map[any]any)) {
t.mx.Lock()
if t.ctx == nil {
t.ctx = map[any]any{}
}
f(t.ctx)
t.mx.Unlock()
}