mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
46 lines
873 B
Go
46 lines
873 B
Go
package websocket
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
"n.eko.moe/neko/internal/types"
|
|
"n.eko.moe/neko/internal/types/event"
|
|
"n.eko.moe/neko/internal/types/message"
|
|
)
|
|
|
|
func (h *MessageHandler) signalProvide(id string, session types.Session) error {
|
|
sdp, lite, ice, err := h.webrtc.CreatePeer(id, session)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
tmp, err := json.Marshal(ice)
|
|
if (err != nil) {
|
|
panic(err)
|
|
}
|
|
|
|
if err := session.Send(message.SignalProvide{
|
|
Event: event.SIGNAL_PROVIDE,
|
|
ID: id,
|
|
SDP: sdp,
|
|
Lite: lite,
|
|
ICE: string(tmp),
|
|
}); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (h *MessageHandler) signalAnswer(id string, session types.Session, payload *message.SignalAnswer) error {
|
|
if err := session.SetName(payload.DisplayName); err != nil {
|
|
return err
|
|
}
|
|
|
|
if err := session.SignalAnswer(payload.SDP); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|