webrtc connect with selected video.

This commit is contained in:
Miroslav Šedivý 2021-04-30 14:05:07 +00:00
parent 57deea25d4
commit 014b757734
5 changed files with 22 additions and 9 deletions

View File

@ -15,6 +15,11 @@ type Message struct {
// System // System
///////////////////////////// /////////////////////////////
type SystemWebRTC struct {
Event string `json:"event,omitempty"`
Videos []string `json:"videos"`
}
type SystemInit struct { type SystemInit struct {
Event string `json:"event,omitempty"` Event string `json:"event,omitempty"`
SessionId string `json:"session_id"` SessionId string `json:"session_id"`
@ -22,6 +27,7 @@ type SystemInit struct {
ScreenSize ScreenSize `json:"screen_size"` ScreenSize ScreenSize `json:"screen_size"`
Sessions map[string]SessionData `json:"sessions"` Sessions map[string]SessionData `json:"sessions"`
ImplicitHosting bool `json:"implicit_hosting"` ImplicitHosting bool `json:"implicit_hosting"`
WebRTC SystemWebRTC `json:"webrtc"`
} }
type SystemAdmin struct { type SystemAdmin struct {
@ -43,7 +49,6 @@ type SignalProvide struct {
Event string `json:"event,omitempty"` Event string `json:"event,omitempty"`
SDP string `json:"sdp"` SDP string `json:"sdp"`
ICEServers []types.ICEServer `json:"iceservers"` ICEServers []types.ICEServer `json:"iceservers"`
Videos []string `json:"videos"`
Video string `json:"video"` Video string `json:"video"`
} }

View File

@ -391,7 +391,7 @@ func (manager *WebRTCManagerCtx) mediaEngine(videoID string) (*webrtc.MediaEngin
// all videos must have the same codec // all videos must have the same codec
video, ok := manager.capture.Video(videoID) video, ok := manager.capture.Video(videoID)
if !ok { if !ok {
return nil, fmt.Errorf("default video track not found") return nil, fmt.Errorf("selected video track not found")
} }
videoCodec := video.Codec() videoCodec := video.Codec()

View File

@ -48,7 +48,10 @@ func (h *MessageHandlerCtx) Message(session types.Session, raw []byte) bool {
switch header.Event { switch header.Event {
// Signal Events // Signal Events
case event.SIGNAL_REQUEST: case event.SIGNAL_REQUEST:
err = h.signalRequest(session) payload := &message.SignalVideo{}
err = utils.Unmarshal(payload, raw, func() error {
return h.signalRequest(session, payload)
})
case event.SIGNAL_ANSWER: case event.SIGNAL_ANSWER:
payload := &message.SignalAnswer{} payload := &message.SignalAnswer{}
err = utils.Unmarshal(payload, raw, func() error { err = utils.Unmarshal(payload, raw, func() error {

View File

@ -6,16 +6,19 @@ import (
"demodesk/neko/internal/types/message" "demodesk/neko/internal/types/message"
) )
func (h *MessageHandlerCtx) signalRequest(session types.Session) error { func (h *MessageHandlerCtx) signalRequest(session types.Session, payload *message.SignalVideo) error {
if !session.Profile().CanWatch { if !session.Profile().CanWatch {
h.logger.Debug().Str("session_id", session.ID()).Msg("not allowed to watch") h.logger.Debug().Str("session_id", session.ID()).Msg("not allowed to watch")
return nil return nil
} }
// use default first video, if not provided
if payload.Video == "" {
videos := h.capture.VideoIDs() videos := h.capture.VideoIDs()
defaultVideo := videos[0] payload.Video = videos[0]
}
offer, err := h.webrtc.CreatePeer(session, defaultVideo) offer, err := h.webrtc.CreatePeer(session, payload.Video)
if err != nil { if err != nil {
return err return err
} }
@ -25,8 +28,7 @@ func (h *MessageHandlerCtx) signalRequest(session types.Session) error {
Event: event.SIGNAL_PROVIDE, Event: event.SIGNAL_PROVIDE,
SDP: offer.SDP, SDP: offer.SDP,
ICEServers: h.webrtc.ICEServers(), ICEServers: h.webrtc.ICEServers(),
Videos: videos, Video: payload.Video,
Video: defaultVideo,
}) })
} }

View File

@ -45,6 +45,9 @@ func (h *MessageHandlerCtx) systemInit(session types.Session) error {
}, },
Sessions: sessions, Sessions: sessions,
ImplicitHosting: h.sessions.ImplicitHosting(), ImplicitHosting: h.sessions.ImplicitHosting(),
WebRTC: message.SystemWebRTC{
Videos: h.capture.VideoIDs(),
},
}) })
} }