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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .changes/dc-leak
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
patch type="fixed" "Memory leaks in data channel cancellation code"
7 changes: 7 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,10 @@ type_name:
excluded:
- ID
- OS

custom_rules:
no_manual_task_management:
name: "No Manual Task Management"
regex: "(let|var)\\s+\\w+\\s*:\\s*Task<Void,"
message: "Prefer AnyTaskCancellable over manually managing Task<Void, ...>. This allows for safer cleanup, similar to Combine's AnyCancellable."
severity: warning
2 changes: 1 addition & 1 deletion Sources/LiveKit/Agent/Agent.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2025 LiveKit
* 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.
Expand Down
2 changes: 1 addition & 1 deletion Sources/LiveKit/Agent/Chat/Message.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2025 LiveKit
* 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.
Expand Down
2 changes: 1 addition & 1 deletion Sources/LiveKit/Agent/Chat/Receive/MessageReceiver.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2025 LiveKit
* 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.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2025 LiveKit
* 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.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2025 LiveKit
* 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.
Expand Down
2 changes: 1 addition & 1 deletion Sources/LiveKit/Agent/Chat/Send/MessageSender.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2025 LiveKit
* 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.
Expand Down
2 changes: 1 addition & 1 deletion Sources/LiveKit/Agent/Chat/Send/TextMessageSender.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2025 LiveKit
* 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.
Expand Down
2 changes: 1 addition & 1 deletion Sources/LiveKit/Agent/Participant+Agent.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2025 LiveKit
* 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.
Expand Down
2 changes: 1 addition & 1 deletion Sources/LiveKit/Agent/Room+Agent.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2025 LiveKit
* 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.
Expand Down
35 changes: 18 additions & 17 deletions Sources/LiveKit/Agent/Session.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2025 LiveKit
* 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.
Expand Down Expand Up @@ -110,7 +110,8 @@ open class Session: ObservableObject {

// MARK: - Internal state

private var waitForAgentTask: Task<Void, Swift.Error>?
private var tasks = Set<AnyTaskCancellable>()
private var waitForAgentTask: AnyTaskCancellable?

// MARK: - Init

Expand Down Expand Up @@ -193,17 +194,10 @@ open class Session: ObservableObject {
receivers: receivers)
}

deinit {
waitForAgentTask?.cancel()
}

private func observe(room: Room) {
Task { [weak self] in
for try await _ in room.changes {
guard let self else { return }
updateAgent(in: room)
}
}
room.changes.subscribeOnMainActor(self) { observer, _ in
observer.updateAgent(in: room)
}.store(in: &tasks)
}

private func updateAgent(in room: Room) {
Expand All @@ -221,18 +215,25 @@ open class Session: ObservableObject {
}

private func observe(receivers: [any MessageReceiver]) {
let (stream, continuation) = AsyncStream.makeStream(of: ReceivedMessage.self)

// Multiple producers → single stream
for receiver in receivers {
Task { [weak self] in
do {
for await message in try await receiver.messages() {
guard let self else { return }
messagesDict.updateValue(message, forKey: message.id)
continuation.yield(message)
}
} catch {
self?.error = .receiver(error)
}
}
}.cancellable().store(in: &tasks)
}

// Single consumer
stream.subscribeOnMainActor(self) { observer, message in
observer.messagesDict.updateValue(message, forKey: message.id)
}.store(in: &tasks)
}

// MARK: - Lifecycle
Expand All @@ -242,7 +243,7 @@ open class Session: ObservableObject {
guard connectionState == .disconnected else { return }

error = nil
waitForAgentTask?.cancel()
waitForAgentTask = nil

let timeout = options.agentConnectTimeout

Expand Down Expand Up @@ -278,7 +279,7 @@ open class Session: ObservableObject {
if isConnected, !agent.isConnected {
agent.failed(error: .timeout)
}
}
}.cancellable()
}
} catch {
self.error = .connection(error)
Expand Down
2 changes: 1 addition & 1 deletion Sources/LiveKit/Agent/SessionOptions.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2025 LiveKit
* 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.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2025 LiveKit
* 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.
Expand Down
2 changes: 1 addition & 1 deletion Sources/LiveKit/Audio/AudioEngineObserver.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2025 LiveKit
* 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.
Expand Down
2 changes: 1 addition & 1 deletion Sources/LiveKit/Audio/AudioSessionEngineObserver.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2025 LiveKit
* 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.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2025 LiveKit
* 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.
Expand Down
2 changes: 1 addition & 1 deletion Sources/LiveKit/Audio/Manager/AudioManager+MuteMode.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2025 LiveKit
* 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.
Expand Down
2 changes: 1 addition & 1 deletion Sources/LiveKit/Audio/Manager/AudioManager+Testing.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2025 LiveKit
* 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.
Expand Down
2 changes: 1 addition & 1 deletion Sources/LiveKit/Audio/Manager/AudioManager.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2025 LiveKit
* 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.
Expand Down Expand Up @@ -103,10 +103,10 @@
// Keep this var within State so it's protected by UnfairLock
public var localTracksCount: Int = 0
public var remoteTracksCount: Int = 0
public var customConfigureFunc: ConfigureAudioSessionFunc?

Check warning on line 106 in Sources/LiveKit/Audio/Manager/AudioManager.swift

View workflow job for this annotation

GitHub Actions / Build & Test (macos-14, 15.4, tvOS Simulator,name=Apple TV,OS=17.5)

'ConfigureAudioSessionFunc' is deprecated

Check warning on line 106 in Sources/LiveKit/Audio/Manager/AudioManager.swift

View workflow job for this annotation

GitHub Actions / Build & Test (macos-14, 15.4, iOS Simulator,name=iPhone 15 Pro,OS=17.5)

'ConfigureAudioSessionFunc' is deprecated

Check warning on line 106 in Sources/LiveKit/Audio/Manager/AudioManager.swift

View workflow job for this annotation

GitHub Actions / Build & Test (macos-14, 15.4, iOS Simulator,name=iPhone 15 Pro,OS=17.5)

'ConfigureAudioSessionFunc' is deprecated

Check warning on line 106 in Sources/LiveKit/Audio/Manager/AudioManager.swift

View workflow job for this annotation

GitHub Actions / Build & Test (macos-14, 15.4, macOS,variant=Mac Catalyst)

'ConfigureAudioSessionFunc' is deprecated

Check warning on line 106 in Sources/LiveKit/Audio/Manager/AudioManager.swift

View workflow job for this annotation

GitHub Actions / Build & Test (macos-15, 16.4, macOS,variant=Mac Catalyst)

'ConfigureAudioSessionFunc' is deprecated

Check warning on line 106 in Sources/LiveKit/Audio/Manager/AudioManager.swift

View workflow job for this annotation

GitHub Actions / Build & Test (macos-26, 26.1, tvOS Simulator,name=Apple TV,OS=26.1)

'ConfigureAudioSessionFunc' is deprecated

Check warning on line 106 in Sources/LiveKit/Audio/Manager/AudioManager.swift

View workflow job for this annotation

GitHub Actions / Build & Test (macos-26, 26.1, tvOS Simulator,name=Apple TV,OS=26.1)

'ConfigureAudioSessionFunc' is deprecated

Check warning on line 106 in Sources/LiveKit/Audio/Manager/AudioManager.swift

View workflow job for this annotation

GitHub Actions / Build & Test (macos-26, 26.1, macOS,variant=Mac Catalyst)

'ConfigureAudioSessionFunc' is deprecated

Check warning on line 106 in Sources/LiveKit/Audio/Manager/AudioManager.swift

View workflow job for this annotation

GitHub Actions / Build & Test (macos-26, 26.1, macOS,variant=Mac Catalyst)

'ConfigureAudioSessionFunc' is deprecated

Check warning on line 106 in Sources/LiveKit/Audio/Manager/AudioManager.swift

View workflow job for this annotation

GitHub Actions / Build & Test (macos-15, 16.4, tvOS Simulator,name=Apple TV,OS=18.5)

'ConfigureAudioSessionFunc' is deprecated

Check warning on line 106 in Sources/LiveKit/Audio/Manager/AudioManager.swift

View workflow job for this annotation

GitHub Actions / Build & Test (macos-15, 16.4, tvOS Simulator,name=Apple TV,OS=18.5)

'ConfigureAudioSessionFunc' is deprecated

Check warning on line 106 in Sources/LiveKit/Audio/Manager/AudioManager.swift

View workflow job for this annotation

GitHub Actions / Build & Test (macos-15, 16.4, iOS Simulator,name=iPhone 16 Pro,OS=18.5)

'ConfigureAudioSessionFunc' is deprecated

Check warning on line 106 in Sources/LiveKit/Audio/Manager/AudioManager.swift

View workflow job for this annotation

GitHub Actions / Build & Test (macos-15, 16.4, visionOS Simulator,name=Apple Vision Pro,OS=2.5)

'ConfigureAudioSessionFunc' is deprecated

Check warning on line 106 in Sources/LiveKit/Audio/Manager/AudioManager.swift

View workflow job for this annotation

GitHub Actions / Build & Test (macos-15, 16.4, visionOS Simulator,name=Apple Vision Pro,OS=2.5)

'ConfigureAudioSessionFunc' is deprecated

Check warning on line 106 in Sources/LiveKit/Audio/Manager/AudioManager.swift

View workflow job for this annotation

GitHub Actions / Build & Test (macos-26, 26.1, iOS Simulator,name=iPhone 17 Pro,OS=26.1, true)

'ConfigureAudioSessionFunc' is deprecated

Check warning on line 106 in Sources/LiveKit/Audio/Manager/AudioManager.swift

View workflow job for this annotation

GitHub Actions / Build & Test (macos-26, 26.1, iOS Simulator,name=iPhone 17 Pro,OS=26.1, true)

'ConfigureAudioSessionFunc' is deprecated

Check warning on line 106 in Sources/LiveKit/Audio/Manager/AudioManager.swift

View workflow job for this annotation

GitHub Actions / Build & Test (macos-26, 26.1, iOS Simulator,name=iPhone 17 Pro,OS=26.1, true)

'ConfigureAudioSessionFunc' is deprecated

Check warning on line 106 in Sources/LiveKit/Audio/Manager/AudioManager.swift

View workflow job for this annotation

GitHub Actions / Build & Test (macos-26, 26.1, iOS Simulator,name=iPhone 17 Pro,OS=26.1, true)

'ConfigureAudioSessionFunc' is deprecated

Check warning on line 106 in Sources/LiveKit/Audio/Manager/AudioManager.swift

View workflow job for this annotation

GitHub Actions / Build & Test (macos-26, 26.1, visionOS Simulator,name=Apple Vision Pro,OS=26.1)

'ConfigureAudioSessionFunc' is deprecated

Check warning on line 106 in Sources/LiveKit/Audio/Manager/AudioManager.swift

View workflow job for this annotation

GitHub Actions / Build & Test (macos-26, 26.1, visionOS Simulator,name=Apple Vision Pro,OS=26.1)

'ConfigureAudioSessionFunc' is deprecated
public var sessionConfiguration: AudioSessionConfiguration?

public var trackState: TrackState {

Check warning on line 109 in Sources/LiveKit/Audio/Manager/AudioManager.swift

View workflow job for this annotation

GitHub Actions / Build & Test (macos-14, 15.4, tvOS Simulator,name=Apple TV,OS=17.5)

'TrackState' is deprecated

Check warning on line 109 in Sources/LiveKit/Audio/Manager/AudioManager.swift

View workflow job for this annotation

GitHub Actions / Build & Test (macos-14, 15.4, iOS Simulator,name=iPhone 15 Pro,OS=17.5)

'TrackState' is deprecated

Check warning on line 109 in Sources/LiveKit/Audio/Manager/AudioManager.swift

View workflow job for this annotation

GitHub Actions / Build & Test (macos-14, 15.4, iOS Simulator,name=iPhone 15 Pro,OS=17.5)

'TrackState' is deprecated

Check warning on line 109 in Sources/LiveKit/Audio/Manager/AudioManager.swift

View workflow job for this annotation

GitHub Actions / Build & Test (macos-14, 15.4, macOS,variant=Mac Catalyst)

'TrackState' is deprecated

Check warning on line 109 in Sources/LiveKit/Audio/Manager/AudioManager.swift

View workflow job for this annotation

GitHub Actions / Build & Test (macos-15, 16.4, macOS,variant=Mac Catalyst)

'TrackState' is deprecated

Check warning on line 109 in Sources/LiveKit/Audio/Manager/AudioManager.swift

View workflow job for this annotation

GitHub Actions / Build & Test (macos-26, 26.1, tvOS Simulator,name=Apple TV,OS=26.1)

'TrackState' is deprecated

Check warning on line 109 in Sources/LiveKit/Audio/Manager/AudioManager.swift

View workflow job for this annotation

GitHub Actions / Build & Test (macos-26, 26.1, tvOS Simulator,name=Apple TV,OS=26.1)

'TrackState' is deprecated

Check warning on line 109 in Sources/LiveKit/Audio/Manager/AudioManager.swift

View workflow job for this annotation

GitHub Actions / Build & Test (macos-26, 26.1, macOS,variant=Mac Catalyst)

'TrackState' is deprecated

Check warning on line 109 in Sources/LiveKit/Audio/Manager/AudioManager.swift

View workflow job for this annotation

GitHub Actions / Build & Test (macos-15, 16.4, tvOS Simulator,name=Apple TV,OS=18.5)

'TrackState' is deprecated

Check warning on line 109 in Sources/LiveKit/Audio/Manager/AudioManager.swift

View workflow job for this annotation

GitHub Actions / Build & Test (macos-15, 16.4, tvOS Simulator,name=Apple TV,OS=18.5)

'TrackState' is deprecated

Check warning on line 109 in Sources/LiveKit/Audio/Manager/AudioManager.swift

View workflow job for this annotation

GitHub Actions / Build & Test (macos-15, 16.4, iOS Simulator,name=iPhone 16 Pro,OS=18.5)

'TrackState' is deprecated

Check warning on line 109 in Sources/LiveKit/Audio/Manager/AudioManager.swift

View workflow job for this annotation

GitHub Actions / Build & Test (macos-15, 16.4, visionOS Simulator,name=Apple Vision Pro,OS=2.5)

'TrackState' is deprecated

Check warning on line 109 in Sources/LiveKit/Audio/Manager/AudioManager.swift

View workflow job for this annotation

GitHub Actions / Build & Test (macos-15, 16.4, visionOS Simulator,name=Apple Vision Pro,OS=2.5)

'TrackState' is deprecated

Check warning on line 109 in Sources/LiveKit/Audio/Manager/AudioManager.swift

View workflow job for this annotation

GitHub Actions / Build & Test (macos-26, 26.1, iOS Simulator,name=iPhone 17 Pro,OS=26.1, true)

'TrackState' is deprecated

Check warning on line 109 in Sources/LiveKit/Audio/Manager/AudioManager.swift

View workflow job for this annotation

GitHub Actions / Build & Test (macos-26, 26.1, iOS Simulator,name=iPhone 17 Pro,OS=26.1, true)

'TrackState' is deprecated

Check warning on line 109 in Sources/LiveKit/Audio/Manager/AudioManager.swift

View workflow job for this annotation

GitHub Actions / Build & Test (macos-26, 26.1, iOS Simulator,name=iPhone 17 Pro,OS=26.1, true)

'TrackState' is deprecated

Check warning on line 109 in Sources/LiveKit/Audio/Manager/AudioManager.swift

View workflow job for this annotation

GitHub Actions / Build & Test (macos-26, 26.1, iOS Simulator,name=iPhone 17 Pro,OS=26.1, true)

'TrackState' is deprecated

Check warning on line 109 in Sources/LiveKit/Audio/Manager/AudioManager.swift

View workflow job for this annotation

GitHub Actions / Build & Test (macos-26, 26.1, visionOS Simulator,name=Apple Vision Pro,OS=26.1)

'TrackState' is deprecated

Check warning on line 109 in Sources/LiveKit/Audio/Manager/AudioManager.swift

View workflow job for this annotation

GitHub Actions / Build & Test (macos-26, 26.1, visionOS Simulator,name=Apple Vision Pro,OS=26.1)

'TrackState' is deprecated
switch (localTracksCount > 0, remoteTracksCount > 0) {
case (true, false): .localOnly
case (false, true): .remoteOnly
Expand Down
2 changes: 1 addition & 1 deletion Sources/LiveKit/Audio/MixerEngineObserver.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2025 LiveKit
* 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.
Expand Down
2 changes: 1 addition & 1 deletion Sources/LiveKit/Broadcast/BroadcastBundleInfo.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2025 LiveKit
* 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.
Expand Down
2 changes: 1 addition & 1 deletion Sources/LiveKit/Broadcast/BroadcastManager.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2025 LiveKit
* 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.
Expand Down
2 changes: 1 addition & 1 deletion Sources/LiveKit/Broadcast/BroadcastScreenCapturer.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2025 LiveKit
* 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.
Expand Down
2 changes: 1 addition & 1 deletion Sources/LiveKit/Broadcast/IPC/BroadcastAudioCodec.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2025 LiveKit
* 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.
Expand Down Expand Up @@ -93,7 +93,7 @@
}
}

extension AudioStreamBasicDescription: Codable {

Check warning on line 96 in Sources/LiveKit/Broadcast/IPC/BroadcastAudioCodec.swift

View workflow job for this annotation

GitHub Actions / Build & Test (macos-26, 26.1, macOS,variant=Mac Catalyst)

extension declares a conformance of imported type 'AudioStreamBasicDescription' to imported protocols 'Decodable', 'Encodable'; this will not behave correctly if the owners of 'CoreAudioTypes' introduce this conformance in the future

Check warning on line 96 in Sources/LiveKit/Broadcast/IPC/BroadcastAudioCodec.swift

View workflow job for this annotation

GitHub Actions / Build & Test (macos-26, 26.1, iOS Simulator,name=iPhone 17 Pro,OS=26.1, true)

extension declares a conformance of imported type 'AudioStreamBasicDescription' to imported protocols 'Decodable', 'Encodable'; this will not behave correctly if the owners of 'CoreAudioTypes' introduce this conformance in the future

Check warning on line 96 in Sources/LiveKit/Broadcast/IPC/BroadcastAudioCodec.swift

View workflow job for this annotation

GitHub Actions / Build & Test (macos-26, 26.1, iOS Simulator,name=iPhone 17 Pro,OS=26.1, true)

extension declares a conformance of imported type 'AudioStreamBasicDescription' to imported protocols 'Decodable', 'Encodable'; this will not behave correctly if the owners of 'CoreAudioTypes' introduce this conformance in the future

Check warning on line 96 in Sources/LiveKit/Broadcast/IPC/BroadcastAudioCodec.swift

View workflow job for this annotation

GitHub Actions / Build & Test (macos-26, 26.1, iOS Simulator,name=iPhone 17 Pro,OS=26.1, true)

extension declares a conformance of imported type 'AudioStreamBasicDescription' to imported protocols 'Decodable', 'Encodable'; this will not behave correctly if the owners of 'CoreAudioTypes' introduce this conformance in the future

Check warning on line 96 in Sources/LiveKit/Broadcast/IPC/BroadcastAudioCodec.swift

View workflow job for this annotation

GitHub Actions / Build & Test (macos-26, 26.1, iOS Simulator,name=iPhone 17 Pro,OS=26.1, true)

extension declares a conformance of imported type 'AudioStreamBasicDescription' to imported protocols 'Decodable', 'Encodable'; this will not behave correctly if the owners of 'CoreAudioTypes' introduce this conformance in the future
public func encode(to encoder: any Encoder) throws {
var container = encoder.unkeyedContainer()
try container.encode(mSampleRate)
Expand Down
2 changes: 1 addition & 1 deletion Sources/LiveKit/Broadcast/IPC/BroadcastIPCHeader.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2025 LiveKit
* 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.
Expand Down
2 changes: 1 addition & 1 deletion Sources/LiveKit/Broadcast/IPC/BroadcastImageCodec.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2025 LiveKit
* 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.
Expand Down
2 changes: 1 addition & 1 deletion Sources/LiveKit/Broadcast/IPC/BroadcastReceiver.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2025 LiveKit
* 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.
Expand Down
33 changes: 21 additions & 12 deletions Sources/LiveKit/Broadcast/IPC/BroadcastUploader.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2025 LiveKit
* 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.
Expand Down Expand Up @@ -29,6 +29,7 @@ final class BroadcastUploader: Sendable, Loggable {
private struct State {
var isUploadingImage = false
var shouldUploadAudio = false
var messageLoopTask: AnyTaskCancellable?
}

private let state = StateSync(State())
Expand All @@ -40,8 +41,19 @@ final class BroadcastUploader: Sendable, Loggable {

/// Creates an uploader with an open connection to another process.
init(socketPath: SocketPath) async throws {
channel = try await IPCChannel(connectingTo: socketPath)
Task { try await handleIncomingMessages() }
let channel = try await IPCChannel(connectingTo: socketPath)
self.channel = channel

let messageLoopTask = channel.incomingMessages(BroadcastIPCHeader.self).subscribe(self) { observer, message in
observer.processMessageHeader(message.0)
} onFailure: { observer, error in
observer.log("IPCChannel returned error: \(error)")
}
state.mutate { $0.messageLoopTask = messageLoopTask }
}

deinit {
close()
}

/// Whether or not the connection to the receiver has been closed.
Expand Down Expand Up @@ -92,15 +104,12 @@ final class BroadcastUploader: Sendable, Loggable {
}
}

private func handleIncomingMessages() async throws {
for try await (header, _) in channel.incomingMessages(BroadcastIPCHeader.self) {
switch header {
case let .wantsAudio(wantsAudio):
state.mutate { $0.shouldUploadAudio = wantsAudio }
default:
log("Unhandled incoming message: \(header)", .debug)
continue
}
private func processMessageHeader(_ header: BroadcastIPCHeader) {
switch header {
case let .wantsAudio(wantsAudio):
state.mutate { $0.shouldUploadAudio = wantsAudio }
default:
log("Unhandled incoming message: \(header)", .debug)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/LiveKit/Broadcast/IPC/IPCChannel.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2025 LiveKit
* 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.
Expand Down
2 changes: 1 addition & 1 deletion Sources/LiveKit/Broadcast/IPC/IPCProtocol.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2025 LiveKit
* 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.
Expand Down
2 changes: 1 addition & 1 deletion Sources/LiveKit/Broadcast/IPC/SocketPath.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2025 LiveKit
* 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.
Expand Down
2 changes: 1 addition & 1 deletion Sources/LiveKit/Broadcast/LKSampleHandler.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2025 LiveKit
* 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.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2025 LiveKit
* 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.
Expand Down
2 changes: 1 addition & 1 deletion Sources/LiveKit/Convenience/AudioProcessing.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2025 LiveKit
* 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.
Expand Down
Loading
Loading