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
/////////////////////////////
type SystemWebRTC struct {
Event string `json:"event,omitempty"`
Videos []string `json:"videos"`
}
type SystemInit struct {
Event string `json:"event,omitempty"`
SessionId string `json:"session_id"`
@ -22,6 +27,7 @@ type SystemInit struct {
ScreenSize ScreenSize `json:"screen_size"`
Sessions map[string]SessionData `json:"sessions"`
ImplicitHosting bool `json:"implicit_hosting"`
WebRTC SystemWebRTC `json:"webrtc"`
}
type SystemAdmin struct {
@ -43,7 +49,6 @@ type SignalProvide struct {
Event string `json:"event,omitempty"`
SDP string `json:"sdp"`
ICEServers []types.ICEServer `json:"iceservers"`
Videos []string `json:"videos"`
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
video, ok := manager.capture.Video(videoID)
if !ok {
return nil, fmt.Errorf("default video track not found")
return nil, fmt.Errorf("selected video track not found")
}
videoCodec := video.Codec()

View File

@ -48,7 +48,10 @@ func (h *MessageHandlerCtx) Message(session types.Session, raw []byte) bool {
switch header.Event {
// Signal Events
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:
payload := &message.SignalAnswer{}
err = utils.Unmarshal(payload, raw, func() error {

View File

@ -6,16 +6,19 @@ import (
"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 {
h.logger.Debug().Str("session_id", session.ID()).Msg("not allowed to watch")
return nil
}
// use default first video, if not provided
if payload.Video == "" {
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 {
return err
}
@ -25,8 +28,7 @@ func (h *MessageHandlerCtx) signalRequest(session types.Session) error {
Event: event.SIGNAL_PROVIDE,
SDP: offer.SDP,
ICEServers: h.webrtc.ICEServers(),
Videos: videos,
Video: defaultVideo,
Video: payload.Video,
})
}

View File

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