Fix panic on write to WebRTC source #935
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/AlexxIT/go2rtc/internal/api/ws"
|
"github.com/AlexxIT/go2rtc/internal/api/ws"
|
||||||
@@ -82,6 +83,7 @@ func go2rtcClient(url string) (core.Producer, error) {
|
|||||||
|
|
||||||
// waiter will wait PC error or WS error or nil (connection OK)
|
// waiter will wait PC error or WS error or nil (connection OK)
|
||||||
var connState core.Waiter
|
var connState core.Waiter
|
||||||
|
var connMu sync.Mutex
|
||||||
|
|
||||||
prod := webrtc.NewConn(pc)
|
prod := webrtc.NewConn(pc)
|
||||||
prod.Desc = "WebRTC/WebSocket async"
|
prod.Desc = "WebRTC/WebSocket async"
|
||||||
@@ -91,7 +93,9 @@ func go2rtcClient(url string) (core.Producer, error) {
|
|||||||
case *pion.ICECandidate:
|
case *pion.ICECandidate:
|
||||||
s := msg.ToJSON().Candidate
|
s := msg.ToJSON().Candidate
|
||||||
log.Trace().Str("candidate", s).Msg("[webrtc] local ")
|
log.Trace().Str("candidate", s).Msg("[webrtc] local ")
|
||||||
|
connMu.Lock()
|
||||||
_ = conn.WriteJSON(&ws.Message{Type: "webrtc/candidate", Value: s})
|
_ = conn.WriteJSON(&ws.Message{Type: "webrtc/candidate", Value: s})
|
||||||
|
connMu.Unlock()
|
||||||
|
|
||||||
case pion.PeerConnectionState:
|
case pion.PeerConnectionState:
|
||||||
switch msg {
|
switch msg {
|
||||||
@@ -118,9 +122,9 @@ func go2rtcClient(url string) (core.Producer, error) {
|
|||||||
|
|
||||||
// 4. Send offer
|
// 4. Send offer
|
||||||
msg := &ws.Message{Type: "webrtc/offer", Value: offer}
|
msg := &ws.Message{Type: "webrtc/offer", Value: offer}
|
||||||
if err = conn.WriteJSON(msg); err != nil {
|
connMu.Lock()
|
||||||
return nil, err
|
_ = conn.WriteJSON(msg)
|
||||||
}
|
connMu.Unlock()
|
||||||
|
|
||||||
// 5. Get answer
|
// 5. Get answer
|
||||||
if err = conn.ReadJSON(msg); err != nil {
|
if err = conn.ReadJSON(msg); err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user