neko/server/internal/websocket/handler/signal.go

52 lines
1.2 KiB
Go
Raw Permalink Normal View History

2022-09-13 08:36:56 +12:00
package handler
2020-02-13 12:13:33 +13:00
import (
2021-10-06 09:38:24 +13:00
"m1k1o/neko/internal/types"
"m1k1o/neko/internal/types/event"
"m1k1o/neko/internal/types/message"
2020-02-13 12:13:33 +13:00
)
func (h *MessageHandler) signalProvide(id string, session types.Session) error {
2021-12-03 11:43:36 +13:00
peer, err := h.webrtc.CreatePeer(id, session)
if err != nil {
return err
}
sdp, err := peer.CreateOffer()
2020-02-13 12:13:33 +13:00
if err != nil {
return err
}
if err := session.Send(message.SignalProvide{
Event: event.SIGNAL_PROVIDE,
ID: id,
SDP: sdp,
2021-12-03 11:43:36 +13:00
Lite: h.webrtc.ICELite(),
ICE: h.webrtc.ICEServers(),
2020-02-13 12:13:33 +13:00
}); err != nil {
return err
}
return nil
}
2021-12-03 11:43:36 +13:00
func (h *MessageHandler) signalRemoteOffer(id string, session types.Session, payload *message.SignalOffer) error {
return session.SignalRemoteOffer(payload.SDP)
}
func (h *MessageHandler) signalRemoteAnswer(id string, session types.Session, payload *message.SignalAnswer) error {
2020-04-05 13:33:19 +12:00
if err := session.SetName(payload.DisplayName); err != nil {
2020-02-13 12:13:33 +13:00
return err
}
2021-12-03 11:43:36 +13:00
if err := session.SignalRemoteAnswer(payload.SDP); err != nil {
2020-02-13 12:13:33 +13:00
return err
}
return nil
}
2023-03-18 12:49:25 +13:00
func (h *MessageHandler) signalRemoteCandidate(id string, session types.Session, payload *message.SignalCandidate) error {
return session.SignalRemoteCandidate(payload.Data)
}