Skip to content

Commit 73e40ad

Browse files
authored
Fix ObjC annotations (#915)
I switched to `@objcMembers` globally, leveraging swiftlint `redundant_objc_attribute` rule here, should solve this problem forever...
1 parent 8173f63 commit 73e40ad

52 files changed

Lines changed: 81 additions & 305 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.changes/missing-objc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
patch type="fixed" "Missing objc annotations for some objc class members"

.swiftlint.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,8 @@ custom_rules:
2727
regex: "(let|var)\\s+\\w+\\s*:\\s*Task<Void,"
2828
message: "Prefer AnyTaskCancellable over manually managing Task<Void, ...>. This allows for safer cleanup, similar to Combine's AnyCancellable."
2929
severity: warning
30+
prefer_objc_members:
31+
name: "Prefer @objcMembers for classes"
32+
regex: "@objc(?![(\\[])\\s+(?:(?:public|open|final|internal|package)\\s+)*class\\b"
33+
message: "Use @objcMembers instead of @objc for classes to implicitly expose members to Objective-C."
34+
severity: warning

Sources/LiveKit/Core/PreConnectAudioBuffer.swift

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import AVFAudio
1818
import Foundation
1919

2020
/// A buffer that captures audio before connecting to the server.
21-
@objc
21+
@objcMembers
2222
public final class PreConnectAudioBuffer: NSObject, Sendable, Loggable {
2323
public typealias OnError = @Sendable (Error) -> Void
2424

@@ -29,15 +29,12 @@ public final class PreConnectAudioBuffer: NSObject, Sendable, Loggable {
2929
}
3030

3131
/// The default data topic used to send the audio buffer.
32-
@objc
3332
public static let dataTopic = "lk.agent.pre-connect-audio-buffer"
3433

3534
/// The room instance to send the audio buffer to.
36-
@objc
3735
public var room: Room? { state.room }
3836

3937
/// The audio recorder instance.
40-
@objc
4138
public var recorder: LocalAudioTrackRecorder? { state.recorder }
4239

4340
private let state = StateSync<State>(State())
@@ -54,7 +51,6 @@ public final class PreConnectAudioBuffer: NSObject, Sendable, Loggable {
5451
/// - Parameters:
5552
/// - room: The room instance to send the audio buffer to.
5653
/// - onError: The error handler to call when an error occurs while sending the audio buffer.
57-
@objc
5854
public init(room: Room?, onError: OnError? = nil) {
5955
state.mutate {
6056
$0.room = room
@@ -67,7 +63,6 @@ public final class PreConnectAudioBuffer: NSObject, Sendable, Loggable {
6763
stopRecording()
6864
}
6965

70-
@objc
7166
public func setErrorHandler(_ onError: OnError?) {
7267
state.mutate { $0.onError = onError }
7368
}
@@ -78,7 +73,6 @@ public final class PreConnectAudioBuffer: NSObject, Sendable, Loggable {
7873
/// The room connection needs to be established and the remote participant needs to subscribe to the audio track
7974
/// before the timeout is reached. Otherwise, the audio stream will be flushed without sending.
8075
/// - recorder: Optional custom recorder instance. If not provided, a new one will be created.
81-
@objc
8276
public func startRecording(timeout: TimeInterval = Constants.timeout, recorder: LocalAudioTrackRecorder? = nil) async throws {
8377
room?.add(delegate: self)
8478

@@ -109,7 +103,6 @@ public final class PreConnectAudioBuffer: NSObject, Sendable, Loggable {
109103
/// Stop capturing audio.
110104
/// - Parameters:
111105
/// - flush: If `true`, the audio stream will be flushed immediately without sending.
112-
@objc
113106
public func stopRecording(flush: Bool = false) {
114107
guard let recorder, recorder.isRecording else { return }
115108

@@ -130,7 +123,6 @@ public final class PreConnectAudioBuffer: NSObject, Sendable, Loggable {
130123
/// - room: The room instance to send the audio data.
131124
/// - agents: The agents to send the audio data to.
132125
/// - topic: The topic to send the audio data.
133-
@objc
134126
public func sendAudioData(to room: Room, agents: [Participant.Identity], on topic: String = dataTopic) async throws {
135127
guard !agents.isEmpty else { return }
136128

Sources/LiveKit/Core/Room.swift

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import Foundation
2323
import Network
2424
#endif
2525

26-
@objc
26+
@objcMembers
2727
// swiftlint:disable:next type_body_length
2828
public class Room: NSObject, @unchecked Sendable, ObservableObject, Loggable {
2929
// MARK: - MulticastDelegate
@@ -37,71 +37,52 @@ public class Room: NSObject, @unchecked Sendable, ObservableObject, Loggable {
3737
// MARK: - Public
3838

3939
/// Server assigned id of the Room.
40-
@objc
4140
public var sid: Sid? { _state.sid }
4241

4342
/// Server assigned id of the Room. *async* version of ``Room/sid``.
44-
@objc
4543
public func sid() async throws -> Sid {
4644
try await _sidCompleter.wait()
4745
}
4846

49-
@objc
5047
public var name: String? { _state.name }
5148

5249
/// Room's metadata.
53-
@objc
5450
public var metadata: String? { _state.metadata }
5551

56-
@objc
5752
public var serverVersion: String? { _state.serverInfo?.version.nilIfEmpty }
5853

5954
/// Region code the client is currently connected to.
60-
@objc
6155
public var serverRegion: String? { _state.serverInfo?.region.nilIfEmpty }
6256

6357
/// Region code the client is currently connected to.
64-
@objc
6558
public var serverNodeId: String? { _state.serverInfo?.nodeID.nilIfEmpty }
6659

67-
@objc
6860
public var remoteParticipants: [Participant.Identity: RemoteParticipant] { _state.remoteParticipants }
6961

70-
@objc
7162
public var activeSpeakers: [Participant] { _state.activeSpeakers }
7263

73-
@objc
7464
public var creationTime: Date? { _state.creationTime }
7565

7666
/// If the current room has a participant with `recorder:true` in its JWT grant.
77-
@objc
7867
public var isRecording: Bool { _state.isRecording }
7968

80-
@objc
8169
public var maxParticipants: Int { _state.maxParticipants }
8270

83-
@objc
8471
public var participantCount: Int { _state.numParticipants }
8572

86-
@objc
8773
public var publishersCount: Int { _state.numPublishers }
8874

8975
/// User-provided URL.
90-
@objc
9176
public var url: String? { _state.providedUrl?.absoluteString }
9277

9378
/// Actual server URL used for the current connection (may include a regional URL).
94-
@objc
9579
public var connectedUrl: String? { _state.connectedUrl?.absoluteString }
9680

97-
@objc
9881
public var token: String? { _state.token }
9982

10083
/// Current ``ConnectionState`` of the ``Room``.
101-
@objc
10284
public var connectionState: ConnectionState { _state.connectionState }
10385

104-
@objc
10586
public var disconnectError: LiveKitError? { _state.disconnectError }
10687

10788
public var connectStopwatch: Stopwatch { _state.connectStopwatch }
@@ -110,7 +91,6 @@ public class Room: NSObject, @unchecked Sendable, ObservableObject, Loggable {
11091

11192
public var e2eeManager: E2EEManager?
11293

113-
@objc
11494
public lazy var localParticipant: LocalParticipant = .init(room: self)
11595

11696
let primaryTransportConnectedCompleter = AsyncCompleter<Void>(label: "Primary transport connect", defaultTimeout: .defaultTransportState)
@@ -219,14 +199,12 @@ public class Room: NSObject, @unchecked Sendable, ObservableObject, Loggable {
219199

220200
// MARK: Objective-C Support
221201

222-
@objc
223202
override public convenience init() {
224203
self.init(delegate: nil,
225204
connectOptions: ConnectOptions(),
226205
roomOptions: RoomOptions())
227206
}
228207

229-
@objc
230208
// swiftlint:disable:next cyclomatic_complexity function_body_length
231209
public init(delegate: RoomDelegate? = nil,
232210
connectOptions: ConnectOptions? = nil,
@@ -326,7 +304,6 @@ public class Room: NSObject, @unchecked Sendable, ObservableObject, Loggable {
326304
}
327305
}
328306

329-
@objc
330307
// swiftlint:disable:next cyclomatic_complexity function_body_length
331308
public func connect(url urlString: String,
332309
token: String,
@@ -467,7 +444,6 @@ public class Room: NSObject, @unchecked Sendable, ObservableObject, Loggable {
467444
log("Connected to \(String(describing: self))", .info)
468445
}
469446

470-
@objc
471447
public func disconnect() async {
472448
let shouldDisconnect = _state.mutate {
473449
switch $0.connectionState {

Sources/LiveKit/DataStream/Incoming/ByteStreamReader.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@
1717
import Foundation
1818

1919
/// An asynchronous sequence of chunks read from a byte data stream.
20-
@objc
20+
@objcMembers
2121
public final class ByteStreamReader: NSObject, AsyncSequence, Sendable {
2222
/// Information about the incoming byte stream.
23-
@objc
2423
public let info: ByteStreamInfo
2524

2625
let source: StreamReaderSource
@@ -36,7 +35,6 @@ public final class ByteStreamReader: NSObject, AsyncSequence, Sendable {
3635
/// - Returns: The data consisting of all concatenated chunks.
3736
/// - Throws: ``StreamError`` if an error occurs while reading the stream.
3837
///
39-
@objc
4038
public func readAll() async throws -> Data {
4139
try await source.collect()
4240
}
@@ -70,7 +68,6 @@ extension ByteStreamReader {
7068
/// - Returns: The URL of the written file on disk.
7169
/// - Throws: ``StreamError`` if an error occurs while reading the stream.
7270
///
73-
@objc
7471
public func writeToFile(
7572
in directory: URL = FileManager.default.temporaryDirectory,
7673
name nameOverride: String? = nil

Sources/LiveKit/DataStream/Incoming/TextStreamReader.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@
1717
import Foundation
1818

1919
/// An asynchronous sequence of chunks read from a text data stream.
20-
@objc
20+
@objcMembers
2121
public final class TextStreamReader: NSObject, AsyncSequence, Sendable {
2222
/// Information about the incoming text stream.
23-
@objc
2423
public let info: TextStreamInfo
2524

2625
let source: StreamReaderSource
@@ -36,7 +35,6 @@ public final class TextStreamReader: NSObject, AsyncSequence, Sendable {
3635
/// - Returns: The string consisting of all concatenated chunks.
3736
/// - Throws: ``StreamError`` if an error occurs while reading the stream.
3837
///
39-
@objc
4038
public func readAll() async throws -> String {
4139
try await collect()
4240
}

Sources/LiveKit/DataStream/Outgoing/ByteStreamWriter.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@
1717
import Foundation
1818

1919
/// Asynchronously write to an open byte stream.
20-
@objc
20+
@objcMembers
2121
public final class ByteStreamWriter: NSObject, Sendable {
2222
/// Information about the outgoing byte stream.
23-
@objc
2423
public let info: ByteStreamInfo
2524

2625
private let destination: StreamWriterDestination

Sources/LiveKit/DataStream/Outgoing/TextStreamWriter.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@
1717
import Foundation
1818

1919
/// Asynchronously write to an open text stream.
20-
@objc
20+
@objcMembers
2121
public final class TextStreamWriter: NSObject, Sendable {
2222
/// Information about the outgoing text stream.
23-
@objc
2423
public let info: TextStreamInfo
2524

2625
private let destination: StreamWriterDestination

Sources/LiveKit/E2EE/E2EEManager.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import Foundation
1919

2020
internal import LiveKitWebRTC
2121

22-
@objc
22+
@objcMembers
2323
public class E2EEManager: NSObject, @unchecked Sendable, ObservableObject, Loggable {
2424
// Private delegate adapter to hide RTCFrameCryptorDelegate symbol
2525
private class DelegateAdapter: NSObject, LKRTCFrameCryptorDelegate {

Sources/LiveKit/E2EE/KeyProvider.swift

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,18 @@ public let defaultRatchetWindowSize: Int32 = 0
2525
public let defaultFailureTolerance: Int32 = -1
2626
public let defaultKeyRingSize: Int32 = 16
2727

28-
@objc
28+
@objcMembers
2929
public final class KeyProviderOptions: NSObject, Sendable {
30-
@objc
3130
public let sharedKey: Bool
3231

33-
@objc
3432
public let ratchetSalt: Data
3533

36-
@objc
3734
public let ratchetWindowSize: Int32
3835

39-
@objc
4036
public let uncryptedMagicBytes: Data
4137

42-
@objc
4338
public let failureTolerance: Int32
4439

45-
@objc
4640
public let keyRingSize: Int32
4741

4842
public init(sharedKey: Bool = true,
@@ -84,9 +78,8 @@ public final class KeyProviderOptions: NSObject, Sendable {
8478
}
8579
}
8680

87-
@objc
81+
@objcMembers
8882
public final class BaseKeyProvider: NSObject, Loggable, Sendable {
89-
@objc
9083
public let options: KeyProviderOptions
9184

9285
// MARK: - Internal
@@ -182,12 +175,10 @@ public final class BaseKeyProvider: NSObject, Loggable, Sendable {
182175
rtcKeyProvider.setSifTrailer(trailer)
183176
}
184177

185-
@objc
186178
public func getCurrentKeyIndex() -> Int32 {
187179
_state.currentKeyIndex
188180
}
189181

190-
@objc
191182
public func setCurrentKeyIndex(_ index: Int32) {
192183
_state.mutate { $0.currentKeyIndex = index % options.keyRingSize }
193184
}

0 commit comments

Comments
 (0)