neko/internal/websocket/handler/signal.go

71 lines
1.6 KiB
Go
Raw Normal View History

2020-11-02 04:09:48 +13:00
package handler
import (
2020-10-29 07:15:48 +13:00
"demodesk/neko/internal/types"
"demodesk/neko/internal/types/event"
"demodesk/neko/internal/types/message"
)
2020-12-01 06:27:25 +13:00
func (h *MessageHandlerCtx) signalRequest(session types.Session) error {
2021-03-14 12:45:51 +13:00
if !session.Profile().CanWatch {
2020-12-07 06:49:20 +13:00
return nil
}
2021-02-08 05:07:55 +13:00
videos := h.capture.VideoIDs()
defaultVideo := videos[0]
offer, err := h.webrtc.CreatePeer(session, defaultVideo)
if err != nil {
return err
}
2020-11-19 08:30:33 +13:00
return session.Send(
message.SignalProvide{
2021-02-08 04:52:30 +13:00
Event: event.SIGNAL_PROVIDE,
SDP: offer.SDP,
Lite: h.webrtc.ICELite(),
ICE: h.webrtc.ICEServers(),
2021-02-08 05:07:55 +13:00
Videos: videos,
Video: defaultVideo,
2020-11-19 08:30:33 +13:00
})
}
2020-11-02 04:09:48 +13:00
func (h *MessageHandlerCtx) signalAnswer(session types.Session, payload *message.SignalAnswer) error {
2021-02-06 06:14:45 +13:00
peer := session.GetWebRTCPeer()
if peer == nil {
h.logger.Debug().Msg("webRTC peer does not exist")
return nil
}
return peer.SignalAnswer(payload.SDP)
}
2021-02-03 08:43:33 +13:00
func (h *MessageHandlerCtx) signalCandidate(session types.Session, payload *message.SignalCandidate) error {
2021-02-06 06:14:45 +13:00
peer := session.GetWebRTCPeer()
if peer == nil {
h.logger.Debug().Msg("webRTC peer does not exist")
return nil
}
return peer.SignalCandidate(*payload.ICECandidateInit)
2021-02-03 08:43:33 +13:00
}
2021-02-06 08:35:30 +13:00
func (h *MessageHandlerCtx) signalVideo(session types.Session, payload *message.SignalVideo) error {
peer := session.GetWebRTCPeer()
if peer == nil {
h.logger.Debug().Msg("webRTC peer does not exist")
return nil
}
2021-02-08 05:29:40 +13:00
err := peer.SetVideoID(payload.Video)
if err != nil {
return err
}
return session.Send(
message.SignalVideo{
2021-02-15 02:40:17 +13:00
Event: event.SIGNAL_VIDEO,
Video: payload.Video,
2021-02-08 05:29:40 +13:00
})
2021-02-06 08:35:30 +13:00
}