Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .changes/protocol-v13
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
minor type="feature" "Support protocol v13 with LeaveRequest action"
43 changes: 22 additions & 21 deletions lib/src/core/engine.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1351,31 +1351,32 @@ class Engine extends Disposable with EventsEmittable<EngineEvent> {
token = event.token;
})
..on<SignalLeaveEvent>((event) async {
logger.fine('[Signal] Leave received, action: ${event.action}, reason: ${event.reason}');
if (event.regions != null && _regionUrlProvider != null) {
logger.fine('updating regions');
_regionUrlProvider?.setServerReportedRegions(event.regions!);
}
switch (event.action) {
case lk_rtc.LeaveRequest_Action.DISCONNECT:
if (connectionState == ConnectionState.reconnecting) {
logger.warning('[Signal] Received Leave while engine is reconnecting, ignoring...');
return;
}
await signalClient.cleanUp();
fullReconnectOnNext = false;
await disconnect();
events.emit(EngineDisconnectedEvent(reason: event.reason.toSDKType()));
break;
case lk_rtc.LeaveRequest_Action.RECONNECT:
fullReconnectOnNext = true;
// reconnect immediately instead of waiting for next attempt
await handleReconnect(ClientDisconnectReason.leaveReconnect);
break;
case lk_rtc.LeaveRequest_Action.RESUME:
// reconnect immediately instead of waiting for next attempt
await handleReconnect(ClientDisconnectReason.leaveReconnect);
default:
break;
// Protocol v13: LeaveRequest.action replaces the deprecated canReconnect boolean.
// canReconnect is still checked for backward compatibility with v12 servers
// (where action defaults to DISCONNECT=0 since it's unset).
if (event.action == lk_rtc.LeaveRequest_Action.RESUME) {
fullReconnectOnNext = false;
// reconnect immediately instead of waiting for next attempt
await handleReconnect(ClientDisconnectReason.leaveReconnect);
} else if (event.action == lk_rtc.LeaveRequest_Action.RECONNECT || event.canReconnect) {
fullReconnectOnNext = true;
// reconnect immediately instead of waiting for next attempt
await handleReconnect(ClientDisconnectReason.leaveReconnect);
} else {
// DISCONNECT or v12 server with canReconnect=false
if (connectionState == ConnectionState.reconnecting) {
logger.warning('[Signal] Received Leave while engine is reconnecting, ignoring...');
return;
}
await signalClient.cleanUp();
fullReconnectOnNext = false;
await disconnect();
events.emit(EngineDisconnectedEvent(reason: event.reason.toSDKType()));
}
});

Expand Down
6 changes: 5 additions & 1 deletion lib/src/core/signal_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,11 @@ class SignalClient extends Disposable with EventsEmittable<SignalEvent> {

Future<void> sendLeave() async {
_sendRequest(lk_rtc.SignalRequest(
leave: lk_rtc.LeaveRequest(canReconnect: false, reason: lk_models.DisconnectReason.CLIENT_INITIATED)));
leave: lk_rtc.LeaveRequest(
reason: lk_models.DisconnectReason.CLIENT_INITIATED,
// server doesn't process this field, keeping it here to indicate the intent of a full disconnect
action: lk_rtc.LeaveRequest_Action.DISCONNECT,
)));
}

// resets internal state to a re-usable state
Expand Down
1 change: 1 addition & 0 deletions lib/src/extensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ extension ProtocolVersionExt on ProtocolVersion {
ProtocolVersion.v10: '10',
ProtocolVersion.v11: '11',
ProtocolVersion.v12: '12',
ProtocolVersion.v13: '13',
}[this]!;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/src/options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class ConnectOptions {
const ConnectOptions({
this.autoSubscribe = true,
this.rtcConfiguration = const RTCConfiguration(),
this.protocolVersion = ProtocolVersion.v12,
this.protocolVersion = ProtocolVersion.v13,
this.timeouts = Timeouts.defaultTimeouts,
});
}
Expand Down
1 change: 1 addition & 0 deletions lib/src/types/other.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ enum ProtocolVersion {
v10,
v11,
v12,
v13, // Regions in leave request, canReconnect obsoleted by action
}

/// Connection state type used throughout the SDK.
Expand Down