mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
register negotiation event after initial offer.
This commit is contained in:
parent
369d8f3ccf
commit
d20fa071e7
@ -38,5 +38,5 @@ type WebRTCManager interface {
|
|||||||
|
|
||||||
ICEServers() []ICEServer
|
ICEServers() []ICEServer
|
||||||
|
|
||||||
CreatePeer(session Session, videoID string) (WebRTCPeer, error)
|
CreatePeer(session Session, videoID string) (*webrtc.SessionDescription, error)
|
||||||
}
|
}
|
||||||
|
@ -117,7 +117,7 @@ func (manager *WebRTCManagerCtx) ICEServers() []types.ICEServer {
|
|||||||
return manager.config.ICEServers
|
return manager.config.ICEServers
|
||||||
}
|
}
|
||||||
|
|
||||||
func (manager *WebRTCManagerCtx) CreatePeer(session types.Session, videoID string) (types.WebRTCPeer, error) {
|
func (manager *WebRTCManagerCtx) CreatePeer(session types.Session, videoID string) (*webrtc.SessionDescription, error) {
|
||||||
// add session id to logger context
|
// add session id to logger context
|
||||||
logger := manager.logger.With().Str("session_id", session.ID()).Logger()
|
logger := manager.logger.With().Str("session_id", session.ID()).Logger()
|
||||||
logger.Info().Msg("creating webrtc peer")
|
logger.Info().Msg("creating webrtc peer")
|
||||||
@ -295,22 +295,6 @@ func (manager *WebRTCManagerCtx) CreatePeer(session types.Session, videoID strin
|
|||||||
logger.Info().Interface("data-channel", dc).Msg("got remote data channel")
|
logger.Info().Interface("data-channel", dc).Msg("got remote data channel")
|
||||||
})
|
})
|
||||||
|
|
||||||
connection.OnNegotiationNeeded(func() {
|
|
||||||
logger.Warn().Msg("negotiation is needed")
|
|
||||||
|
|
||||||
offer, err := peer.CreateOffer(false)
|
|
||||||
if err != nil {
|
|
||||||
logger.Err(err).Msg("sdp offer failed")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
session.Send(
|
|
||||||
event.SIGNAL_OFFER,
|
|
||||||
message.SignalDescription{
|
|
||||||
SDP: offer.SDP,
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
connection.OnConnectionStateChange(func(state webrtc.PeerConnectionState) {
|
connection.OnConnectionStateChange(func(state webrtc.PeerConnectionState) {
|
||||||
switch state {
|
switch state {
|
||||||
case webrtc.PeerConnectionStateConnected:
|
case webrtc.PeerConnectionStateConnected:
|
||||||
@ -370,5 +354,35 @@ func (manager *WebRTCManagerCtx) CreatePeer(session types.Session, videoID strin
|
|||||||
})
|
})
|
||||||
|
|
||||||
session.SetWebRTCPeer(peer)
|
session.SetWebRTCPeer(peer)
|
||||||
return peer, nil
|
|
||||||
|
offer, err := peer.CreateOffer(false)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// on negotiation needed handler must be registered after creating initial
|
||||||
|
// offer, otherwise it can fire and intercept sucessful negotiation
|
||||||
|
|
||||||
|
connection.OnNegotiationNeeded(func() {
|
||||||
|
logger.Warn().Msg("negotiation is needed")
|
||||||
|
|
||||||
|
if connection.SignalingState() != webrtc.SignalingStateStable {
|
||||||
|
logger.Warn().Msg("connection isn't stable yet; postponing...")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
offer, err := peer.CreateOffer(false)
|
||||||
|
if err != nil {
|
||||||
|
logger.Err(err).Msg("sdp offer failed")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
session.Send(
|
||||||
|
event.SIGNAL_OFFER,
|
||||||
|
message.SignalDescription{
|
||||||
|
SDP: offer.SDP,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
return offer, nil
|
||||||
}
|
}
|
||||||
|
@ -19,12 +19,7 @@ func (h *MessageHandlerCtx) signalRequest(session types.Session, payload *messag
|
|||||||
payload.Video = videos[0]
|
payload.Video = videos[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
peer, err := h.webrtc.CreatePeer(session, payload.Video)
|
offer, err := h.webrtc.CreatePeer(session, payload.Video)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
offer, err := peer.CreateOffer(false)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user