neko/internal/websocket/handler/signal.go

35 lines
822 B
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 {
2020-12-07 06:49:20 +13:00
if !session.CanWatch() {
return nil
}
2021-02-03 07:21:48 +13:00
offer, err := h.webrtc.CreatePeer(session)
if err != nil {
return err
}
2020-11-19 08:30:33 +13:00
return session.Send(
message.SignalProvide{
Event: event.SIGNAL_PROVIDE,
2021-02-03 07:21:48 +13:00
SDP: offer.SDP,
Lite: h.webrtc.ICELite(),
ICE: h.webrtc.ICEServers(),
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 {
2020-11-15 04:09:00 +13:00
return session.SignalAnswer(payload.SDP)
}
2021-02-03 08:43:33 +13:00
func (h *MessageHandlerCtx) signalCandidate(session types.Session, payload *message.SignalCandidate) error {
return session.SignalCandidate(*payload.ICECandidateInit)
}