2020-10-23 03:54:50 +13:00
|
|
|
package webrtc
|
|
|
|
|
2021-02-03 07:21:48 +13:00
|
|
|
import "github.com/pion/webrtc/v3"
|
2020-10-23 03:54:50 +13:00
|
|
|
|
2020-11-26 06:41:40 +13:00
|
|
|
type WebRTCPeerCtx struct {
|
2021-02-05 09:39:48 +13:00
|
|
|
api *webrtc.API
|
|
|
|
engine *webrtc.MediaEngine
|
|
|
|
settings *webrtc.SettingEngine
|
|
|
|
connection *webrtc.PeerConnection
|
|
|
|
configuration *webrtc.Configuration
|
|
|
|
audioTransceiver *webrtc.RTPTransceiver
|
|
|
|
videoTransceiver *webrtc.RTPTransceiver
|
2020-10-23 03:54:50 +13:00
|
|
|
}
|
|
|
|
|
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-10-23 03:54:50 +13:00
|
|
|
}
|
|
|
|
|
2021-02-03 08:43:33 +13:00
|
|
|
func (webrtc_peer *WebRTCPeerCtx) SignalCandidate(candidate webrtc.ICECandidateInit) error {
|
|
|
|
return webrtc_peer.connection.AddICECandidate(candidate)
|
|
|
|
}
|
|
|
|
|
2021-02-05 09:39:48 +13:00
|
|
|
func (webrtc_peer *WebRTCPeerCtx) ReplaceAudioTrack(track webrtc.TrackLocal) error {
|
|
|
|
return webrtc_peer.audioTransceiver.Sender().ReplaceTrack(track)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (webrtc_peer *WebRTCPeerCtx) ReplaceVideoTrack(track webrtc.TrackLocal) error {
|
|
|
|
return webrtc_peer.videoTransceiver.Sender().ReplaceTrack(track)
|
|
|
|
}
|
|
|
|
|
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-10-23 03:54:50 +13:00
|
|
|
}
|
2021-02-03 06:28:32 +13:00
|
|
|
|
2020-11-26 06:41:40 +13:00
|
|
|
return webrtc_peer.connection.Close()
|
2020-10-23 03:54:50 +13:00
|
|
|
}
|