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
1 change: 1 addition & 0 deletions .changes/remove-swift-collections
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
patch type="changed" "Remove swift-collections dependency by replacing with minimal internal implementations"
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Key components:
- `StateSync<T>` - thread-safe state container with `@dynamicMemberLookup`; triggers `onDidMutate` callbacks
- `MulticastDelegate<T>` - weak-reference delegate collection for event broadcasting

Dependencies: LiveKitWebRTC, LiveKitUniFFI, SwiftProtobuf, swift-collections.
Dependencies: LiveKitWebRTC, LiveKitUniFFI, SwiftProtobuf.

## WebRTC

Expand Down
2 changes: 0 additions & 2 deletions LiveKitClient.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ Pod::Spec.new do |spec|
spec.dependency("LiveKitWebRTC", "= 144.7559.01")
spec.dependency("LiveKitUniFFI", "= 0.0.5")
spec.dependency("SwiftProtobuf")
spec.dependency("DequeModule", "= 1.1.4")
spec.dependency("OrderedCollections", " = 1.1.4")

spec.resource_bundles = {"Privacy" => ["Sources/LiveKit/PrivacyInfo.xcprivacy"]}

Expand Down
3 changes: 0 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ let package = Package(
.package(url: "https://github.com/livekit/webrtc-xcframework.git", exact: "144.7559.01"),
.package(url: "https://github.com/livekit/livekit-uniffi-xcframework.git", exact: "0.0.5"),
.package(url: "https://github.com/apple/swift-protobuf.git", from: "1.31.0"),
.package(url: "https://github.com/apple/swift-collections.git", "1.1.0" ..< "1.3.0"),
// Only used for DocC generation
.package(url: "https://github.com/apple/swift-docc-plugin.git", from: "1.3.0"),
],
Expand All @@ -37,8 +36,6 @@ let package = Package(
.product(name: "LiveKitWebRTC", package: "webrtc-xcframework"),
.product(name: "LiveKitUniFFI", package: "livekit-uniffi-xcframework"),
.product(name: "SwiftProtobuf", package: "swift-protobuf"),
.product(name: "DequeModule", package: "swift-collections"),
.product(name: "OrderedCollections", package: "swift-collections"),
"LKObjCHelpers",
],
exclude: [
Expand Down
3 changes: 0 additions & 3 deletions Package@swift-6.0.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ let package = Package(
.package(url: "https://github.com/livekit/webrtc-xcframework.git", exact: "144.7559.01"),
.package(url: "https://github.com/livekit/livekit-uniffi-xcframework.git", exact: "0.0.5"),
.package(url: "https://github.com/apple/swift-protobuf.git", from: "1.31.0"),
.package(url: "https://github.com/apple/swift-collections.git", "1.1.0" ..< "1.3.0"),
// Only used for DocC generation
.package(url: "https://github.com/apple/swift-docc-plugin.git", from: "1.3.0"),
],
Expand All @@ -37,8 +36,6 @@ let package = Package(
.product(name: "LiveKitWebRTC", package: "webrtc-xcframework"),
.product(name: "LiveKitUniFFI", package: "livekit-uniffi-xcframework"),
.product(name: "SwiftProtobuf", package: "swift-protobuf"),
.product(name: "DequeModule", package: "swift-collections"),
.product(name: "OrderedCollections", package: "swift-collections"),
"LKObjCHelpers",
],
exclude: [
Expand Down
3 changes: 0 additions & 3 deletions Package@swift-6.2.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ let package = Package(
.package(url: "https://github.com/livekit/webrtc-xcframework.git", exact: "144.7559.01"),
.package(url: "https://github.com/livekit/livekit-uniffi-xcframework.git", exact: "0.0.5"),
.package(url: "https://github.com/apple/swift-protobuf.git", from: "1.31.0"),
.package(url: "https://github.com/apple/swift-collections.git", "1.1.0" ..< "1.3.0"),
// Only used for DocC generation
.package(url: "https://github.com/apple/swift-docc-plugin.git", from: "1.3.0"),
],
Expand All @@ -38,8 +37,6 @@ let package = Package(
.product(name: "LiveKitWebRTC", package: "webrtc-xcframework"),
.product(name: "LiveKitUniFFI", package: "livekit-uniffi-xcframework"),
.product(name: "SwiftProtobuf", package: "swift-protobuf"),
.product(name: "DequeModule", package: "swift-collections"),
.product(name: "OrderedCollections", package: "swift-collections"),
"LKObjCHelpers",
],
exclude: [
Expand Down
1 change: 0 additions & 1 deletion Sources/LiveKit/Agent/Session.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import Combine
import Foundation
import OrderedCollections

/// A ``Session`` represents a connection to a LiveKit Room that can contain an ``Agent``.
///
Expand Down
1 change: 0 additions & 1 deletion Sources/LiveKit/Core/DataChannelPair.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

// swiftlint:disable file_length

import DequeModule
import Foundation

internal import LiveKitWebRTC
Expand Down
74 changes: 74 additions & 0 deletions Sources/LiveKit/Support/DataStructures/Deque.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Copyright 2026 LiveKit
Comment thread
dfed marked this conversation as resolved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

// API inspired by swift-collections by Apple Inc.
// https://github.com/apple/swift-collections

/// A double-ended queue backed by a circular buffer.
/// Provides O(1) amortized `append` and `removeFirst`.
struct Deque<Element>: ExpressibleByArrayLiteral {
private var buffer: [Element?] = []
Comment thread
dfed marked this conversation as resolved.
private var head = 0
private var count_ = 0

init() {}

init(arrayLiteral elements: Element...) {
buffer = elements.map { $0 }
count_ = elements.count
}

var isEmpty: Bool { count_ == 0 }

var first: Element? {
guard count_ > 0 else { return nil }
return buffer[head]
}

mutating func append(_ element: Element) {
if count_ == buffer.count {
grow()
}
let tail = (head + count_) & (buffer.count - 1)
buffer[tail] = element
count_ += 1
}

@discardableResult
mutating func removeFirst() -> Element {
guard count_ > 0 else {
preconditionFailure("Cannot removeFirst from an empty Deque")
}
let element = buffer[head]!
buffer[head] = nil
head = (head + 1) & (buffer.count - 1)
count_ -= 1
return element
}

private mutating func grow() {
let newCapacity = max(buffer.count * 2, 4)
var newBuffer = [Element?](repeating: nil, count: newCapacity)
let mask = buffer.count - 1
for i in 0 ..< count_ {
newBuffer[i] = buffer[(head + i) & mask]
}
Comment thread
dfed marked this conversation as resolved.
buffer = newBuffer
head = 0
}
}

extension Deque: Sendable where Element: Sendable {}
97 changes: 97 additions & 0 deletions Sources/LiveKit/Support/DataStructures/OrderedDictionary.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*
* Copyright 2026 LiveKit
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

// API inspired by swift-collections by Apple Inc.
// https://github.com/apple/swift-collections

struct OrderedDictionary<Key: Hashable, Value>: ExpressibleByDictionaryLiteral {
private var pairs: [(key: Key, value: Value)] = []
private var index: [Key: Int] = [:]
Comment thread
pblazej marked this conversation as resolved.

init() {}

init(dictionaryLiteral elements: (Key, Value)...) {
for (key, value) in elements {
pairs.append((key, value))
index[key] = pairs.count - 1
}
}

init(uniqueKeysWithValues keysAndValues: some Sequence<(Key, Value)>) {
Comment thread
dfed marked this conversation as resolved.
for (key, value) in keysAndValues {
if let i = index[key] {
pairs[i] = (key, value)
} else {
index[key] = pairs.count
pairs.append((key, value))
}
}
}

var count: Int { pairs.count }

var keys: Keys { Keys(pairs: pairs) }
var values: Values { Values(pairs: pairs) }

subscript(key: Key) -> Value? {
get {
guard let i = index[key] else { return nil }
return pairs[i].value
}
set {
if let newValue {
if let i = index[key] {
pairs[i] = (key, newValue)
} else {
index[key] = pairs.count
pairs.append((key, newValue))
}
} else if let i = index.removeValue(forKey: key) {
pairs.remove(at: i)
for j in i ..< pairs.count {
index[pairs[j].key] = j
}
}
}
}

@discardableResult
mutating func updateValue(_ value: Value, forKey key: Key) -> Value? {
if let i = index[key] {
let old = pairs[i].value
pairs[i] = (key, value)
return old
}
index[key] = pairs.count
pairs.append((key, value))
return nil
}

struct Keys {
fileprivate let pairs: [(key: Key, value: Value)]
subscript(position: Int) -> Key { pairs[position].key }
}

struct Values {
fileprivate let pairs: [(key: Key, value: Value)]
var elements: [Value] { pairs.map(\.value) }
subscript(position: Int) -> Value { pairs[position].value }
}
}

extension OrderedDictionary: Sendable where Key: Sendable, Value: Sendable {}
extension OrderedDictionary.Keys: Sendable where Key: Sendable, Value: Sendable {}
extension OrderedDictionary.Values: Sendable where Key: Sendable, Value: Sendable {}
40 changes: 40 additions & 0 deletions Sources/LiveKit/Support/DataStructures/OrderedSet.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright 2026 LiveKit
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

// API inspired by swift-collections by Apple Inc.
// https://github.com/apple/swift-collections

struct OrderedSet<Element: Hashable> {
private var array: [Element] = []
private var set: [Element: Int] = [:]
Comment thread
pblazej marked this conversation as resolved.

init() {}

var elements: [Element] { array }

@discardableResult
mutating func append(_ element: Element) -> (inserted: Bool, index: Int) {
if let existing = set[element] {
return (inserted: false, index: existing)
}
let index = array.count
array.append(element)
set[element] = index
return (inserted: true, index: index)
}
}

extension OrderedSet: Sendable where Element: Sendable {}
1 change: 0 additions & 1 deletion Sources/LiveKit/Track/Metrics/MetricsManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/

import Foundation
import OrderedCollections

// MARK: - Triggers

Expand Down
1 change: 0 additions & 1 deletion Tests/LiveKitCoreTests/Agent/TranscriptionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/

@testable import LiveKit
import OrderedCollections
#if canImport(LiveKitTestSupport)
import LiveKitTestSupport
#endif
Expand Down
Loading