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:
+51
-10
@@ -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()
|
||||
}
|
||||
|
||||
@@ -105,6 +105,7 @@ const (
|
||||
ParticipantCloseReasonSubscriptionError
|
||||
ParticipantCloseReasonDataChannelError
|
||||
ParticipantCloseReasonMigrateCodecMismatch
|
||||
ParticipantCloseReasonSignalSourceClose
|
||||
)
|
||||
|
||||
func (p ParticipantCloseReason) String() string {
|
||||
@@ -157,6 +158,8 @@ func (p ParticipantCloseReason) String() string {
|
||||
return "DATA_CHANNEL_ERROR"
|
||||
case ParticipantCloseReasonMigrateCodecMismatch:
|
||||
return "MIGRATE_CODEC_MISMATCH"
|
||||
case ParticipantCloseReasonSignalSourceClose:
|
||||
return "SIGNAL_SOURCE_CLOSE"
|
||||
default:
|
||||
return fmt.Sprintf("%d", int(p))
|
||||
}
|
||||
@@ -173,22 +176,20 @@ func (p ParticipantCloseReason) ToDisconnectReason() livekit.DisconnectReason {
|
||||
return livekit.DisconnectReason_JOIN_FAILURE
|
||||
case ParticipantCloseReasonPeerConnectionDisconnected:
|
||||
return livekit.DisconnectReason_STATE_MISMATCH
|
||||
case ParticipantCloseReasonDuplicateIdentity, ParticipantCloseReasonMigrationComplete, ParticipantCloseReasonStale:
|
||||
case ParticipantCloseReasonDuplicateIdentity, ParticipantCloseReasonStale:
|
||||
return livekit.DisconnectReason_DUPLICATE_IDENTITY
|
||||
case ParticipantCloseReasonMigrationComplete, ParticipantCloseReasonSimulateMigration:
|
||||
return livekit.DisconnectReason_MIGRATION
|
||||
case ParticipantCloseReasonServiceRequestRemoveParticipant:
|
||||
return livekit.DisconnectReason_PARTICIPANT_REMOVED
|
||||
case ParticipantCloseReasonServiceRequestDeleteRoom:
|
||||
return livekit.DisconnectReason_ROOM_DELETED
|
||||
case ParticipantCloseReasonSimulateMigration:
|
||||
return livekit.DisconnectReason_DUPLICATE_IDENTITY
|
||||
case ParticipantCloseReasonSimulateNodeFailure:
|
||||
return livekit.DisconnectReason_SERVER_SHUTDOWN
|
||||
case ParticipantCloseReasonSimulateServerLeave:
|
||||
return livekit.DisconnectReason_SERVER_SHUTDOWN
|
||||
case ParticipantCloseReasonOvercommitted:
|
||||
case ParticipantCloseReasonSimulateNodeFailure, ParticipantCloseReasonSimulateServerLeave, ParticipantCloseReasonOvercommitted:
|
||||
return livekit.DisconnectReason_SERVER_SHUTDOWN
|
||||
case ParticipantCloseReasonNegotiateFailed, ParticipantCloseReasonPublicationError, ParticipantCloseReasonSubscriptionError, ParticipantCloseReasonDataChannelError, ParticipantCloseReasonMigrateCodecMismatch:
|
||||
return livekit.DisconnectReason_STATE_MISMATCH
|
||||
case ParticipantCloseReasonSignalSourceClose:
|
||||
return livekit.DisconnectReason_SIGNAL_CLOSE
|
||||
default:
|
||||
// the other types will map to unknown reason
|
||||
return livekit.DisconnectReason_UNKNOWN_REASON
|
||||
@@ -421,6 +422,8 @@ type LocalParticipant interface {
|
||||
GetPacer() pacer.Pacer
|
||||
|
||||
GetTrafficLoad() *TrafficLoad
|
||||
|
||||
SetRegionSettings(regionSettings *livekit.RegionSettings)
|
||||
}
|
||||
|
||||
// Room is a container of participants, and can provide room-level actions
|
||||
|
||||
@@ -16,7 +16,7 @@ package types
|
||||
|
||||
type ProtocolVersion int
|
||||
|
||||
const CurrentProtocol = 12
|
||||
const CurrentProtocol = 13
|
||||
|
||||
func (v ProtocolVersion) SupportsPackedStreamId() bool {
|
||||
return v > 0
|
||||
@@ -83,3 +83,7 @@ func (v ProtocolVersion) SupportsConnectionQualityLost() bool {
|
||||
func (v ProtocolVersion) SupportsAsyncRoomID() bool {
|
||||
return v > 11
|
||||
}
|
||||
|
||||
func (v ProtocolVersion) SupportsRegionsInLeaveRequest() bool {
|
||||
return v > 12
|
||||
}
|
||||
|
||||
@@ -753,6 +753,11 @@ type FakeLocalParticipant struct {
|
||||
setPermissionReturnsOnCall map[int]struct {
|
||||
result1 bool
|
||||
}
|
||||
SetRegionSettingsStub func(*livekit.RegionSettings)
|
||||
setRegionSettingsMutex sync.RWMutex
|
||||
setRegionSettingsArgsForCall []struct {
|
||||
arg1 *livekit.RegionSettings
|
||||
}
|
||||
SetResponseSinkStub func(routing.MessageSink)
|
||||
setResponseSinkMutex sync.RWMutex
|
||||
setResponseSinkArgsForCall []struct {
|
||||
@@ -4981,6 +4986,38 @@ func (fake *FakeLocalParticipant) SetPermissionReturnsOnCall(i int, result1 bool
|
||||
}{result1}
|
||||
}
|
||||
|
||||
func (fake *FakeLocalParticipant) SetRegionSettings(arg1 *livekit.RegionSettings) {
|
||||
fake.setRegionSettingsMutex.Lock()
|
||||
fake.setRegionSettingsArgsForCall = append(fake.setRegionSettingsArgsForCall, struct {
|
||||
arg1 *livekit.RegionSettings
|
||||
}{arg1})
|
||||
stub := fake.SetRegionSettingsStub
|
||||
fake.recordInvocation("SetRegionSettings", []interface{}{arg1})
|
||||
fake.setRegionSettingsMutex.Unlock()
|
||||
if stub != nil {
|
||||
fake.SetRegionSettingsStub(arg1)
|
||||
}
|
||||
}
|
||||
|
||||
func (fake *FakeLocalParticipant) SetRegionSettingsCallCount() int {
|
||||
fake.setRegionSettingsMutex.RLock()
|
||||
defer fake.setRegionSettingsMutex.RUnlock()
|
||||
return len(fake.setRegionSettingsArgsForCall)
|
||||
}
|
||||
|
||||
func (fake *FakeLocalParticipant) SetRegionSettingsCalls(stub func(*livekit.RegionSettings)) {
|
||||
fake.setRegionSettingsMutex.Lock()
|
||||
defer fake.setRegionSettingsMutex.Unlock()
|
||||
fake.SetRegionSettingsStub = stub
|
||||
}
|
||||
|
||||
func (fake *FakeLocalParticipant) SetRegionSettingsArgsForCall(i int) *livekit.RegionSettings {
|
||||
fake.setRegionSettingsMutex.RLock()
|
||||
defer fake.setRegionSettingsMutex.RUnlock()
|
||||
argsForCall := fake.setRegionSettingsArgsForCall[i]
|
||||
return argsForCall.arg1
|
||||
}
|
||||
|
||||
func (fake *FakeLocalParticipant) SetResponseSink(arg1 routing.MessageSink) {
|
||||
fake.setResponseSinkMutex.Lock()
|
||||
fake.setResponseSinkArgsForCall = append(fake.setResponseSinkArgsForCall, struct {
|
||||
@@ -6343,6 +6380,8 @@ func (fake *FakeLocalParticipant) Invocations() map[string][][]interface{} {
|
||||
defer fake.setNameMutex.RUnlock()
|
||||
fake.setPermissionMutex.RLock()
|
||||
defer fake.setPermissionMutex.RUnlock()
|
||||
fake.setRegionSettingsMutex.RLock()
|
||||
defer fake.setRegionSettingsMutex.RUnlock()
|
||||
fake.setResponseSinkMutex.RLock()
|
||||
defer fake.setResponseSinkMutex.RUnlock()
|
||||
fake.setSignalSourceValidMutex.RLock()
|
||||
|
||||
Reference in New Issue
Block a user