peer -> webrtc_peer.

This commit is contained in:
Miroslav Šedivý 2020-11-25 18:41:40 +01:00
parent ff7efe9f3b
commit b73e2403af
5 changed files with 20 additions and 20 deletions

View File

@ -16,7 +16,7 @@ type SessionCtx struct {
connected bool
manager *SessionManagerCtx
websocket_peer types.WebSocketPeer
peer types.Peer
webrtc_peer types.WebRTCPeer
}
func (session *SessionCtx) ID() string {
@ -48,8 +48,8 @@ func (session *SessionCtx) SetWebSocketPeer(websocket_peer types.WebSocketPeer)
session.manager.emmiter.Emit("created", session)
}
func (session *SessionCtx) SetPeer(peer types.Peer) {
session.peer = peer
func (session *SessionCtx) SetWebRTCPeer(webrtc_peer types.WebRTCPeer) {
session.webrtc_peer = webrtc_peer
}
func (session *SessionCtx) SetConnected(connected bool) {
@ -85,11 +85,11 @@ func (session *SessionCtx) Send(v interface{}) error {
}
func (session *SessionCtx) SignalAnswer(sdp string) error {
if session.peer == nil {
if session.webrtc_peer == nil {
return nil
}
return session.peer.SignalAnswer(sdp)
return session.webrtc_peer.SignalAnswer(sdp)
}
func (session *SessionCtx) destroy() error {
@ -99,8 +99,8 @@ func (session *SessionCtx) destroy() error {
}
}
if session.peer != nil {
if err := session.peer.Destroy(); err != nil {
if session.webrtc_peer != nil {
if err := session.webrtc_peer.Destroy(); err != nil {
return err
}
}

View File

@ -10,7 +10,7 @@ type Session interface {
Connected() bool
SetName(name string)
SetWebSocketPeer(websocket_peer WebSocketPeer)
SetPeer(peer Peer)
SetWebRTCPeer(webrtc_peer WebRTCPeer)
SetConnected(connected bool)
Disconnect(reason string) error
Send(v interface{}) error

View File

@ -1,12 +1,12 @@
package types
type WebRTCPeer interface {
SignalAnswer(sdp string) error
Destroy() error
}
type WebRTCManager interface {
Start()
Shutdown() error
CreatePeer(session Session) (string, bool, []string, error)
}
type Peer interface {
SignalAnswer(sdp string) error
Destroy() error
}

View File

@ -163,7 +163,7 @@ func (manager *WebRTCManagerCtx) CreatePeer(session types.Session) (string, bool
}
})
session.SetPeer(&PeerCtx{
session.SetWebRTCPeer(&WebRTCPeerCtx{
api: api,
engine: &engine,
settings: &settings,

View File

@ -4,7 +4,7 @@ import (
"github.com/pion/webrtc/v2"
)
type PeerCtx struct {
type WebRTCPeerCtx struct {
api *webrtc.API
engine *webrtc.MediaEngine
settings *webrtc.SettingEngine
@ -12,17 +12,17 @@ type PeerCtx struct {
configuration *webrtc.Configuration
}
func (peer *PeerCtx) SignalAnswer(sdp string) error {
return peer.connection.SetRemoteDescription(webrtc.SessionDescription{
func (webrtc_peer *WebRTCPeerCtx) SignalAnswer(sdp string) error {
return webrtc_peer.connection.SetRemoteDescription(webrtc.SessionDescription{
SDP: sdp,
Type: webrtc.SDPTypeAnswer,
})
}
func (peer *PeerCtx) Destroy() error {
if peer.connection == nil || peer.connection.ConnectionState() != webrtc.PeerConnectionStateConnected {
func (webrtc_peer *WebRTCPeerCtx) Destroy() error {
if webrtc_peer.connection == nil || webrtc_peer.connection.ConnectionState() != webrtc.PeerConnectionStateConnected {
return nil
}
return peer.connection.Close()
return webrtc_peer.connection.Close()
}