11/*
2- * Copyright 2023-2025 LiveKit, Inc.
2+ * Copyright 2023-2026 LiveKit, Inc.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
@@ -169,7 +169,7 @@ constructor(
169169 // Clean up any pre-existing connection.
170170 close(reason = " Starting new connection" , shouldClearQueuedRequests = false )
171171
172- val wsUrlString = " ${url.toWebsocketUrl()} /rtc" + createConnectionParams(getClientInfo(), options, roomOptions)
172+ val wsUrlString = " ${url.toWebsocketUrl()} /rtc${ createConnectionParams(getClientInfo(), options, roomOptions)} "
173173 isReconnecting = options.reconnect
174174
175175 LKLog .i { " connecting to $wsUrlString " }
@@ -196,34 +196,39 @@ constructor(
196196 options : ConnectOptions ,
197197 roomOptions : RoomOptions ,
198198 ): String {
199- val queryParams = mutableListOf<Pair <String , String >>()
200- queryParams.add(CONNECT_QUERY_PROTOCOL to options.protocolVersion.value.toString())
199+ val queryBuilder = StringBuilder ()
200+ var first = true
201+
202+ fun addParam (key : String , value : String ) {
203+ queryBuilder.append(if (first) " ?" else " &" )
204+ .append(key).append(" =" ).append(value)
205+ first = false
206+ }
207+
208+ addParam(CONNECT_QUERY_PROTOCOL , options.protocolVersion.value.toString())
201209
202210 if (options.reconnect) {
203- queryParams.add (CONNECT_QUERY_RECONNECT to 1 .toString() )
211+ addParam (CONNECT_QUERY_RECONNECT , " 1 " )
204212 options.participantSid?.let { sid ->
205- queryParams.add (CONNECT_QUERY_PARTICIPANT_SID to sid)
213+ addParam (CONNECT_QUERY_PARTICIPANT_SID , sid)
206214 }
207215 }
208216
209217 val autoSubscribe = if (options.autoSubscribe) 1 else 0
210- queryParams.add (CONNECT_QUERY_AUTOSUBSCRIBE to autoSubscribe.toString())
218+ addParam (CONNECT_QUERY_AUTOSUBSCRIBE , autoSubscribe.toString())
211219
212220 val adaptiveStream = if (roomOptions.adaptiveStream) 1 else 0
213- queryParams.add (CONNECT_QUERY_ADAPTIVE_STREAM to adaptiveStream.toString())
221+ addParam (CONNECT_QUERY_ADAPTIVE_STREAM , adaptiveStream.toString())
214222
215223 // Client info
216- queryParams.add(CONNECT_QUERY_SDK to " android" )
217- queryParams.add(CONNECT_QUERY_VERSION to clientInfo.version)
218- queryParams.add(CONNECT_QUERY_DEVICE_MODEL to clientInfo.deviceModel)
219- queryParams.add(CONNECT_QUERY_OS to clientInfo.os)
220- queryParams.add(CONNECT_QUERY_OS_VERSION to clientInfo.osVersion)
221- queryParams.add(CONNECT_QUERY_NETWORK_TYPE to networkInfo.getNetworkType().protoName)
222-
223- return queryParams.foldIndexed(" " ) { index, acc, pair ->
224- val separator = if (index == 0 ) " ?" else " &"
225- acc + separator + " ${pair.first} =${pair.second} "
226- }
224+ addParam(CONNECT_QUERY_SDK , " android" )
225+ addParam(CONNECT_QUERY_VERSION , clientInfo.version)
226+ addParam(CONNECT_QUERY_DEVICE_MODEL , clientInfo.deviceModel)
227+ addParam(CONNECT_QUERY_OS , clientInfo.os)
228+ addParam(CONNECT_QUERY_OS_VERSION , clientInfo.osVersion)
229+ addParam(CONNECT_QUERY_NETWORK_TYPE , networkInfo.getNetworkType().protoName)
230+
231+ return queryBuilder.toString()
227232 }
228233
229234 /* *
0 commit comments