From 441053b7fa925bc2150074ff151c6c93d006cbd7 Mon Sep 17 00:00:00 2001 From: cnderrauber Date: Wed, 7 Sep 2022 15:56:56 +0800 Subject: [PATCH] add participant id when client reconnect (#988) --- go.mod | 2 +- go.sum | 6 ++---- pkg/routing/interfaces.go | 3 +++ pkg/service/rtcservice.go | 4 ++++ pkg/sfu/downtrack.go | 2 +- 5 files changed, 11 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index 9909c3d06..583253346 100644 --- a/go.mod +++ b/go.mod @@ -16,7 +16,7 @@ require ( github.com/gorilla/websocket v1.5.0 github.com/hashicorp/go-version v1.6.0 github.com/hashicorp/golang-lru v0.5.4 - github.com/livekit/protocol v1.0.2-0.20220906220530-df2069bbbec1 + github.com/livekit/protocol v1.0.2-0.20220907025839-ca55e87895c4 github.com/livekit/rtcscore-go v0.0.0-20220815072451-20ee10ae1995 github.com/mackerelio/go-osstat v0.2.3 github.com/magefile/mage v1.13.0 diff --git a/go.sum b/go.sum index 9c2df52d5..a12784c80 100644 --- a/go.sum +++ b/go.sum @@ -240,10 +240,8 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/lithammer/shortuuid/v3 v3.0.7 h1:trX0KTHy4Pbwo/6ia8fscyHoGA+mf1jWbPJVuvyJQQ8= github.com/lithammer/shortuuid/v3 v3.0.7/go.mod h1:vMk8ke37EmiewwolSO1NLW8vP4ZaKlRuDIi8tWWmAts= -github.com/livekit/protocol v1.0.2-0.20220831180559-284d6b27297a h1:UY0lVZdEixOguIApMxWRqLEYj7tSJDJguvzhJaPtl/Y= -github.com/livekit/protocol v1.0.2-0.20220831180559-284d6b27297a/go.mod h1:ykRtMmaq4blqGyLWWPtYkB/74JYsyK7N2DAXLGnfSa4= -github.com/livekit/protocol v1.0.2-0.20220906220530-df2069bbbec1 h1:jjykqJJ0uQ+2HBIkkC/wpdbuKyawNfy7LzGVGRXQTc4= -github.com/livekit/protocol v1.0.2-0.20220906220530-df2069bbbec1/go.mod h1:ykRtMmaq4blqGyLWWPtYkB/74JYsyK7N2DAXLGnfSa4= +github.com/livekit/protocol v1.0.2-0.20220907025839-ca55e87895c4 h1:hS766MKj69TBYAueHx2jrv8eGK9rvigARsoTveHU2D0= +github.com/livekit/protocol v1.0.2-0.20220907025839-ca55e87895c4/go.mod h1:ykRtMmaq4blqGyLWWPtYkB/74JYsyK7N2DAXLGnfSa4= github.com/livekit/rtcscore-go v0.0.0-20220815072451-20ee10ae1995 h1:vOaY2qvfLihDyeZtnGGN1Law9wRrw8BMGCr1TygTvMw= github.com/livekit/rtcscore-go v0.0.0-20220815072451-20ee10ae1995/go.mod h1:116ych8UaEs9vfIE8n6iZCZ30iagUFTls0vRmC+Ix5U= github.com/mackerelio/go-osstat v0.2.3 h1:jAMXD5erlDE39kdX2CU7YwCGRcxIO33u/p8+Fhe5dJw= diff --git a/pkg/routing/interfaces.go b/pkg/routing/interfaces.go index 9cac114af..cb1728bc2 100644 --- a/pkg/routing/interfaces.go +++ b/pkg/routing/interfaces.go @@ -38,6 +38,7 @@ type ParticipantInit struct { Grants *auth.ClaimGrants Region string AdaptiveStream bool + ID livekit.ParticipantID } type NewParticipantCallback func( @@ -119,6 +120,7 @@ func (pi *ParticipantInit) ToStartSession(roomName livekit.RoomName, connectionI Client: pi.Client, GrantsJson: string(claims), AdaptiveStream: pi.AdaptiveStream, + ParticipantId: string(pi.ID), }, nil } @@ -137,5 +139,6 @@ func ParticipantInitFromStartSession(ss *livekit.StartSession, region string) (* Grants: claims, Region: region, AdaptiveStream: ss.AdaptiveStream, + ID: livekit.ParticipantID(ss.ParticipantId), }, nil } diff --git a/pkg/service/rtcservice.go b/pkg/service/rtcservice.go index b3a4bdaa1..bdb1aedcd 100644 --- a/pkg/service/rtcservice.go +++ b/pkg/service/rtcservice.go @@ -94,6 +94,7 @@ func (s *RTCService) validate(r *http.Request) (livekit.RoomName, routing.Partic autoSubParam := r.FormValue("auto_subscribe") publishParam := r.FormValue("publish") adaptiveStreamParam := r.FormValue("adaptive_stream") + participantID := r.FormValue("sid") if onlyName != "" { roomName = onlyName @@ -129,6 +130,9 @@ func (s *RTCService) validate(r *http.Request) (livekit.RoomName, routing.Partic Grants: claims, Region: region, } + if pi.Reconnect { + pi.ID = livekit.ParticipantID(participantID) + } if autoSubParam != "" { pi.AutoSubscribe = boolValue(autoSubParam) diff --git a/pkg/sfu/downtrack.go b/pkg/sfu/downtrack.go index 96babb924..fff74e851 100644 --- a/pkg/sfu/downtrack.go +++ b/pkg/sfu/downtrack.go @@ -281,7 +281,7 @@ func (d *DownTrack) Bind(t webrtc.TrackLocalContext) (webrtc.RTPCodecParameters, return codec, nil } - d.logger.Debugw("DownTrack.Bind", "codecs", d.upstreamCodecs, "matchCodec", codec) + d.logger.Debugw("DownTrack.Bind", "codecs", d.upstreamCodecs, "matchCodec", codec, "ssrc", t.SSRC()) d.ssrc = uint32(t.SSRC()) d.payloadType = uint8(codec.PayloadType) d.writeStream = t.WriteStream()