Fix WebRTC client
This commit is contained in:
@@ -39,7 +39,7 @@ func asyncClient(url string) (streamer.Producer, error) {
|
||||
}()
|
||||
|
||||
// 2. Create PeerConnection
|
||||
pc, err := newPeerConnection()
|
||||
pc, err := newPeerConnection(false)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Caller().Send()
|
||||
return nil, err
|
||||
@@ -115,7 +115,7 @@ func asyncClient(url string) (streamer.Producer, error) {
|
||||
// syncClient - support WebRTC-HTTP Egress Protocol (WHEP)
|
||||
func syncClient(url string) (streamer.Producer, error) {
|
||||
// 2. Create PeerConnection
|
||||
pc, err := newPeerConnection()
|
||||
pc, err := newPeerConnection(false)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Caller().Send()
|
||||
return nil, err
|
||||
@@ -136,6 +136,8 @@ func syncClient(url string) (streamer.Producer, error) {
|
||||
}
|
||||
|
||||
client := http.Client{Timeout: time.Second * 5000}
|
||||
defer client.CloseIdleConnections()
|
||||
|
||||
res, err := client.Do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -139,7 +139,7 @@ func inputWebRTC(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
log.Trace().Msgf("[webrtc] WHIP offer\n%s", offer)
|
||||
|
||||
pc, err := newPeerConnection()
|
||||
pc, err := newPeerConnection(true)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Caller().Send()
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
|
||||
@@ -50,8 +50,12 @@ func Init() {
|
||||
SDPSemantics: pion.SDPSemanticsUnifiedPlanWithFallback,
|
||||
}
|
||||
|
||||
newPeerConnection = func() (*pion.PeerConnection, error) {
|
||||
return pionAPI.NewPeerConnection(pionConf)
|
||||
newPeerConnection = func(isServer bool) (*pion.PeerConnection, error) {
|
||||
if isServer {
|
||||
return pionAPI.NewPeerConnection(pionConf)
|
||||
} else {
|
||||
return pion.NewPeerConnection(pionConf)
|
||||
}
|
||||
}
|
||||
|
||||
for _, candidate := range cfg.Mod.Candidates {
|
||||
@@ -73,7 +77,7 @@ func Init() {
|
||||
var Port string
|
||||
var log zerolog.Logger
|
||||
|
||||
var newPeerConnection func() (*pion.PeerConnection, error)
|
||||
var newPeerConnection func(isServer bool) (*pion.PeerConnection, error)
|
||||
|
||||
func asyncHandler(tr *api.Transport, msg *api.Message) error {
|
||||
src := tr.Request.URL.Query().Get("src")
|
||||
@@ -85,7 +89,7 @@ func asyncHandler(tr *api.Transport, msg *api.Message) error {
|
||||
log.Debug().Str("url", src).Msg("[webrtc] new consumer")
|
||||
|
||||
// create new PeerConnection instance
|
||||
pc, err := newPeerConnection()
|
||||
pc, err := newPeerConnection(true)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Caller().Send()
|
||||
return err
|
||||
@@ -155,7 +159,7 @@ func asyncHandler(tr *api.Transport, msg *api.Message) error {
|
||||
}
|
||||
|
||||
func ExchangeSDP(stream *streams.Stream, offer string, userAgent string) (answer string, err error) {
|
||||
pc, err := newPeerConnection()
|
||||
pc, err := newPeerConnection(true)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Caller().Send()
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user