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