Augment LeaveRequest with alternate regions to connect. (#2408)

* Augment LeaveRequest with alternate regions to connect.

* update protocol and issue resume action on close if expected to resume

* use current protocol in tests

* address feedback
This commit is contained in:
Raja Subramanian
2024-01-25 22:22:46 +05:30
committed by GitHub
parent 43a40eb52d
commit d3da94c45e
9 changed files with 146 additions and 347 deletions
+51 -10
View File
@@ -221,6 +221,8 @@ type ParticipantImpl struct {
// loggers for publisher and subscriber
pubLogger logger.Logger
subLogger logger.Logger
regionSettings *livekit.RegionSettings
}
func NewParticipant(params ParticipantParams) (*ParticipantImpl, error) {
@@ -582,8 +584,7 @@ func (p *ParticipantImpl) HandleSignalSourceClose() {
p.TransportManager.SetSignalSourceValid(false)
if !p.HasConnected() {
reason := types.ParticipantCloseReasonJoinFailed
_ = p.Close(false, reason, false)
_ = p.Close(false, types.ParticipantCloseReasonSignalSourceClose, false)
}
}
@@ -749,12 +750,32 @@ func (p *ParticipantImpl) Close(sendLeave bool, reason types.ParticipantCloseRea
p.clearMigrationTimer()
// send leave message
if sendLeave {
var leave *livekit.LeaveRequest
if p.ProtocolVersion().SupportsRegionsInLeaveRequest() {
leave = &livekit.LeaveRequest{
Reason: reason.ToDisconnectReason(),
}
if isExpectedToResume {
leave.Action = livekit.LeaveRequest_RESUME
} else {
leave.Action = livekit.LeaveRequest_DISCONNECT
}
// although regions are not needed when resuming OR disconnecting,
// send it if available, just in case clients want to fall back.
p.lock.RLock()
if p.regionSettings != nil {
leave.Regions = proto.Clone(p.regionSettings).(*livekit.RegionSettings)
}
p.lock.RUnlock()
} else if sendLeave {
leave = &livekit.LeaveRequest{
Reason: reason.ToDisconnectReason(),
}
}
if leave != nil {
_ = p.writeMessage(&livekit.SignalResponse{
Message: &livekit.SignalResponse_Leave{
Leave: &livekit.LeaveRequest{
Reason: reason.ToDisconnectReason(),
},
Leave: leave,
},
})
}
@@ -2282,12 +2303,26 @@ func (p *ParticipantImpl) GetCachedDownTrack(trackID livekit.TrackID) (*webrtc.R
}
func (p *ParticipantImpl) IssueFullReconnect(reason types.ParticipantCloseReason) {
var leave *livekit.LeaveRequest
if p.ProtocolVersion().SupportsRegionsInLeaveRequest() {
leave = &livekit.LeaveRequest{
Reason: reason.ToDisconnectReason(),
Action: livekit.LeaveRequest_RECONNECT,
}
p.lock.RLock()
if p.regionSettings != nil {
leave.Regions = proto.Clone(p.regionSettings).(*livekit.RegionSettings)
}
p.lock.RUnlock()
} else {
leave = &livekit.LeaveRequest{
CanReconnect: true,
Reason: reason.ToDisconnectReason(),
}
}
_ = p.writeMessage(&livekit.SignalResponse{
Message: &livekit.SignalResponse_Leave{
Leave: &livekit.LeaveRequest{
CanReconnect: true,
Reason: reason.ToDisconnectReason(),
},
Leave: leave,
},
})
@@ -2451,3 +2486,9 @@ func (p *ParticipantImpl) setupEnabledCodecs(publishEnabledCodecs []*livekit.Cod
}
p.enabledSubscribeCodecs = subscribeCodecs
}
func (p *ParticipantImpl) SetRegionSettings(regionSettings *livekit.RegionSettings) {
p.lock.Lock()
p.regionSettings = proto.Clone(regionSettings).(*livekit.RegionSettings)
p.lock.Unlock()
}