Skip to content
Merged
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
5 changes: 5 additions & 0 deletions .changeset/chubby-ideas-bow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"client-sdk-android": patch
---

Optimised connection params building
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023-2025 LiveKit, Inc.
* Copyright 2023-2026 LiveKit, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -169,7 +169,7 @@ constructor(
// Clean up any pre-existing connection.
close(reason = "Starting new connection", shouldClearQueuedRequests = false)

val wsUrlString = "${url.toWebsocketUrl()}/rtc" + createConnectionParams(getClientInfo(), options, roomOptions)
val wsUrlString = "${url.toWebsocketUrl()}/rtc${createConnectionParams(getClientInfo(), options, roomOptions)}"
isReconnecting = options.reconnect

LKLog.i { "connecting to $wsUrlString" }
Expand All @@ -196,34 +196,39 @@ constructor(
options: ConnectOptions,
roomOptions: RoomOptions,
): String {
val queryParams = mutableListOf<Pair<String, String>>()
queryParams.add(CONNECT_QUERY_PROTOCOL to options.protocolVersion.value.toString())
val queryBuilder = StringBuilder()
var first = true

fun addParam(key: String, value: String) {
queryBuilder.append(if (first) "?" else "&")
.append(key).append("=").append(value)
first = false
}

addParam(CONNECT_QUERY_PROTOCOL, options.protocolVersion.value.toString())

if (options.reconnect) {
queryParams.add(CONNECT_QUERY_RECONNECT to 1.toString())
addParam(CONNECT_QUERY_RECONNECT, "1")
options.participantSid?.let { sid ->
queryParams.add(CONNECT_QUERY_PARTICIPANT_SID to sid)
addParam(CONNECT_QUERY_PARTICIPANT_SID, sid)
}
}

val autoSubscribe = if (options.autoSubscribe) 1 else 0
queryParams.add(CONNECT_QUERY_AUTOSUBSCRIBE to autoSubscribe.toString())
addParam(CONNECT_QUERY_AUTOSUBSCRIBE, autoSubscribe.toString())

val adaptiveStream = if (roomOptions.adaptiveStream) 1 else 0
queryParams.add(CONNECT_QUERY_ADAPTIVE_STREAM to adaptiveStream.toString())
addParam(CONNECT_QUERY_ADAPTIVE_STREAM, adaptiveStream.toString())

// Client info
queryParams.add(CONNECT_QUERY_SDK to "android")
queryParams.add(CONNECT_QUERY_VERSION to clientInfo.version)
queryParams.add(CONNECT_QUERY_DEVICE_MODEL to clientInfo.deviceModel)
queryParams.add(CONNECT_QUERY_OS to clientInfo.os)
queryParams.add(CONNECT_QUERY_OS_VERSION to clientInfo.osVersion)
queryParams.add(CONNECT_QUERY_NETWORK_TYPE to networkInfo.getNetworkType().protoName)

return queryParams.foldIndexed("") { index, acc, pair ->
val separator = if (index == 0) "?" else "&"
acc + separator + "${pair.first}=${pair.second}"
}
addParam(CONNECT_QUERY_SDK, "android")
addParam(CONNECT_QUERY_VERSION, clientInfo.version)
addParam(CONNECT_QUERY_DEVICE_MODEL, clientInfo.deviceModel)
addParam(CONNECT_QUERY_OS, clientInfo.os)
addParam(CONNECT_QUERY_OS_VERSION, clientInfo.osVersion)
addParam(CONNECT_QUERY_NETWORK_TYPE, networkInfo.getNetworkType().protoName)

return queryBuilder.toString()
}

/**
Expand Down