Big rewrite for WebRTC processing

This commit is contained in:
Alexey Khit
2023-02-25 17:10:45 +03:00
parent ad3c5440fe
commit 218eea6806
10 changed files with 625 additions and 253 deletions
+34
View File
@@ -0,0 +1,34 @@
package webrtc
import "github.com/pion/webrtc/v3"
func (c *Conn) CreateOffer() (string, error) {
init := webrtc.RTPTransceiverInit{Direction: webrtc.RTPTransceiverDirectionRecvonly}
_, _ = c.pc.AddTransceiverFromKind(webrtc.RTPCodecTypeVideo, init)
_, _ = c.pc.AddTransceiverFromKind(webrtc.RTPCodecTypeAudio, init)
desc, err := c.pc.CreateOffer(nil)
if err != nil {
return "", err
}
if err = c.pc.SetLocalDescription(desc); err != nil {
return "", err
}
return desc.SDP, nil
}
func (c *Conn) CreateCompleteOffer() (string, error) {
if _, err := c.CreateOffer(); err != nil {
return "", err
}
<-webrtc.GatheringCompletePromise(c.pc)
return c.pc.LocalDescription().SDP, nil
}
func (c *Conn) SetAnswer(answer string) (err error) {
desc := webrtc.SessionDescription{SDP: answer, Type: webrtc.SDPTypeAnswer}
return c.pc.SetRemoteDescription(desc)
}