buildUri static method

  1. @internal
Future<Uri> buildUri(
  1. String uriString, {
  2. required String token,
  3. ConnectOptions? connectOptions,
  4. bool reconnect = false,
  5. bool validate = false,
  6. bool forceSecure = false,
})

Implementation

@internal
static Future<Uri> buildUri(
  String uriString, {
  required String token,
  ConnectOptions? connectOptions,
  bool reconnect = false,
  bool validate = false,
  bool forceSecure = false,
}) async {
  connectOptions ??= const ConnectOptions();

  final Uri uri = Uri.parse(uriString);

  final useSecure = uri.isSecureScheme || forceSecure;
  final httpScheme = useSecure ? 'https' : 'http';
  final wsScheme = useSecure ? 'wss' : 'ws';
  final lastSegment = validate ? 'validate' : 'rtc';

  final pathSegments = List<String>.from(uri.pathSegments);

  // strip path segment used for LiveKit if already exists
  pathSegments.removeWhere((e) => e.isEmpty);
  if (pathSegments.isNotEmpty &&
      ['rtc', 'validate'].contains(uri.pathSegments.last)) {
    pathSegments.removeLast();
  }
  pathSegments.add(lastSegment);

  final clientInfo = await _clientInfo();

  return uri.replace(
    scheme: validate ? httpScheme : wsScheme,
    pathSegments: pathSegments,
    queryParameters: <String, String>{
      'access_token': token,
      'auto_subscribe': connectOptions.autoSubscribe ? '1' : '0',
      if (reconnect) 'reconnect': '1',
      'protocol': connectOptions.protocolVersion.toStringValue(),
      'sdk': 'flutter',
      'version': LiveKitClient.version,
      // client info
      if (clientInfo != null) ...{
        if (clientInfo.hasOs()) 'os': clientInfo.os,
        if (clientInfo.hasOsVersion()) 'os_version': clientInfo.osVersion,
        if (clientInfo.hasDeviceModel())
          'device_model': clientInfo.deviceModel,
        if (clientInfo.hasBrowser()) 'browser': clientInfo.browser,
        if (clientInfo.hasBrowserVersion())
          'browser_version': clientInfo.browserVersion,
      },
    },
  );
}