Skip to content

Commit 19af0f8

Browse files
authored
Prepare for v2 release (livekit#265)
* data delegates * remove legacy stats * remove reportStats option from RoomConnection * remove deprecated macos screenshare code * remove deprecated dimensions * remove deprecated connect related code * remove deprecated data publish method * update publish(data:) method * set(reportStatistics:)
1 parent 347a27b commit 19af0f8

23 files changed

+40
-615
lines changed

Sources/LiveKit/Core/Engine+TransportDelegate.swift

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,6 @@ import Promises
2121

2222
extension Engine: TransportDelegate {
2323

24-
func transport(_ transport: Transport, didGenerate stats: [TrackStats], target: Livekit_SignalTarget) {
25-
// relay to Room
26-
notify { $0.engine(self, didGenerate: stats, target: target) }
27-
}
28-
2924
func transport(_ transport: Transport, didUpdate pcState: RTCPeerConnectionState) {
3025
log("target: \(transport.target), state: \(pcState)")
3126

Sources/LiveKit/Core/Engine.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -319,14 +319,12 @@ internal extension Engine {
319319
let subscriber = try Transport(config: rtcConfiguration,
320320
target: .subscriber,
321321
primary: self.subscriberPrimary,
322-
delegate: self,
323-
reportStats: room._state.options.reportStats)
322+
delegate: self)
324323

325324
let publisher = try Transport(config: rtcConfiguration,
326325
target: .publisher,
327326
primary: !self.subscriberPrimary,
328-
delegate: self,
329-
reportStats: room._state.options.reportStats)
327+
delegate: self)
330328

331329
publisher.onOffer = { offer in
332330
self.log("publisher onOffer \(offer.sdp)")

Sources/LiveKit/Core/Room+EngineDelegate.swift

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -73,24 +73,6 @@ extension Room: EngineDelegate {
7373
}
7474
}
7575

76-
func engine(_ engine: Engine, didGenerate trackStats: [TrackStats], target: Livekit_SignalTarget) {
77-
78-
let allParticipants = ([[localParticipant],
79-
_state.remoteParticipants.map { $0.value }] as [[Participant?]])
80-
.joined()
81-
.compactMap { $0 }
82-
83-
let allTracks = allParticipants.map { $0._state.tracks.values.map { $0.track } }.joined()
84-
.compactMap { $0 }
85-
86-
// this relies on the last stat entry being the latest
87-
for track in allTracks {
88-
if let stats = trackStats.last(where: { $0.trackId == track.mediaTrack.trackId }) {
89-
track.set(stats: stats)
90-
}
91-
}
92-
}
93-
9476
func engine(_ engine: Engine, didUpdate speakers: [Livekit_SpeakerInfo]) {
9577

9678
let activeSpeakers = _state.mutate { state -> [Participant] in
@@ -187,18 +169,12 @@ extension Room: EngineDelegate {
187169
guard let self = self else { return }
188170

189171
self.delegates.notify(label: { "room.didReceive data: \(userPacket.payload)" }) {
190-
// deprecated
191-
$0.room?(self, participant: participant, didReceive: userPacket.payload)
192-
// new method with topic param
193172
$0.room?(self, participant: participant, didReceiveData: userPacket.payload, topic: userPacket.topic)
194173
}
195174

196175
if let participant = participant {
197176
participant.delegates.notify(label: { "participant.didReceive data: \(userPacket.payload)" }) { [weak participant] (delegate) -> Void in
198177
guard let participant = participant else { return }
199-
// deprecated
200-
delegate.participant?(participant, didReceive: userPacket.payload)
201-
// new method with topic param
202178
delegate.participant?(participant, didReceiveData: userPacket.payload, topic: userPacket.topic)
203179
}
204180
}

Sources/LiveKit/Core/Transport.swift

Lines changed: 1 addition & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,13 @@ internal class Transport: MulticastDelegate<TransportDelegate> {
7171
private let pc: LKRTCPeerConnection
7272
private var pendingCandidates: [LKRTCIceCandidate] = []
7373

74-
// used for stats timer
75-
private let statsTimer = DispatchQueueTimer(timeInterval: 1, queue: .liveKitWebRTC)
76-
private var stats = [String: TrackStats]()
77-
7874
// keep reference to cancel later
7975
private var debounceWorkItem: DispatchWorkItem?
8076

8177
init(config: LKRTCConfiguration,
8278
target: Livekit_SignalTarget,
8379
primary: Bool,
84-
delegate: TransportDelegate,
85-
reportStats: Bool = false) throws {
80+
delegate: TransportDelegate) throws {
8681

8782
// try create peerConnection
8883
guard let pc = Engine.createPeerConnection(config,
@@ -96,29 +91,16 @@ internal class Transport: MulticastDelegate<TransportDelegate> {
9691
self.pc = pc
9792

9893
super.init()
99-
10094
log()
10195

10296
DispatchQueue.liveKitWebRTC.sync { pc.delegate = self }
10397
add(delegate: delegate)
104-
105-
statsTimer.handler = { [weak self] in
106-
self?.onStatsTimer()
107-
}
108-
109-
set(reportStats: reportStats)
11098
}
11199

112100
deinit {
113-
statsTimer.suspend()
114101
log()
115102
}
116103

117-
internal func set(reportStats: Bool) {
118-
log("reportStats: \(reportStats)")
119-
reportStats ? statsTimer.resume() : statsTimer.suspend()
120-
}
121-
122104
@discardableResult
123105
func addIceCandidate(_ candidate: LKRTCIceCandidate) -> Promise<Void> {
124106

@@ -196,7 +178,6 @@ internal class Transport: MulticastDelegate<TransportDelegate> {
196178

197179
// prevent debounced negotiate firing
198180
self.debounceWorkItem?.cancel()
199-
self.statsTimer.suspend()
200181

201182
// can be async
202183
DispatchQueue.liveKitWebRTC.async {
@@ -224,48 +205,6 @@ extension Transport {
224205
func statistics(for receiver: LKRTCRtpReceiver) async -> LKRTCStatisticsReport {
225206
await pc.statistics(for: receiver)
226207
}
227-
228-
func onStatsTimer() {
229-
230-
statsTimer.suspend()
231-
232-
pc.stats(for: nil, statsOutputLevel: .standard) { [weak self] reports in
233-
234-
guard let self = self else { return }
235-
236-
self.statsTimer.resume()
237-
238-
let tracks = reports
239-
.filter { $0.type == TrackStats.keyTypeSSRC }
240-
.map { entry -> TrackStats? in
241-
242-
let findPrevious = { () -> TrackStats? in
243-
guard let ssrc = entry.values[TrackStats.keyTypeSSRC],
244-
let previous = self.stats[ssrc] else { return nil }
245-
return previous
246-
}
247-
248-
return TrackStats(from: entry.values, previous: findPrevious())
249-
}
250-
.compactMap { $0 }
251-
252-
for track in tracks {
253-
// cache
254-
self.stats[track.ssrc] = track
255-
}
256-
257-
if !tracks.isEmpty {
258-
self.notify { $0.transport(self, didGenerate: tracks, target: self.target) }
259-
}
260-
261-
// clean up
262-
// for key in self.stats.keys {
263-
// if !tracks.contains(where: { $0.ssrc == key }) {
264-
// self.stats.removeValue(forKey: key)
265-
// }
266-
// }
267-
}
268-
}
269208
}
270209

271210
// MARK: - RTCPeerConnectionDelegate

Sources/LiveKit/LiveKit.swift

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,6 @@ public class LiveKit: NSObject {
3838
@objc(sdkVersion)
3939
public static let version = "1.1.3"
4040

41-
@available(*, deprecated, message: "Use Room.connect() instead, protocol v8 and higher do not support this method")
42-
public static func connect(
43-
_ url: String,
44-
_ token: String,
45-
delegate: RoomDelegate? = nil,
46-
connectOptions: ConnectOptions = ConnectOptions(),
47-
roomOptions: RoomOptions = RoomOptions()) -> Promise<Room> {
48-
49-
let room = Room(delegate: delegate,
50-
// Override with protocol v7 or lower when using this deprecated method
51-
connectOptions: connectOptions.protocolVersion >= .v8 ? connectOptions.copyWith(protocolVersion: .v7) : connectOptions,
52-
roomOptions: roomOptions)
53-
54-
return room.connect(url, token)
55-
}
56-
5741
@objc
5842
public static func setLoggerStandardOutput() {
5943
LoggingSystem.bootstrap({

Sources/LiveKit/Participant/LocalParticipant+Async.swift

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -72,19 +72,6 @@ public extension LocalParticipant {
7272
}
7373
}
7474

75-
func publishData(_ data: Data,
76-
reliability: Reliability = .reliable,
77-
destination: [String] = []) async throws {
78-
79-
try await withCheckedThrowingContinuation { continuation in
80-
publishData(data: data, reliability: reliability, destination: destination).then(on: queue) { result in
81-
continuation.resume(returning: result)
82-
}.catch(on: queue) { error in
83-
continuation.resume(throwing: error)
84-
}
85-
}
86-
}
87-
8875
///
8976
/// Publish data to the other participants in the room
9077
///
@@ -102,7 +89,7 @@ public extension LocalParticipant {
10289
///
10390
func publish(data: Data,
10491
reliability: Reliability = .reliable,
105-
destinations: [RemoteParticipant]? = nil,
92+
destinations: [Sid]? = nil,
10693
topic: String? = nil,
10794
options: DataPublishOptions? = nil) async throws {
10895

Sources/LiveKit/Participant/LocalParticipant+ObjC.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ extension LocalParticipant {
6767
@discardableResult
6868
public func publishDataObjC(data: Data,
6969
reliability: Reliability = .reliable,
70-
destination: [String] = []) -> Promise<Void>.ObjCPromise<NSNull> {
70+
destinations: [String] = []) -> Promise<Void>.ObjCPromise<NSNull> {
7171

72-
publishData(data: data, reliability: reliability, destination: destination).asObjCPromise()
72+
publish(data: data, reliability: reliability, destinations: destinations).asObjCPromise()
7373
}
7474

7575
@objc(setTrackSubscriptionPermissionsWithAllParticipantsAllowed:trackPermissions:)

Sources/LiveKit/Participant/LocalParticipant.swift

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -282,42 +282,20 @@ public class LocalParticipant: Participant {
282282
/// - reliability: Toggle between sending relialble vs lossy delivery.
283283
/// For data that you need delivery guarantee (such as chat messages), use Reliable.
284284
/// For data that should arrive as quickly as possible, but you are ok with dropped packets, use Lossy.
285-
/// - destination: SIDs of the participants who will receive the message. If empty, deliver to everyone
286-
///
287-
/// > Notice: Deprecated, use ``publish(data:reliability:destinations:topic:options:)-2581z`` instead.
288-
@available(*, deprecated, renamed: "publish(data:reliability:destinations:topic:options:)")
289-
@discardableResult
290-
public func publishData(data: Data,
291-
reliability: Reliability = .reliable,
292-
destination: [String] = []) -> Promise<Void> {
293-
294-
let userPacket = Livekit_UserPacket.with {
295-
$0.destinationSids = destination
296-
$0.payload = data
297-
$0.participantSid = self.sid
298-
}
299-
300-
return room.engine.send(userPacket: userPacket,
301-
reliability: reliability)
302-
}
303-
304-
///
305-
/// Promise version of ``publish(data:reliability:destinations:topic:options:)-75jme``.
306-
///
285+
/// - destinations: SIDs of the participants who will receive the message. If empty, deliver to everyone
307286
@discardableResult
308287
public func publish(data: Data,
309288
reliability: Reliability = .reliable,
310-
destinations: [RemoteParticipant]? = nil,
289+
destinations: [Sid]? = nil,
311290
topic: String? = nil,
312291
options: DataPublishOptions? = nil) -> Promise<Void> {
313292

314293
let options = options ?? self.room._state.options.defaultDataPublishOptions
315-
let destinations = destinations?.map { $0.sid }
316294

317295
let userPacket = Livekit_UserPacket.with {
318-
$0.destinationSids = destinations ?? options.destinations
319-
$0.payload = data
320296
$0.participantSid = self.sid
297+
$0.payload = data
298+
$0.destinationSids = destinations ?? options.destinations
321299
$0.topic = topic ?? options.topic ?? ""
322300
}
323301

Sources/LiveKit/Protocols/EngineDelegate.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,4 @@ internal protocol EngineDelegate: AnyObject {
2424
func engine(_ engine: Engine, didAddTrack track: LKRTCMediaStreamTrack, rtpReceiver: LKRTCRtpReceiver, streams: [LKRTCMediaStream])
2525
func engine(_ engine: Engine, didRemove track: LKRTCMediaStreamTrack)
2626
func engine(_ engine: Engine, didReceive userPacket: Livekit_UserPacket)
27-
func engine(_ engine: Engine, didGenerate stats: [TrackStats], target: Livekit_SignalTarget)
2827
}

Sources/LiveKit/Protocols/ParticipantDelegate.swift

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,6 @@ public protocol ParticipantDelegate: AnyObject {
104104
func participant(_ participant: RemoteParticipant, didUnsubscribe publication: RemoteTrackPublication, track: Track)
105105

106106
/// Data was received from a ``RemoteParticipant``.
107-
///
108-
/// > Notice: Deprecated, use ``participant(_:didReceiveData:topic:)`` instead.
109-
@objc(participant:didReceiveData:)
110-
@available(*, deprecated, renamed: "participant(_:didReceiveData:topic:)")
111-
optional
112-
func participant(_ participant: RemoteParticipant, didReceive data: Data)
113-
114107
@objc(participant:didReceiveData:topic:) optional
115108
func participant(_ participant: RemoteParticipant, didReceiveData data: Data, topic: String)
116109
}

Sources/LiveKit/Protocols/RoomDelegate.swift

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,6 @@ public protocol RoomDelegateObjC: AnyObject {
119119

120120
/// Same with ``ParticipantDelegate/participant(_:didReceive:)-2t55a``
121121
/// participant could be nil if data was sent by server api.
122-
///
123-
/// Deprecated, use ``room(_:participant:didReceiveData:topic:)`` instead.
124-
@objc(room:participant:didReceiveData:)
125-
@available(*, deprecated, renamed: "room(_:participant:didReceiveData:topic:)")
126-
optional
127-
func room(_ room: Room, participant: RemoteParticipant?, didReceive data: Data)
128-
129122
@objc(room:participant:didReceiveData:topic:) optional
130123
func room(_ room: Room, participant: RemoteParticipant?, didReceiveData data: Data, topic: String)
131124

Sources/LiveKit/Protocols/TrackDelegate.swift

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,6 @@ public protocol TrackDelegate: AnyObject {
3636
@objc(track:didUpdateMuted:shouldSendSignal:) optional
3737
func track(_ track: Track, didUpdate muted: Bool, shouldSendSignal: Bool)
3838

39-
/// Statistics for the track has been generated.
40-
@available(*, deprecated, message: "Use track:didUpdateStatistics: instead")
41-
@objc(track:didUpdateStats:) optional
42-
func track(_ track: Track, didUpdate stats: TrackStats)
43-
4439
/// Statistics for the track has been generated (v2).
4540
@objc(track:didUpdateStatistics:) optional
4641
func track(_ track: Track, didUpdateStatistics: TrackStatistics)

Sources/LiveKit/Protocols/TransportDelegate.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,4 @@ internal protocol TransportDelegate: AnyObject {
2525
func transport(_ transport: Transport, didAddTrack: LKRTCMediaStreamTrack, rtpReceiver: LKRTCRtpReceiver, streams: [LKRTCMediaStream])
2626
func transport(_ transport: Transport, didRemove track: LKRTCMediaStreamTrack)
2727
func transportShouldNegotiate(_ transport: Transport)
28-
func transport(_ transport: Transport, didGenerate stats: [TrackStats], target: Livekit_SignalTarget)
2928
}

Sources/LiveKit/SwiftUI/SwiftUIVideoView.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ import SwiftUI
2121
internal class TrackDelegateReceiver: TrackDelegate, Loggable {
2222

2323
@Binding var dimensions: Dimensions?
24-
@Binding var stats: TrackStats?
24+
@Binding var statistics: TrackStatistics?
2525

26-
init(dimensions: Binding<Dimensions?>, stats: Binding<TrackStats?>) {
26+
init(dimensions: Binding<Dimensions?>, statistics: Binding<TrackStatistics?>) {
2727
self._dimensions = dimensions
28-
self._stats = stats
28+
self._statistics = statistics
2929
}
3030

3131
func track(_ track: VideoTrack, didUpdate dimensions: Dimensions?) {
@@ -34,9 +34,9 @@ internal class TrackDelegateReceiver: TrackDelegate, Loggable {
3434
}
3535
}
3636

37-
func track(_ track: Track, didUpdate stats: TrackStats) {
37+
func track(_ track: Track, didUpdateStatistics statistics: TrackStatistics) {
3838
Task.detached { @MainActor in
39-
self.stats = stats
39+
self.statistics = statistics
4040
}
4141
}
4242
}
@@ -83,7 +83,7 @@ public struct SwiftUIVideoView: NativeViewRepresentable {
8383
debugMode: Bool = false,
8484
isRendering: Binding<Bool> = .constant(false),
8585
dimensions: Binding<Dimensions?> = .constant(nil),
86-
trackStats: Binding<TrackStats?> = .constant(nil)) {
86+
trackStatistics: Binding<TrackStatistics?> = .constant(nil)) {
8787

8888
self.track = track
8989
self.layoutMode = layoutMode
@@ -95,14 +95,14 @@ public struct SwiftUIVideoView: NativeViewRepresentable {
9595
self._dimensions = dimensions
9696

9797
self.trackDelegateReceiver = TrackDelegateReceiver(dimensions: dimensions,
98-
stats: trackStats)
98+
statistics: trackStatistics)
9999

100100
self.videoViewDelegateReceiver = VideoViewDelegateReceiver(isRendering: isRendering)
101101

102102
// update binding value
103103
Task.detached { @MainActor in
104104
dimensions.wrappedValue = track.dimensions
105-
trackStats.wrappedValue = track.stats
105+
trackStatistics.wrappedValue = track.statistics
106106
}
107107

108108
// listen for TrackDelegate

0 commit comments

Comments
 (0)