From 0075cdca2b99b56cc88de083d1e84690b7dfabfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0ediv=C3=BD?= Date: Thu, 25 Nov 2021 21:43:39 +0100 Subject: [PATCH] implement OnNegotiationNeeded. --- internal/webrtc/manager.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/internal/webrtc/manager.go b/internal/webrtc/manager.go index 205f601e..2844d9b5 100644 --- a/internal/webrtc/manager.go +++ b/internal/webrtc/manager.go @@ -155,6 +155,22 @@ func (manager *WebRTCManagerCtx) CreatePeer(session types.Session, videoID strin iceTrickle: manager.config.ICETrickle, } + connection.OnNegotiationNeeded(func() { + logger.Warn().Msg("negotiation is needed") + + offer, err := peer.CreateOffer(false) + if err != nil { + logger.Err(err).Msg("sdp offer failed") + return + } + + session.Send( + event.SIGNAL_OFFER, + message.SignalDescription{ + SDP: offer.SDP, + }) + }) + connection.OnConnectionStateChange(func(state webrtc.PeerConnectionState) { switch state { case webrtc.PeerConnectionStateConnected: