92 lines
2.2 KiB
Go
Raw Normal View History

2020-11-01 16:09:48 +01:00
package handler
import (
2020-10-28 19:15:48 +01:00
"demodesk/neko/internal/types"
"demodesk/neko/internal/types/event"
"demodesk/neko/internal/types/message"
)
2021-04-30 14:05:07 +00:00
func (h *MessageHandlerCtx) signalRequest(session types.Session, payload *message.SignalVideo) error {
2021-03-14 00:45:51 +01:00
if !session.Profile().CanWatch {
2021-03-16 10:53:03 +01:00
h.logger.Debug().Str("session_id", session.ID()).Msg("not allowed to watch")
2020-12-06 18:49:20 +01:00
return nil
}
2021-04-30 14:05:07 +00:00
// use default first video, if not provided
if payload.Video == "" {
videos := h.capture.VideoIDs()
payload.Video = videos[0]
}
2021-02-07 17:07:55 +01:00
2021-04-30 14:05:07 +00:00
offer, err := h.webrtc.CreatePeer(session, payload.Video)
if err != nil {
return err
}
2020-11-18 20:30:33 +01:00
return session.Send(
message.SignalProvide{
2021-03-17 15:47:49 +01:00
Event: event.SIGNAL_PROVIDE,
SDP: offer.SDP,
ICEServers: h.webrtc.ICEServers(),
2021-04-30 14:05:07 +00:00
Video: payload.Video,
2020-11-18 20:30:33 +01:00
})
}
2021-06-27 22:02:05 +02:00
func (h *MessageHandlerCtx) signalRestart(session types.Session) error {
peer := session.GetWebRTCPeer()
if peer == nil {
h.logger.Debug().Str("session_id", session.ID()).Msg("webRTC peer does not exist")
return nil
}
offer, err := peer.CreateOffer(true)
2021-06-27 22:02:05 +02:00
if err != nil {
return err
}
return session.Send(
message.SignalAnswer{
Event: event.SIGNAL_RESTART,
SDP: offer.SDP,
})
}
2020-11-01 16:09:48 +01:00
func (h *MessageHandlerCtx) signalAnswer(session types.Session, payload *message.SignalAnswer) error {
2021-02-05 18:14:45 +01:00
peer := session.GetWebRTCPeer()
if peer == nil {
2021-03-16 10:53:03 +01:00
h.logger.Debug().Str("session_id", session.ID()).Msg("webRTC peer does not exist")
2021-02-05 18:14:45 +01:00
return nil
}
return peer.SignalAnswer(payload.SDP)
}
2021-02-02 20:43:33 +01:00
func (h *MessageHandlerCtx) signalCandidate(session types.Session, payload *message.SignalCandidate) error {
2021-02-05 18:14:45 +01:00
peer := session.GetWebRTCPeer()
if peer == nil {
2021-03-16 10:53:03 +01:00
h.logger.Debug().Str("session_id", session.ID()).Msg("webRTC peer does not exist")
2021-02-05 18:14:45 +01:00
return nil
}
return peer.SignalCandidate(*payload.ICECandidateInit)
2021-02-02 20:43:33 +01:00
}
2021-02-05 20:35:30 +01:00
func (h *MessageHandlerCtx) signalVideo(session types.Session, payload *message.SignalVideo) error {
peer := session.GetWebRTCPeer()
if peer == nil {
2021-03-16 10:53:03 +01:00
h.logger.Debug().Str("session_id", session.ID()).Msg("webRTC peer does not exist")
2021-02-05 20:35:30 +01:00
return nil
}
2021-02-07 17:29:40 +01:00
err := peer.SetVideoID(payload.Video)
if err != nil {
return err
}
return session.Send(
message.SignalVideo{
2021-02-14 14:40:17 +01:00
Event: event.SIGNAL_VIDEO,
Video: payload.Video,
2021-02-07 17:29:40 +01:00
})
2021-02-05 20:35:30 +01:00
}