switchProtocol method

  1. @protected
Future<void> switchProtocol(
  1. CheckProtocol protocol
)

Asks the server to restrict ICE candidates to protocol and forces a full reconnect so the switch takes effect. Mirrors simulateScenario('force-tcp') from client-sdk-js.

CheckProtocol.udp is a no-op since fresh connections already prefer UDP (this matches the JS SDK, which has no force-udp scenario).

Implementation

@protected
Future<void> switchProtocol(CheckProtocol protocol) async {
  if (protocol == CheckProtocol.udp) {
    return;
  }
  final listener = room.createListener();
  try {
    // unlike client-sdk-js, the reconnect is always triggered explicitly
    // below, so simply wait for it to complete
    final reconnected = listener.waitFor<RoomReconnectedEvent>(
      duration: const Duration(seconds: 10),
      onTimeout: () => throw CheckException('Could not reconnect using ${protocol.name} protocol after 10 seconds'),
    );
    reconnected.ignore();
    engine.signalClient.sendSimulateScenario(switchCandidate: true);
    engine.fullReconnectOnNext = true;
    await engine.handleReconnect(ClientDisconnectReason.leaveReconnect);
    await reconnected;
  } finally {
    await listener.dispose();
  }
}