Selective send of LeaveRequest. (#2429)
Cannot send old style leave request during migration and other scenarios when client is expected to resume. The old style can only do a full reconnect or disconnect. If `CanReconnect: false` which will be the case for resume, client will disconnect. Add a parameter to selectively send leave request to older clients.
This commit is contained in:
@@ -766,7 +766,7 @@ func (p *ParticipantImpl) Close(sendLeave bool, reason types.ParticipantCloseRea
|
|||||||
p.clearMigrationTimer()
|
p.clearMigrationTimer()
|
||||||
|
|
||||||
if sendLeave {
|
if sendLeave {
|
||||||
p.sendLeaveRequest(reason, isExpectedToResume, false)
|
p.sendLeaveRequest(reason, isExpectedToResume, false, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
if p.supervisor != nil {
|
if p.supervisor != nil {
|
||||||
@@ -842,7 +842,7 @@ func (p *ParticipantImpl) MaybeStartMigration(force bool, onStart func()) bool {
|
|||||||
onStart()
|
onStart()
|
||||||
}
|
}
|
||||||
|
|
||||||
p.sendLeaveRequest(types.ParticipantCloseReasonMigrationRequested, true, false)
|
p.sendLeaveRequest(types.ParticipantCloseReasonMigrationRequested, true, false, true)
|
||||||
p.CloseSignalConnection(types.SignallingCloseReasonMigration)
|
p.CloseSignalConnection(types.SignallingCloseReasonMigration)
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -1506,7 +1506,7 @@ func (p *ParticipantImpl) setupDisconnectTimer() {
|
|||||||
|
|
||||||
func (p *ParticipantImpl) onAnyTransportFailed() {
|
func (p *ParticipantImpl) onAnyTransportFailed() {
|
||||||
// clients support resuming of connections when websocket becomes disconnected
|
// clients support resuming of connections when websocket becomes disconnected
|
||||||
p.sendLeaveRequest(types.ParticipantCloseReasonPeerConnectionDisconnected, true, false)
|
p.sendLeaveRequest(types.ParticipantCloseReasonPeerConnectionDisconnected, true, false, true)
|
||||||
p.CloseSignalConnection(types.SignallingCloseReasonTransportFailure)
|
p.CloseSignalConnection(types.SignallingCloseReasonTransportFailure)
|
||||||
|
|
||||||
// detect when participant has actually left.
|
// detect when participant has actually left.
|
||||||
@@ -2329,7 +2329,7 @@ func (p *ParticipantImpl) GetCachedDownTrack(trackID livekit.TrackID) (*webrtc.R
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *ParticipantImpl) IssueFullReconnect(reason types.ParticipantCloseReason) {
|
func (p *ParticipantImpl) IssueFullReconnect(reason types.ParticipantCloseReason) {
|
||||||
p.sendLeaveRequest(reason, false, true)
|
p.sendLeaveRequest(reason, false, true, false)
|
||||||
|
|
||||||
scr := types.SignallingCloseReasonUnknown
|
scr := types.SignallingCloseReasonUnknown
|
||||||
switch reason {
|
switch reason {
|
||||||
|
|||||||
@@ -312,7 +312,12 @@ func (p *ParticipantImpl) CloseSignalConnection(reason types.SignallingCloseReas
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *ParticipantImpl) sendLeaveRequest(reason types.ParticipantCloseReason, isExpectedToResume bool, isExpectedToReconnect bool) {
|
func (p *ParticipantImpl) sendLeaveRequest(
|
||||||
|
reason types.ParticipantCloseReason,
|
||||||
|
isExpectedToResume bool,
|
||||||
|
isExpectedToReconnect bool,
|
||||||
|
sendOnlyIfSupportingLeaveRequestWithAction bool,
|
||||||
|
) error {
|
||||||
var leave *livekit.LeaveRequest
|
var leave *livekit.LeaveRequest
|
||||||
if p.ProtocolVersion().SupportsRegionsInLeaveRequest() {
|
if p.ProtocolVersion().SupportsRegionsInLeaveRequest() {
|
||||||
leave = &livekit.LeaveRequest{
|
leave = &livekit.LeaveRequest{
|
||||||
@@ -331,14 +336,20 @@ func (p *ParticipantImpl) sendLeaveRequest(reason types.ParticipantCloseReason,
|
|||||||
leave.Regions = p.params.GetRegionSettings(p.params.ClientInfo.Address)
|
leave.Regions = p.params.GetRegionSettings(p.params.ClientInfo.Address)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
if !sendOnlyIfSupportingLeaveRequestWithAction {
|
||||||
leave = &livekit.LeaveRequest{
|
leave = &livekit.LeaveRequest{
|
||||||
CanReconnect: isExpectedToReconnect,
|
CanReconnect: isExpectedToReconnect,
|
||||||
Reason: reason.ToDisconnectReason(),
|
Reason: reason.ToDisconnectReason(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ = p.writeMessage(&livekit.SignalResponse{
|
}
|
||||||
|
if leave != nil {
|
||||||
|
return p.writeMessage(&livekit.SignalResponse{
|
||||||
Message: &livekit.SignalResponse_Leave{
|
Message: &livekit.SignalResponse_Leave{
|
||||||
Leave: leave,
|
Leave: leave,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user