From 4e19c54467506e8bbea41b72a6bdc0e6697c4b23 Mon Sep 17 00:00:00 2001 From: Alexey Khit Date: Sat, 25 Feb 2023 19:57:29 +0300 Subject: [PATCH] Set custom pion API for WebRTC client --- cmd/webrtc/webrtc.go | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/cmd/webrtc/webrtc.go b/cmd/webrtc/webrtc.go index 0c6db9dd..9c516f46 100644 --- a/cmd/webrtc/webrtc.go +++ b/cmd/webrtc/webrtc.go @@ -32,17 +32,20 @@ func Init() { address := cfg.Mod.Listen // create pionAPI with custom codecs list and custom network settings - pionAPI, err := webrtc.NewAPI(address) - if pionAPI == nil { + serverAPI, err := webrtc.NewAPI(address) + if err != nil { log.Error().Err(err).Caller().Send() return } - if err != nil { - log.Warn().Err(err).Caller().Send() - } else if address != "" { + // use same API for WebRTC server and client if no address + clientAPI := serverAPI + + if address != "" { log.Info().Str("addr", address).Msg("[webrtc] listen") _, Port, _ = net.SplitHostPort(address) + + clientAPI, _ = webrtc.NewAPI("") } pionConf := pion.Configuration{ @@ -52,9 +55,9 @@ func Init() { newPeerConnection = func(isServer bool) (*pion.PeerConnection, error) { if isServer { - return pionAPI.NewPeerConnection(pionConf) + return serverAPI.NewPeerConnection(pionConf) } else { - return pion.NewPeerConnection(pionConf) + return clientAPI.NewPeerConnection(pionConf) } }