session GetWebRTCPeer.

This commit is contained in:
Miroslav Šedivý 2021-02-05 18:14:45 +01:00
parent 761f6d8a8f
commit c81bca9b2f
3 changed files with 18 additions and 24 deletions

View File

@ -2,7 +2,6 @@ package session
import (
"github.com/rs/zerolog"
"github.com/pion/webrtc/v3"
"demodesk/neko/internal/types"
"demodesk/neko/internal/types/event"
@ -189,18 +188,6 @@ func (session *SessionCtx) SetWebRTCConnected(connected bool) {
}
}
func (session *SessionCtx) SignalAnswer(sdp string) error {
if session.webrtc_peer == nil {
return nil
}
return session.webrtc_peer.SignalAnswer(sdp)
}
func (session *SessionCtx) SignalCandidate(candidate webrtc.ICECandidateInit) error {
if session.webrtc_peer == nil {
return nil
}
return session.webrtc_peer.SignalCandidate(candidate)
func (session *SessionCtx) GetWebRTCPeer() types.WebRTCPeer {
return session.webrtc_peer
}

View File

@ -1,10 +1,6 @@
package types
import (
"net/http"
"github.com/pion/webrtc/v3"
)
import "net/http"
type MemberProfile struct {
Secret string `json:"secret,omitempty"`
@ -61,8 +57,7 @@ type Session interface {
// webrtc
SetWebRTCPeer(webrtc_peer WebRTCPeer)
SetWebRTCConnected(connected bool)
SignalAnswer(sdp string) error
SignalCandidate(candidate webrtc.ICECandidateInit) error
GetWebRTCPeer() WebRTCPeer
}
type SessionManager interface {

View File

@ -26,9 +26,21 @@ func (h *MessageHandlerCtx) signalRequest(session types.Session) error {
}
func (h *MessageHandlerCtx) signalAnswer(session types.Session, payload *message.SignalAnswer) error {
return session.SignalAnswer(payload.SDP)
peer := session.GetWebRTCPeer()
if peer == nil {
h.logger.Debug().Msg("webRTC peer does not exist")
return nil
}
return peer.SignalAnswer(payload.SDP)
}
func (h *MessageHandlerCtx) signalCandidate(session types.Session, payload *message.SignalCandidate) error {
return session.SignalCandidate(*payload.ICECandidateInit)
peer := session.GetWebRTCPeer()
if peer == nil {
h.logger.Debug().Msg("webRTC peer does not exist")
return nil
}
return peer.SignalCandidate(*payload.ICECandidateInit)
}