Skip to content

Commit 020eac7

Browse files
committed
Merge branch 'main' into track-reference
2 parents 25dbf2c + e7b1496 commit 020eac7

35 files changed

+200
-334
lines changed

.github/banner_dark.png

-80 KB
Loading

.github/banner_light.png

-22.7 KB
Loading

.github/workflows/testing-matrix.yaml

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Testing Matrix
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches: [ main ]
7+
pull_request:
8+
branches: [ main ]
9+
10+
concurrency:
11+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
12+
cancel-in-progress: true
13+
14+
jobs:
15+
run_all_tests:
16+
strategy:
17+
fail-fast: false
18+
matrix:
19+
xcode-version: [14.2, 15.2]
20+
destination: ['platform=iOS Simulator,OS=17.2,name=iPhone 14 Pro', 'platform=macOS', 'platform=macOS,variant=Mac Catalyst']
21+
22+
runs-on: macos-13
23+
24+
steps:
25+
- uses: actions/checkout@v4
26+
27+
- uses: maxim-lobanov/setup-xcode@v1
28+
with:
29+
xcode-version: ${{ matrix.xcode-version }}
30+
31+
- name: Xcode Version
32+
run: xcodebuild -version
33+
34+
- name: Show SDKs
35+
run: xcodebuild -showsdks
36+
37+
- name: Download iOS platforms
38+
run: xcodebuild -downloadPlatform iOS
39+
40+
# TODO: Add step to install iOS 13
41+
# - name: Install iOS 13
42+
# run: xcversion simulators --install='iOS 13.0'
43+
44+
- name: Show Destinations
45+
run: xcodebuild -scheme LiveKitComponents -showdestinations
46+
47+
- name: Run All Tests
48+
run: xcodebuild test -scheme LiveKitComponents -destination '${{ matrix.destination }}'

.swift-version

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
5.7 # Xcode 14

.swiftformat

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
--exclude Sources/LiveKit/Protos
2+
--header "/*\n * Copyright {year} LiveKit\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */"

Package.swift

+11-13
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,36 @@
1-
// swift-tools-version:5.3
2-
// The swift-tools-version declares the minimum version of Swift required to build this package.
1+
// swift-tools-version:5.7
2+
// (Xcode14.0+)
33

44
import PackageDescription
55

66
let package = Package(
77
name: "LiveKitComponents",
88
platforms: [
99
.iOS(.v14),
10-
.macOS(.v11)
10+
.macOS(.v11),
11+
.macCatalyst(.v14),
1112
],
1213
products: [
13-
// Products define the executables and libraries a package produces, and make them visible to other packages.
1414
.library(
1515
name: "LiveKitComponents",
1616
targets: ["LiveKitComponents"]
17-
)
17+
),
1818
],
1919
dependencies: [
20-
// Dependencies declare other packages that this package depends on.
21-
// .package(url: /* package url */, from: "1.0.0"),
22-
.package(name: "LiveKit", url: "https://github.com/livekit/client-sdk-swift.git", .exact("1.0.13")),
23-
.package(url: "https://github.com/apple/swift-docc-plugin.git", from: "1.3.0")
20+
.package(url: "https://github.com/livekit/client-sdk-swift.git", exact: "2.0.4"),
21+
.package(url: "https://github.com/apple/swift-docc-plugin.git", from: "1.3.0"),
2422
],
2523
targets: [
26-
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
27-
// Targets can depend on other targets in this package, and on products in packages this package depends on.
2824
.target(
2925
name: "LiveKitComponents",
30-
dependencies: ["LiveKit"],
26+
dependencies: [
27+
.product(name: "LiveKit", package: "client-sdk-swift"),
28+
],
3129
path: "Sources"
3230
),
3331
.testTarget(
3432
name: "LiveKitComponentsTests",
3533
dependencies: ["LiveKitComponents"]
36-
)
34+
),
3735
]
3836
)

README.md

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,29 @@
11
<!--BEGIN_BANNER_IMAGE-->
2+
23
<picture>
34
<source media="(prefers-color-scheme: dark)" srcset="/.github/banner_dark.png">
45
<source media="(prefers-color-scheme: light)" srcset="/.github/banner_light.png">
56
<img style="width:100%;" alt="The LiveKit icon, the name of the repository and some sample code in the background." src="https://raw.githubusercontent.com/livekit/components-swift/main/.github/banner_light.png">
67
</picture>
8+
79
<!--END_BANNER_IMAGE-->
810

911
# Swift Components
1012

11-
<!--BEGIN_DESCRIPTION-->Use this SDK to add real-time video, audio and data features to your Swift app. By connecting to a self- or cloud-hosted <a href="https://livekit.io/">LiveKit</a> server, you can quickly build applications like interactive live streaming or video calls with just a few lines of code.<!--END_DESCRIPTION-->
13+
<!--BEGIN_DESCRIPTION-->
14+
Use this SDK to add real-time video, audio and data features to your Swift app. By connecting to a self- or cloud-hosted <a href="https://livekit.io/">LiveKit</a> server, you can quickly build applications like interactive live streaming or video calls with just a few lines of code.
15+
<!--END_DESCRIPTION-->
1216

1317
## [Docs](https://livekit.github.io/components-swift/documentation/livekitcomponents/)
1418

1519
<!--BEGIN_REPO_NAV-->
16-
1720
<br/><table>
18-
1921
<thead><tr><th colspan="2">LiveKit Ecosystem</th></tr></thead>
2022
<tbody>
21-
<tr><td>Client SDKs</td><td><a href="https://github.com/livekit/components-js">Components</a> · <a href="https://github.com/livekit/client-sdk-js">JavaScript</a> · <a href="https://github.com/livekit/client-sdk-swift">iOS/macOS</a> · <a href="https://github.com/livekit/client-sdk-android">Android</a> · <a href="https://github.com/livekit/client-sdk-flutter">Flutter</a> · <a href="https://github.com/livekit/client-sdk-react-native">React Native</a> · <a href="https://github.com/livekit/client-sdk-rust">Rust</a> · <a href="https://github.com/livekit/client-sdk-python">Python</a> · <a href="https://github.com/livekit/client-sdk-unity-web">Unity (web)</a> · <a href="https://github.com/livekit/client-sdk-unity">Unity (beta)</a></td></tr><tr></tr>
22-
<tr><td>Server SDKs</td><td><a href="https://github.com/livekit/server-sdk-js">Node.js</a> · <a href="https://github.com/livekit/server-sdk-go">Golang</a> · <a href="https://github.com/livekit/server-sdk-ruby">Ruby</a> · <a href="https://github.com/livekit/server-sdk-kotlin">Java/Kotlin</a> · <a href="https://github.com/agence104/livekit-server-sdk-php">PHP (community)</a> · <a href="https://github.com/tradablebits/livekit-server-sdk-python">Python (community)</a></td></tr><tr></tr>
23-
<tr><td>Services</td><td><a href="https://github.com/livekit/livekit">Livekit server</a> · <a href="https://github.com/livekit/egress">Egress</a> · <a href="https://github.com/livekit/ingress">Ingress</a></td></tr><tr></tr>
23+
<tr><td>Real-time SDKs</td><td><a href="https://github.com/livekit/components-js">React Components</a> · <a href="https://github.com/livekit/client-sdk-js">JavaScript</a> · <a href="https://github.com/livekit/client-sdk-swift">iOS/macOS</a> · <a href="https://github.com/livekit/client-sdk-android">Android</a> · <a href="https://github.com/livekit/client-sdk-flutter">Flutter</a> · <a href="https://github.com/livekit/client-sdk-react-native">React Native</a> · <a href="https://github.com/livekit/client-sdk-rust">Rust</a> · <a href="https://github.com/livekit/client-sdk-python">Python</a> · <a href="https://github.com/livekit/client-sdk-unity-web">Unity (web)</a> · <a href="https://github.com/livekit/client-sdk-unity">Unity (beta)</a></td></tr><tr></tr>
24+
<tr><td>Server APIs</td><td><a href="https://github.com/livekit/server-sdk-js">Node.js</a> · <a href="https://github.com/livekit/server-sdk-go">Golang</a> · <a href="https://github.com/livekit/server-sdk-ruby">Ruby</a> · <a href="https://github.com/livekit/server-sdk-kotlin">Java/Kotlin</a> · <a href="https://github.com/livekit/client-sdk-python">Python</a> · <a href="https://github.com/livekit/client-sdk-rust">Rust</a> · <a href="https://github.com/agence104/livekit-server-sdk-php">PHP (community)</a></td></tr><tr></tr>
25+
<tr><td>Agents Frameworks</td><td><a href="https://github.com/livekit/agents">Python</a> · <a href="https://github.com/livekit/agent-playground">Playground</a></td></tr><tr></tr>
26+
<tr><td>Services</td><td><a href="https://github.com/livekit/livekit">Livekit server</a> · <a href="https://github.com/livekit/egress">Egress</a> · <a href="https://github.com/livekit/ingress">Ingress</a> · <a href="https://github.com/livekit/sip">SIP</a></td></tr><tr></tr>
2427
<tr><td>Resources</td><td><a href="https://docs.livekit.io">Docs</a> · <a href="https://github.com/livekit-examples">Example apps</a> · <a href="https://livekit.io/cloud">Cloud</a> · <a href="https://docs.livekit.io/oss/deployment">Self-hosting</a> · <a href="https://github.com/livekit/livekit-cli">CLI</a></td></tr>
2528
</tbody>
2629
</table>

Sources/LiveKitComponents/Buttons/CameraToggleButton.swift

+5-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023 LiveKit
2+
* Copyright 2024 LiveKit
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.
@@ -14,35 +14,32 @@
1414
* limitations under the License.
1515
*/
1616

17-
import SwiftUI
1817
import LiveKit
18+
import SwiftUI
1919

2020
/// The Camera Toggle Button is a button that toggles the camera on and off.
2121
public struct CameraToggleButton<Label: View, PublishedLabel: View>: View {
22-
2322
@EnvironmentObject var room: Room
2423
@State var isBusy = false
2524

2625
let label: ComponentBuilder<Label>
2726
let publishedLabel: ComponentBuilder<PublishedLabel>
2827

2928
public init(@ViewBuilder label: @escaping ComponentBuilder<Label>, @ViewBuilder published: @escaping ComponentBuilder<PublishedLabel>) {
30-
3129
self.label = label
32-
self.publishedLabel = published
30+
publishedLabel = published
3331
}
3432

3533
var isCameraEnabled: Bool {
36-
room.localParticipant?.isCameraEnabled() ?? false
34+
room.localParticipant.isCameraEnabled()
3735
}
3836

3937
public var body: some View {
4038
Button {
4139
Task {
4240
isBusy = true
4341
defer { Task { @MainActor in isBusy = false } }
44-
guard let localParticipant = room.localParticipant else { return }
45-
try await localParticipant.setCamera(enabled: !isCameraEnabled)
42+
try await room.localParticipant.setCamera(enabled: !isCameraEnabled)
4643
}
4744
} label: {
4845
if isCameraEnabled {

Sources/LiveKitComponents/Buttons/DisconnectRoomButton.swift

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023 LiveKit
2+
* Copyright 2024 LiveKit
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.
@@ -14,11 +14,10 @@
1414
* limitations under the License.
1515
*/
1616

17-
import SwiftUI
1817
import LiveKit
18+
import SwiftUI
1919

2020
public struct DisconnectRoomButton<Label: View>: View {
21-
2221
@EnvironmentObject var room: Room
2322

2423
let label: ComponentBuilder<Label>
@@ -30,7 +29,7 @@ public struct DisconnectRoomButton<Label: View>: View {
3029
public var body: some View {
3130
Button {
3231
Task {
33-
try await room.disconnect()
32+
await room.disconnect()
3433
}
3534
} label: {
3635
label()

Sources/LiveKitComponents/Buttons/MicrophoneToggleButton.swift

+5-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023 LiveKit
2+
* Copyright 2024 LiveKit
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.
@@ -14,11 +14,10 @@
1414
* limitations under the License.
1515
*/
1616

17-
import SwiftUI
1817
import LiveKit
18+
import SwiftUI
1919

2020
public struct MicrophoneToggleButton<Label: View, PublishedLabel: View>: View {
21-
2221
@EnvironmentObject var room: Room
2322

2423
@State var isBusy = false
@@ -27,22 +26,20 @@ public struct MicrophoneToggleButton<Label: View, PublishedLabel: View>: View {
2726
let publishedLabel: ComponentBuilder<PublishedLabel>
2827

2928
public init(@ViewBuilder label: @escaping ComponentBuilder<Label>, @ViewBuilder published: @escaping ComponentBuilder<PublishedLabel>) {
30-
3129
self.label = label
32-
self.publishedLabel = published
30+
publishedLabel = published
3331
}
3432

3533
var isMicrophoneEnabled: Bool {
36-
room.localParticipant?.isMicrophoneEnabled() ?? false
34+
room.localParticipant.isMicrophoneEnabled()
3735
}
3836

3937
public var body: some View {
4038
Button {
4139
Task {
4240
isBusy = true
4341
defer { Task { @MainActor in isBusy = false } }
44-
guard let localParticipant = room.localParticipant else { return }
45-
try await localParticipant.setMicrophone(enabled: !isMicrophoneEnabled)
42+
try await room.localParticipant.setMicrophone(enabled: !isMicrophoneEnabled)
4643
}
4744
} label: {
4845
if isMicrophoneEnabled {

Sources/LiveKitComponents/Components.swift

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023 LiveKit
2+
* Copyright 2024 LiveKit
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.
@@ -14,13 +14,10 @@
1414
* limitations under the License.
1515
*/
1616

17-
import SwiftUI
1817
import LiveKit
18+
import SwiftUI
1919

20-
// Scope for Components framework
21-
struct LiveKitComponents {
22-
public static let version = "0.0.1"
23-
}
20+
public let liveKitComponentsVersion = "0.0.1"
2421

2522
public typealias ComponentBuilder<Content: View> = () -> Content
2623
public typealias ParticipantComponentBuilder<Content: View> = (_: Participant) -> Content

Sources/LiveKitComponents/ForEach/ForEachParticipant.swift

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023 LiveKit
2+
* Copyright 2024 LiveKit
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.
@@ -14,14 +14,13 @@
1414
* limitations under the License.
1515
*/
1616

17-
import SwiftUI
1817
import LiveKit
18+
import SwiftUI
1919

2020
/// Loops through `Participant`'s in the current `Room`.
2121
///
2222
/// > Note: References `Room` environment object.
2323
public struct ForEachParticipant<Content: View>: View {
24-
2524
@EnvironmentObject var room: Room
2625

2726
public enum Filter {
@@ -39,15 +38,14 @@ public struct ForEachParticipant<Content: View>: View {
3938

4039
public init(includeLocalParticipant: Bool = true,
4140
filter: Filter = .all,
42-
@ViewBuilder content: @escaping ParticipantComponentBuilder<Content>) {
43-
41+
@ViewBuilder content: @escaping ParticipantComponentBuilder<Content>)
42+
{
4443
self.includeLocalParticipant = includeLocalParticipant
45-
self.filterMode = filter
44+
filterMode = filter
4645
self.content = content
4746
}
4847

4948
private func sortedParticipants() -> [Participant] {
50-
5149
// Include LocalParticipant or not
5250
let participants: [Participant] = Array(room.allParticipants.values).filter { participant in
5351
// Filter out LocalParticipant if not required

Sources/LiveKitComponents/ForEach/ForEachTrackPublication.swift

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023 LiveKit
2+
* Copyright 2024 LiveKit
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.
@@ -14,8 +14,8 @@
1414
* limitations under the License.
1515
*/
1616

17-
import SwiftUI
1817
import LiveKit
18+
import SwiftUI
1919

2020
/// Loops through `TrackPublications`'s in the current `Participant`.
2121
///
@@ -24,7 +24,6 @@ import LiveKit
2424
///
2525
/// > Note: References `Participant` environment object.
2626
public struct ForEachTrackPublication<Content: View>: View {
27-
2827
public enum Filter {
2928
case all
3029
case video
@@ -37,14 +36,14 @@ public struct ForEachTrackPublication<Content: View>: View {
3736
let content: TrackPublicationComponentBuilder<Content>
3837

3938
public init(filter: Filter = .video,
40-
@ViewBuilder content: @escaping TrackPublicationComponentBuilder<Content>) {
41-
39+
@ViewBuilder content: @escaping TrackPublicationComponentBuilder<Content>)
40+
{
4241
self.filter = filter
4342
self.content = content
4443
}
4544

4645
private func computedTrackPublications() -> [TrackPublication] {
47-
let trackPublications = Array(participant.tracks.values)
46+
let trackPublications = Array(participant.trackPublications.values)
4847
switch filter {
4948
case .all: return trackPublications
5049
case .video: return trackPublications.filter { $0.kind == .video }

0 commit comments

Comments
 (0)