neko/internal/webrtc/peer.go

36 lines
996 B
Go
Raw Normal View History

package webrtc
import "github.com/pion/webrtc/v3"
2020-11-25 18:41:40 +01:00
type WebRTCPeerCtx struct {
2021-02-05 20:35:30 +01:00
api *webrtc.API
engine *webrtc.MediaEngine
settings *webrtc.SettingEngine
connection *webrtc.PeerConnection
configuration *webrtc.Configuration
changeVideo func(videoID string) error
}
2020-11-25 18:41:40 +01:00
func (webrtc_peer *WebRTCPeerCtx) SignalAnswer(sdp string) error {
return webrtc_peer.connection.SetRemoteDescription(webrtc.SessionDescription{
2020-11-01 16:09:48 +01:00
SDP: sdp,
Type: webrtc.SDPTypeAnswer,
})
}
2021-02-02 20:43:33 +01:00
func (webrtc_peer *WebRTCPeerCtx) SignalCandidate(candidate webrtc.ICECandidateInit) error {
return webrtc_peer.connection.AddICECandidate(candidate)
}
2021-02-05 17:57:33 +01:00
func (webrtc_peer *WebRTCPeerCtx) SetVideoID(videoID string) error {
return webrtc_peer.changeVideo(videoID)
}
2020-11-25 18:41:40 +01:00
func (webrtc_peer *WebRTCPeerCtx) Destroy() error {
if webrtc_peer.connection == nil || webrtc_peer.connection.ConnectionState() != webrtc.PeerConnectionStateConnected {
2020-11-01 16:09:48 +01:00
return nil
}
2021-02-02 18:28:32 +01:00
2020-11-25 18:41:40 +01:00
return webrtc_peer.connection.Close()
}