mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
implement signal offer.
This commit is contained in:
parent
a260ce6a60
commit
44e74e3088
@ -10,6 +10,7 @@ const (
|
||||
const (
|
||||
SIGNAL_REQUEST = "signal/request"
|
||||
SIGNAL_RESTART = "signal/restart"
|
||||
SIGNAL_OFFER = "signal/offer"
|
||||
SIGNAL_ANSWER = "signal/answer"
|
||||
SIGNAL_PROVIDE = "signal/provide"
|
||||
SIGNAL_CANDIDATE = "signal/candidate"
|
||||
|
@ -56,7 +56,7 @@ type SignalCandidate struct {
|
||||
webrtc.ICECandidateInit
|
||||
}
|
||||
|
||||
type SignalAnswer struct {
|
||||
type SignalDescription struct {
|
||||
SDP string `json:"sdp"`
|
||||
}
|
||||
|
||||
|
@ -19,6 +19,7 @@ type ICEServer struct {
|
||||
|
||||
type WebRTCPeer interface {
|
||||
CreateOffer(ICERestart bool) (*webrtc.SessionDescription, error)
|
||||
SignalOffer(sdp string) error
|
||||
SignalAnswer(sdp string) error
|
||||
SignalCandidate(candidate webrtc.ICECandidateInit) error
|
||||
|
||||
|
@ -45,6 +45,13 @@ func (peer *WebRTCPeerCtx) CreateOffer(ICERestart bool) (*webrtc.SessionDescript
|
||||
return peer.connection.LocalDescription(), nil
|
||||
}
|
||||
|
||||
func (peer *WebRTCPeerCtx) SignalOffer(sdp string) error {
|
||||
return peer.connection.SetRemoteDescription(webrtc.SessionDescription{
|
||||
SDP: sdp,
|
||||
Type: webrtc.SDPTypeOffer,
|
||||
})
|
||||
}
|
||||
|
||||
func (peer *WebRTCPeerCtx) SignalAnswer(sdp string) error {
|
||||
return peer.connection.SetRemoteDescription(webrtc.SessionDescription{
|
||||
SDP: sdp,
|
||||
|
@ -56,8 +56,13 @@ func (h *MessageHandlerCtx) Message(session types.Session, data types.WebSocketM
|
||||
})
|
||||
case event.SIGNAL_RESTART:
|
||||
err = h.signalRestart(session)
|
||||
case event.SIGNAL_OFFER:
|
||||
payload := &message.SignalDescription{}
|
||||
err = utils.Unmarshal(payload, data.Payload, func() error {
|
||||
return h.signalOffer(session, payload)
|
||||
})
|
||||
case event.SIGNAL_ANSWER:
|
||||
payload := &message.SignalAnswer{}
|
||||
payload := &message.SignalDescription{}
|
||||
err = utils.Unmarshal(payload, data.Payload, func() error {
|
||||
return h.signalAnswer(session, payload)
|
||||
})
|
||||
|
@ -48,14 +48,23 @@ func (h *MessageHandlerCtx) signalRestart(session types.Session) error {
|
||||
|
||||
session.Send(
|
||||
event.SIGNAL_RESTART,
|
||||
message.SignalAnswer{
|
||||
message.SignalDescription{
|
||||
SDP: offer.SDP,
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *MessageHandlerCtx) signalAnswer(session types.Session, payload *message.SignalAnswer) error {
|
||||
func (h *MessageHandlerCtx) signalOffer(session types.Session, payload *message.SignalDescription) error {
|
||||
peer := session.GetWebRTCPeer()
|
||||
if peer == nil {
|
||||
return errors.New("webRTC peer does not exist")
|
||||
}
|
||||
|
||||
return peer.SignalOffer(payload.SDP)
|
||||
}
|
||||
|
||||
func (h *MessageHandlerCtx) signalAnswer(session types.Session, payload *message.SignalDescription) error {
|
||||
peer := session.GetWebRTCPeer()
|
||||
if peer == nil {
|
||||
return errors.New("webRTC peer does not exist")
|
||||
|
Loading…
Reference in New Issue
Block a user