2020-01-24 15:47:37 +00:00
|
|
|
package webrtc
|
|
|
|
|
|
|
|
import (
|
2020-02-03 14:46:30 +00:00
|
|
|
"sync"
|
|
|
|
|
2021-02-14 16:30:24 +00:00
|
|
|
"github.com/pion/webrtc/v3"
|
2020-01-24 15:47:37 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type Peer struct {
|
2020-04-05 07:07:45 +00:00
|
|
|
id string
|
|
|
|
api *webrtc.API
|
|
|
|
engine *webrtc.MediaEngine
|
|
|
|
manager *WebRTCManager
|
|
|
|
settings *webrtc.SettingEngine
|
|
|
|
connection *webrtc.PeerConnection
|
|
|
|
configuration *webrtc.Configuration
|
|
|
|
mu sync.Mutex
|
2020-01-24 15:47:37 +00:00
|
|
|
}
|
|
|
|
|
2020-02-26 13:46:10 +01:00
|
|
|
func (peer *Peer) SignalAnswer(sdp string) error {
|
2020-02-12 23:13:33 +00:00
|
|
|
return peer.connection.SetRemoteDescription(webrtc.SessionDescription{SDP: sdp, Type: webrtc.SDPTypeAnswer})
|
2020-01-24 15:47:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (peer *Peer) WriteData(v interface{}) error {
|
2020-02-03 14:46:30 +00:00
|
|
|
peer.mu.Lock()
|
|
|
|
defer peer.mu.Unlock()
|
2020-01-24 15:47:37 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (peer *Peer) Destroy() error {
|
2021-03-01 01:07:31 +00:00
|
|
|
if peer.connection != nil && peer.connection.ConnectionState() != webrtc.PeerConnectionStateClosed {
|
2020-01-24 15:47:37 +00:00
|
|
|
if err := peer.connection.Close(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|