neko/internal/webrtc/peer.go

29 lines
687 B
Go
Raw Normal View History

package webrtc
import (
"github.com/pion/webrtc/v2"
)
2020-11-26 06:41:40 +13:00
type WebRTCPeerCtx struct {
api *webrtc.API
engine *webrtc.MediaEngine
settings *webrtc.SettingEngine
connection *webrtc.PeerConnection
configuration *webrtc.Configuration
}
2020-11-26 06:41:40 +13:00
func (webrtc_peer *WebRTCPeerCtx) SignalAnswer(sdp string) error {
return webrtc_peer.connection.SetRemoteDescription(webrtc.SessionDescription{
2020-11-02 04:09:48 +13:00
SDP: sdp,
Type: webrtc.SDPTypeAnswer,
})
}
2020-11-26 06:41:40 +13:00
func (webrtc_peer *WebRTCPeerCtx) Destroy() error {
if webrtc_peer.connection == nil || webrtc_peer.connection.ConnectionState() != webrtc.PeerConnectionStateConnected {
2020-11-02 04:09:48 +13:00
return nil
}
2020-11-02 04:09:48 +13:00
2020-11-26 06:41:40 +13:00
return webrtc_peer.connection.Close()
}