From fabc15212998b09cf7575d83d5e1307e6a4f5577 Mon Sep 17 00:00:00 2001 From: Hiroshi Horie <548776+hiroshihorie@users.noreply.github.com> Date: Thu, 16 Nov 2023 08:57:40 +0800 Subject: [PATCH] strip unused code --- Sources/LiveKit/Core/Engine.swift | 11 +- Sources/LiveKit/Core/Room.swift | 4 +- Sources/LiveKit/Core/SignalClient.swift | 5 +- Sources/LiveKit/Extensions/Logger.swift | 2 - Sources/LiveKit/Participant/Participant.swift | 4 +- Sources/LiveKit/Support/DisplayLink.swift | 132 ------------------ .../Track/Capturers/VideoCapturer.swift | 4 +- Sources/LiveKit/Track/Track.swift | 4 +- Sources/LiveKit/Types/ConnectionState.swift | 5 - Sources/LiveKit/Types/Dimensions.swift | 19 --- Sources/LiveKit/Types/VideoQuality.swift | 10 -- Sources/LiveKit/Views/VideoView.swift | 2 +- 12 files changed, 11 insertions(+), 191 deletions(-) delete mode 100644 Sources/LiveKit/Support/DisplayLink.swift diff --git a/Sources/LiveKit/Core/Engine.swift b/Sources/LiveKit/Core/Engine.swift index 3536f6668..3a37ca102 100644 --- a/Sources/LiveKit/Core/Engine.swift +++ b/Sources/LiveKit/Core/Engine.swift @@ -23,13 +23,11 @@ import Foundation @_implementationOnly import WebRTC class Engine: MulticastDelegate { - let queue = DispatchQueue(label: "LiveKitSDK.engine", qos: .default) - // MARK: - Public public typealias ConditionEvalFunc = (_ newState: State, _ oldState: State?) -> Bool - struct State: ReconnectableState, Equatable { + struct State: Equatable { var connectOptions: ConnectOptions var url: String? var token: String? @@ -62,13 +60,12 @@ class Engine: MulticastDelegate { let block: () -> Void } - var subscriberPrimary: Bool = false - private var primary: Transport? { subscriberPrimary ? subscriber : publisher } + public internal(set) var subscriberPrimary: Bool = false // MARK: - DataChannels - var subscriberDC = DataChannelPair(target: .subscriber) - var publisherDC = DataChannelPair(target: .publisher) + public internal(set) var subscriberDC = DataChannelPair(target: .subscriber) + public internal(set) var publisherDC = DataChannelPair(target: .publisher) private var _blockProcessQueue = DispatchQueue(label: "LiveKitSDK.engine.pendingBlocks", qos: .default) diff --git a/Sources/LiveKit/Core/Room.swift b/Sources/LiveKit/Core/Room.swift index 8dbc3c41e..68bb7bb2d 100644 --- a/Sources/LiveKit/Core/Room.swift +++ b/Sources/LiveKit/Core/Room.swift @@ -24,9 +24,7 @@ import Foundation public class Room: NSObject, ObservableObject, Loggable { // MARK: - MulticastDelegate - var delegates = MulticastDelegate() - - let queue = DispatchQueue(label: "LiveKitSDK.room", qos: .default) + public let delegates = MulticastDelegate() // MARK: - Public diff --git a/Sources/LiveKit/Core/SignalClient.swift b/Sources/LiveKit/Core/SignalClient.swift index a9cf1a7b7..72bd7b7d4 100644 --- a/Sources/LiveKit/Core/SignalClient.swift +++ b/Sources/LiveKit/Core/SignalClient.swift @@ -35,8 +35,7 @@ class SignalClient: MulticastDelegate { let joinResponseCompleter = AsyncCompleter(label: "Join response", timeOut: .defaultJoinResponse) let _addTrackCompleters = CompleterMapActor(label: "Completers for add track", timeOut: .defaultPublish) - struct State: ReconnectableState, Equatable { - var reconnectMode: ReconnectMode? + struct State: Equatable { var connectionState: ConnectionState = .disconnected() } @@ -99,7 +98,7 @@ class SignalClient: MulticastDelegate { log("Connecting with url: \(urlString)") _state.mutate { - $0.reconnectMode = reconnectMode + // $0.reconnectMode = reconnectMode $0.connectionState = .connecting } diff --git a/Sources/LiveKit/Extensions/Logger.swift b/Sources/LiveKit/Extensions/Logger.swift index cdd039264..856036552 100644 --- a/Sources/LiveKit/Extensions/Logger.swift +++ b/Sources/LiveKit/Extensions/Logger.swift @@ -20,8 +20,6 @@ import Logging /// Allows to extend with custom `log` method which automatically captures current type (class name). public protocol Loggable {} -private var _scopedMetadataKey = "scopedMetadata" - public typealias ScopedMetadata = CustomStringConvertible typealias ScopedMetadataContainer = [String: ScopedMetadata] diff --git a/Sources/LiveKit/Participant/Participant.swift b/Sources/LiveKit/Participant/Participant.swift index d06086653..d056724e3 100644 --- a/Sources/LiveKit/Participant/Participant.swift +++ b/Sources/LiveKit/Participant/Participant.swift @@ -22,9 +22,7 @@ import Foundation public class Participant: NSObject, ObservableObject, Loggable { // MARK: - MulticastDelegate - var delegates = MulticastDelegate() - - let queue = DispatchQueue(label: "LiveKitSDK.participant", qos: .default) + public let delegates = MulticastDelegate() /// This will be an empty String for LocalParticipants until connected. @objc diff --git a/Sources/LiveKit/Support/DisplayLink.swift b/Sources/LiveKit/Support/DisplayLink.swift deleted file mode 100644 index 70a864da5..000000000 --- a/Sources/LiveKit/Support/DisplayLink.swift +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Copyright 2023 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. - */ - -import Foundation - -protocol DisplayLink { - var onFrame: ((DisplayLinkFrame) -> Void)? { get set } - var isPaused: Bool { get set } -} - -struct DisplayLinkFrame { - // The system timestamp for the frame to be drawn - var timestamp: TimeInterval - // The duration between each display update - var duration: TimeInterval -} - -#if os(iOS) - - import QuartzCore - - typealias PlatformDisplayLink = iOSDisplayLink - - class iOSDisplayLink: DisplayLink { - var onFrame: ((DisplayLinkFrame) -> Void)? - - var isPaused: Bool { - get { _displayLink.isPaused } - set { _displayLink.isPaused = newValue } - } - - let _displayLink: CADisplayLink - - let _target = DisplayLinkTarget() - - init() { - _displayLink = CADisplayLink(target: _target, selector: #selector(DisplayLinkTarget.frame(_:))) - _displayLink.isPaused = true - _displayLink.add(to: RunLoop.main, forMode: RunLoop.Mode.common) - - _target.callback = { [weak self] frame in - guard let self else { return } - self.onFrame?(frame) - } - } - - deinit { - _displayLink.invalidate() - } - - class DisplayLinkTarget { - var callback: ((DisplayLinkFrame) -> Void)? - - @objc - dynamic func frame(_ _displayLink: CADisplayLink) { - let frame = DisplayLinkFrame( - timestamp: _displayLink.timestamp, - duration: _displayLink.duration - ) - - callback?(frame) - } - } - } - -#elseif os(macOS) - - import CoreVideo - - typealias PlatformDisplayLink = macOSDisplayLink - - class macOSDisplayLink: DisplayLink { - var onFrame: ((DisplayLinkFrame) -> Void)? - - var isPaused: Bool = true { - didSet { - guard isPaused != oldValue else { return } - if isPaused == true { - CVDisplayLinkStop(_displayLink) - } else { - CVDisplayLinkStart(_displayLink) - } - } - } - - private var _displayLink: CVDisplayLink = { - var dl: CVDisplayLink? - CVDisplayLinkCreateWithActiveCGDisplays(&dl) - return dl! - }() - - init() { - CVDisplayLinkSetOutputHandler(_displayLink) { [weak self] _, inNow, inOutputTime, _, _ -> CVReturn in - - guard let self else { return kCVReturnSuccess } - - let frame = DisplayLinkFrame( - timestamp: inNow.pointee.timeInterval, - duration: inOutputTime.pointee.timeInterval - inNow.pointee.timeInterval - ) - - self.onFrame?(frame) - - return kCVReturnSuccess - } - } - - deinit { - isPaused = true - } - } - - extension CVTimeStamp { - var timeInterval: TimeInterval { - TimeInterval(videoTime) / TimeInterval(videoTimeScale) - } - } - -#endif diff --git a/Sources/LiveKit/Track/Capturers/VideoCapturer.swift b/Sources/LiveKit/Track/Capturers/VideoCapturer.swift index 8161199d9..2918cb440 100644 --- a/Sources/LiveKit/Track/Capturers/VideoCapturer.swift +++ b/Sources/LiveKit/Track/Capturers/VideoCapturer.swift @@ -41,9 +41,7 @@ public protocol VideoCapturerDelegate: AnyObject { public class VideoCapturer: NSObject, Loggable, VideoCapturerProtocol { // MARK: - MulticastDelegate - var delegates = MulticastDelegate() - - let queue = DispatchQueue(label: "LiveKitSDK.videoCapturer", qos: .default) + public let delegates = MulticastDelegate() /// Array of supported pixel formats that can be used to capture a frame. /// diff --git a/Sources/LiveKit/Track/Track.swift b/Sources/LiveKit/Track/Track.swift index e0684e0c0..11e151d4f 100644 --- a/Sources/LiveKit/Track/Track.swift +++ b/Sources/LiveKit/Track/Track.swift @@ -96,9 +96,7 @@ public class Track: NSObject, Loggable { // MARK: - Internal - var delegates = MulticastDelegate() - - let queue = DispatchQueue(label: "LiveKitSDK.track", qos: .default) + public let delegates = MulticastDelegate() /// Only for ``LocalTrack``s. private(set) var _publishState: PublishState = .unpublished diff --git a/Sources/LiveKit/Types/ConnectionState.swift b/Sources/LiveKit/Types/ConnectionState.swift index 5b47a0670..aeaeedb2d 100644 --- a/Sources/LiveKit/Types/ConnectionState.swift +++ b/Sources/LiveKit/Types/ConnectionState.swift @@ -77,8 +77,3 @@ extension ConnectionState: Equatable { return error } } - -protocol ReconnectableState { - var reconnectMode: ReconnectMode? { get } - var connectionState: ConnectionState { get } -} diff --git a/Sources/LiveKit/Types/Dimensions.swift b/Sources/LiveKit/Types/Dimensions.swift index 1eb40d904..72f5eae4d 100644 --- a/Sources/LiveKit/Types/Dimensions.swift +++ b/Sources/LiveKit/Types/Dimensions.swift @@ -88,10 +88,6 @@ extension Dimensions { Swift.max(width, height) } - var sum: Int32 { - width + height - } - // TODO: Find better name var area: Int32 { width * height @@ -155,17 +151,6 @@ extension Dimensions { return VideoQuality.rids.compactMap { rid in result.first(where: { $0.rid == rid }) } } - func computeSuggestedPresetIndex(in presets: [VideoParameters]) -> Int { - assert(!presets.isEmpty) - var result = 0 - for preset in presets { - if width >= preset.dimensions.width, height >= preset.dimensions.height { - result += 1 - } - } - return result - } - func videoLayers(for encodings: [LKRTCRtpEncodingParameters]) -> [Livekit_VideoLayer] { encodings.filter(\.isActive).map { encoding in let scaleDownBy = encoding.scaleResolutionDownBy?.doubleValue ?? 1.0 @@ -182,10 +167,6 @@ extension Dimensions { // MARK: - Convert extension Dimensions { - func toCGSize() -> CGSize { - CGSize(width: Int(width), height: Int(height)) - } - func apply(rotation: RTCVideoRotation) -> Dimensions { if rotation == ._90 || rotation == ._270 { return swapped() diff --git a/Sources/LiveKit/Types/VideoQuality.swift b/Sources/LiveKit/Types/VideoQuality.swift index 842322a52..6744b819c 100644 --- a/Sources/LiveKit/Types/VideoQuality.swift +++ b/Sources/LiveKit/Types/VideoQuality.swift @@ -39,16 +39,6 @@ extension VideoQuality { } extension Livekit_VideoQuality { - private static let toSDKTypeMap: [Livekit_VideoQuality: VideoQuality] = [ - .low: .low, - .medium: .medium, - .high: .high, - ] - - func toSDKType() -> VideoQuality { - Self.toSDKTypeMap[self] ?? .low - } - static func from(rid: String?) -> Livekit_VideoQuality { switch rid { case "h": return Livekit_VideoQuality.medium diff --git a/Sources/LiveKit/Views/VideoView.swift b/Sources/LiveKit/Views/VideoView.swift index 4e507de21..7ac6eb08d 100644 --- a/Sources/LiveKit/Views/VideoView.swift +++ b/Sources/LiveKit/Views/VideoView.swift @@ -30,7 +30,7 @@ protocol Mirrorable { public class VideoView: NativeView, Loggable { // MARK: - MulticastDelegate - var delegates = MulticastDelegate() + public let delegates = MulticastDelegate() // MARK: - Static