mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
71 lines
1.7 KiB
Go
71 lines
1.7 KiB
Go
package handler
|
|
|
|
import (
|
|
"demodesk/neko/internal/types"
|
|
"demodesk/neko/internal/types/event"
|
|
"demodesk/neko/internal/types/message"
|
|
)
|
|
|
|
func (h *MessageHandlerCtx) signalRequest(session types.Session) error {
|
|
if !session.Profile().CanWatch {
|
|
h.logger.Debug().Str("session_id", session.ID()).Msg("not allowed to watch")
|
|
return nil
|
|
}
|
|
|
|
videos := h.capture.VideoIDs()
|
|
defaultVideo := videos[0]
|
|
|
|
offer, err := h.webrtc.CreatePeer(session, defaultVideo)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return session.Send(
|
|
message.SignalProvide{
|
|
Event: event.SIGNAL_PROVIDE,
|
|
SDP: offer.SDP,
|
|
ICEServers: h.webrtc.ICEServers(),
|
|
Videos: videos,
|
|
Video: defaultVideo,
|
|
})
|
|
}
|
|
|
|
func (h *MessageHandlerCtx) signalAnswer(session types.Session, payload *message.SignalAnswer) error {
|
|
peer := session.GetWebRTCPeer()
|
|
if peer == nil {
|
|
h.logger.Debug().Str("session_id", session.ID()).Msg("webRTC peer does not exist")
|
|
return nil
|
|
}
|
|
|
|
return peer.SignalAnswer(payload.SDP)
|
|
}
|
|
|
|
func (h *MessageHandlerCtx) signalCandidate(session types.Session, payload *message.SignalCandidate) error {
|
|
peer := session.GetWebRTCPeer()
|
|
if peer == nil {
|
|
h.logger.Debug().Str("session_id", session.ID()).Msg("webRTC peer does not exist")
|
|
return nil
|
|
}
|
|
|
|
return peer.SignalCandidate(*payload.ICECandidateInit)
|
|
}
|
|
|
|
func (h *MessageHandlerCtx) signalVideo(session types.Session, payload *message.SignalVideo) error {
|
|
peer := session.GetWebRTCPeer()
|
|
if peer == nil {
|
|
h.logger.Debug().Str("session_id", session.ID()).Msg("webRTC peer does not exist")
|
|
return nil
|
|
}
|
|
|
|
err := peer.SetVideoID(payload.Video)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return session.Send(
|
|
message.SignalVideo{
|
|
Event: event.SIGNAL_VIDEO,
|
|
Video: payload.Video,
|
|
})
|
|
}
|