LeaveRequest changes. (#2426)
Reworking this a bit 1. Send leave whenever the signal channel is closed to induce a resume. 2. Use a getter to get regions rather than setting.
This commit is contained in:
+6
-59
@@ -120,6 +120,7 @@ type ParticipantParams struct {
|
||||
AllowUDPUnstableFallback bool
|
||||
TURNSEnabled bool
|
||||
GetParticipantInfo func(pID livekit.ParticipantID) *livekit.ParticipantInfo
|
||||
GetRegionSettings func(ip string) *livekit.RegionSettings
|
||||
DisableSupervisor bool
|
||||
ReconnectOnPublicationError bool
|
||||
ReconnectOnSubscriptionError bool
|
||||
@@ -221,8 +222,6 @@ type ParticipantImpl struct {
|
||||
// loggers for publisher and subscriber
|
||||
pubLogger logger.Logger
|
||||
subLogger logger.Logger
|
||||
|
||||
regionSettings *livekit.RegionSettings
|
||||
}
|
||||
|
||||
func NewParticipant(params ParticipantParams) (*ParticipantImpl, error) {
|
||||
@@ -766,35 +765,8 @@ func (p *ParticipantImpl) Close(sendLeave bool, reason types.ParticipantCloseRea
|
||||
p.clearDisconnectTimer()
|
||||
p.clearMigrationTimer()
|
||||
|
||||
// send leave message
|
||||
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: leave,
|
||||
},
|
||||
})
|
||||
if sendLeave {
|
||||
p.sendLeaveRequest(reason, isExpectedToResume, false)
|
||||
}
|
||||
|
||||
if p.supervisor != nil {
|
||||
@@ -870,6 +842,7 @@ func (p *ParticipantImpl) MaybeStartMigration(force bool, onStart func()) bool {
|
||||
onStart()
|
||||
}
|
||||
|
||||
p.sendLeaveRequest(types.ParticipantCloseReasonMigrationRequested, true, false)
|
||||
p.CloseSignalConnection(types.SignallingCloseReasonMigration)
|
||||
|
||||
//
|
||||
@@ -1533,6 +1506,7 @@ func (p *ParticipantImpl) setupDisconnectTimer() {
|
||||
|
||||
func (p *ParticipantImpl) onAnyTransportFailed() {
|
||||
// clients support resuming of connections when websocket becomes disconnected
|
||||
p.sendLeaveRequest(types.ParticipantCloseReasonPeerConnectionDisconnected, true, false)
|
||||
p.CloseSignalConnection(types.SignallingCloseReasonTransportFailure)
|
||||
|
||||
// detect when participant has actually left.
|
||||
@@ -2355,28 +2329,7 @@ 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: leave,
|
||||
},
|
||||
})
|
||||
p.sendLeaveRequest(reason, false, true)
|
||||
|
||||
scr := types.SignallingCloseReasonUnknown
|
||||
switch reason {
|
||||
@@ -2538,9 +2491,3 @@ 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()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user