mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
peer -> webrtc_peer.
This commit is contained in:
parent
ff7efe9f3b
commit
b73e2403af
@ -16,7 +16,7 @@ type SessionCtx struct {
|
|||||||
connected bool
|
connected bool
|
||||||
manager *SessionManagerCtx
|
manager *SessionManagerCtx
|
||||||
websocket_peer types.WebSocketPeer
|
websocket_peer types.WebSocketPeer
|
||||||
peer types.Peer
|
webrtc_peer types.WebRTCPeer
|
||||||
}
|
}
|
||||||
|
|
||||||
func (session *SessionCtx) ID() string {
|
func (session *SessionCtx) ID() string {
|
||||||
@ -48,8 +48,8 @@ func (session *SessionCtx) SetWebSocketPeer(websocket_peer types.WebSocketPeer)
|
|||||||
session.manager.emmiter.Emit("created", session)
|
session.manager.emmiter.Emit("created", session)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (session *SessionCtx) SetPeer(peer types.Peer) {
|
func (session *SessionCtx) SetWebRTCPeer(webrtc_peer types.WebRTCPeer) {
|
||||||
session.peer = peer
|
session.webrtc_peer = webrtc_peer
|
||||||
}
|
}
|
||||||
|
|
||||||
func (session *SessionCtx) SetConnected(connected bool) {
|
func (session *SessionCtx) SetConnected(connected bool) {
|
||||||
@ -85,11 +85,11 @@ func (session *SessionCtx) Send(v interface{}) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (session *SessionCtx) SignalAnswer(sdp string) error {
|
func (session *SessionCtx) SignalAnswer(sdp string) error {
|
||||||
if session.peer == nil {
|
if session.webrtc_peer == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return session.peer.SignalAnswer(sdp)
|
return session.webrtc_peer.SignalAnswer(sdp)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (session *SessionCtx) destroy() error {
|
func (session *SessionCtx) destroy() error {
|
||||||
@ -99,8 +99,8 @@ func (session *SessionCtx) destroy() error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if session.peer != nil {
|
if session.webrtc_peer != nil {
|
||||||
if err := session.peer.Destroy(); err != nil {
|
if err := session.webrtc_peer.Destroy(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ type Session interface {
|
|||||||
Connected() bool
|
Connected() bool
|
||||||
SetName(name string)
|
SetName(name string)
|
||||||
SetWebSocketPeer(websocket_peer WebSocketPeer)
|
SetWebSocketPeer(websocket_peer WebSocketPeer)
|
||||||
SetPeer(peer Peer)
|
SetWebRTCPeer(webrtc_peer WebRTCPeer)
|
||||||
SetConnected(connected bool)
|
SetConnected(connected bool)
|
||||||
Disconnect(reason string) error
|
Disconnect(reason string) error
|
||||||
Send(v interface{}) error
|
Send(v interface{}) error
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
package types
|
package types
|
||||||
|
|
||||||
|
type WebRTCPeer interface {
|
||||||
|
SignalAnswer(sdp string) error
|
||||||
|
Destroy() error
|
||||||
|
}
|
||||||
|
|
||||||
type WebRTCManager interface {
|
type WebRTCManager interface {
|
||||||
Start()
|
Start()
|
||||||
Shutdown() error
|
Shutdown() error
|
||||||
CreatePeer(session Session) (string, bool, []string, error)
|
CreatePeer(session Session) (string, bool, []string, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type Peer interface {
|
|
||||||
SignalAnswer(sdp string) error
|
|
||||||
Destroy() error
|
|
||||||
}
|
|
||||||
|
@ -163,7 +163,7 @@ func (manager *WebRTCManagerCtx) CreatePeer(session types.Session) (string, bool
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
session.SetPeer(&PeerCtx{
|
session.SetWebRTCPeer(&WebRTCPeerCtx{
|
||||||
api: api,
|
api: api,
|
||||||
engine: &engine,
|
engine: &engine,
|
||||||
settings: &settings,
|
settings: &settings,
|
||||||
|
@ -4,7 +4,7 @@ import (
|
|||||||
"github.com/pion/webrtc/v2"
|
"github.com/pion/webrtc/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
type PeerCtx struct {
|
type WebRTCPeerCtx struct {
|
||||||
api *webrtc.API
|
api *webrtc.API
|
||||||
engine *webrtc.MediaEngine
|
engine *webrtc.MediaEngine
|
||||||
settings *webrtc.SettingEngine
|
settings *webrtc.SettingEngine
|
||||||
@ -12,17 +12,17 @@ type PeerCtx struct {
|
|||||||
configuration *webrtc.Configuration
|
configuration *webrtc.Configuration
|
||||||
}
|
}
|
||||||
|
|
||||||
func (peer *PeerCtx) SignalAnswer(sdp string) error {
|
func (webrtc_peer *WebRTCPeerCtx) SignalAnswer(sdp string) error {
|
||||||
return peer.connection.SetRemoteDescription(webrtc.SessionDescription{
|
return webrtc_peer.connection.SetRemoteDescription(webrtc.SessionDescription{
|
||||||
SDP: sdp,
|
SDP: sdp,
|
||||||
Type: webrtc.SDPTypeAnswer,
|
Type: webrtc.SDPTypeAnswer,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (peer *PeerCtx) Destroy() error {
|
func (webrtc_peer *WebRTCPeerCtx) Destroy() error {
|
||||||
if peer.connection == nil || peer.connection.ConnectionState() != webrtc.PeerConnectionStateConnected {
|
if webrtc_peer.connection == nil || webrtc_peer.connection.ConnectionState() != webrtc.PeerConnectionStateConnected {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return peer.connection.Close()
|
return webrtc_peer.connection.Close()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user