Add Id to SDP signalling messages. (#3722)
* Add Id to SDP signalling messages. Allows matching up offer/answer. For now, the subscriber answer just logs if there is a mismatch. * correct variable name * test * fixing rid * revert * clean up
This commit is contained in:
+11
-11
@@ -318,7 +318,7 @@ func NewRTCClient(conn *websocket.Conn, opts *Options) (*RTCClient, error) {
|
||||
logger.Debugw("subscriber fully established", "participant", c.localParticipant.Identity, "pID", c.localParticipant.Sid)
|
||||
c.subscriberFullyEstablished.Store(true)
|
||||
})
|
||||
subscriberHandler.OnAnswerCalls(func(answer webrtc.SessionDescription) error {
|
||||
subscriberHandler.OnAnswerCalls(func(answer webrtc.SessionDescription, answerId uint32) error {
|
||||
// send remote an answer
|
||||
logger.Infow("sending subscriber answer",
|
||||
"participant", c.localParticipant.Identity,
|
||||
@@ -326,7 +326,7 @@ func NewRTCClient(conn *websocket.Conn, opts *Options) (*RTCClient, error) {
|
||||
)
|
||||
return c.SendRequest(&livekit.SignalRequest{
|
||||
Message: &livekit.SignalRequest_Answer{
|
||||
Answer: rtc.ToProtoSessionDescription(answer),
|
||||
Answer: rtc.ToProtoSessionDescription(answer, answerId),
|
||||
},
|
||||
})
|
||||
})
|
||||
@@ -355,7 +355,7 @@ func (c *RTCClient) Run() error {
|
||||
// run the session
|
||||
for {
|
||||
res, err := c.ReadResponse()
|
||||
if errors.Is(io.EOF, err) {
|
||||
if errors.Is(err, io.EOF) {
|
||||
return nil
|
||||
} else if err != nil {
|
||||
logger.Errorw("error while reading", err)
|
||||
@@ -400,8 +400,8 @@ func (c *RTCClient) handleSignalResponse(res *livekit.SignalResponse) error {
|
||||
logger.Infow("received server offer",
|
||||
"participant", c.localParticipant.Identity,
|
||||
)
|
||||
desc := rtc.FromProtoSessionDescription(msg.Offer)
|
||||
c.handleOffer(desc)
|
||||
desc, offerId := rtc.FromProtoSessionDescription(msg.Offer)
|
||||
c.handleOffer(desc, offerId)
|
||||
case *livekit.SignalResponse_Trickle:
|
||||
candidateInit, err := rtc.FromProtoTrickle(msg.Trickle)
|
||||
if err != nil {
|
||||
@@ -827,26 +827,26 @@ func (c *RTCClient) handleDataMessageUnlabeled(data []byte) {
|
||||
}
|
||||
|
||||
// handles a server initiated offer, handle on subscriber PC
|
||||
func (c *RTCClient) handleOffer(desc webrtc.SessionDescription) {
|
||||
c.subscriber.HandleRemoteDescription(desc)
|
||||
func (c *RTCClient) handleOffer(desc webrtc.SessionDescription, offerId uint32) {
|
||||
c.subscriber.HandleRemoteDescription(desc, offerId)
|
||||
}
|
||||
|
||||
// the client handles answer on the publisher PC
|
||||
func (c *RTCClient) handleAnswer(desc webrtc.SessionDescription) {
|
||||
func (c *RTCClient) handleAnswer(desc webrtc.SessionDescription, answerId uint32) {
|
||||
logger.Infow("handling server answer", "participant", c.localParticipant.Identity)
|
||||
|
||||
c.lastAnswer.Store(&desc)
|
||||
// remote answered the offer, establish connection
|
||||
c.publisher.HandleRemoteDescription(desc)
|
||||
c.publisher.HandleRemoteDescription(desc, answerId)
|
||||
}
|
||||
|
||||
func (c *RTCClient) onOffer(offer webrtc.SessionDescription) error {
|
||||
func (c *RTCClient) onOffer(offer webrtc.SessionDescription, offerId uint32) error {
|
||||
if c.localParticipant != nil {
|
||||
logger.Infow("starting negotiation", "participant", c.localParticipant.Identity)
|
||||
}
|
||||
return c.SendRequest(&livekit.SignalRequest{
|
||||
Message: &livekit.SignalRequest_Offer{
|
||||
Offer: rtc.ToProtoSessionDescription(offer),
|
||||
Offer: rtc.ToProtoSessionDescription(offer, offerId),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user