35 lines
689 B
Go
Raw Normal View History

2020-01-24 15:47:37 +00:00
package webrtc
import (
2020-02-03 14:46:30 +00:00
"sync"
2020-01-24 15:47:37 +00:00
"github.com/pion/webrtc/v2"
)
type Peer struct {
id string
2020-02-12 23:13:33 +00:00
manager *WebRTCManager
2020-01-24 15:47:37 +00:00
connection *webrtc.PeerConnection
2020-02-03 14:46:30 +00:00
mu sync.Mutex
2020-01-24 15:47:37 +00: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 {
if peer.connection != nil && peer.connection.ConnectionState() == webrtc.PeerConnectionStateConnected {
if err := peer.connection.Close(); err != nil {
return err
}
}
return nil
}