diff --git a/lib/src/utils.dart b/lib/src/utils.dart index e149646..4dfcc15 100644 --- a/lib/src/utils.dart +++ b/lib/src/utils.dart @@ -28,10 +28,21 @@ class Utils { final useSecure = uri.isSecureScheme || forceSecure; final httpScheme = useSecure ? 'https' : 'http'; final wsScheme = useSecure ? 'wss' : 'ws'; + final lastSegment = validate ? 'validate' : 'rtc'; + + final pathSegments = List.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); return uri.replace( scheme: validate ? httpScheme : wsScheme, - path: validate ? 'validate' : 'rtc', + pathSegments: pathSegments, queryParameters: { 'access_token': token, if (options != null)