Skip to content

Commit

Permalink
Remove dependency on "Swift Collections" package (livekit#109)
Browse files Browse the repository at this point in the history
  • Loading branch information
hiroshihorie authored Jul 14, 2022
1 parent a0ecd31 commit 39207e8
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 18 deletions.
1 change: 0 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ let package = Package(
.target(name: "CHeaders"),
"WebRTC", "SwiftProtobuf", "Promises",
.product(name: "Logging", package: "swift-log"),
.product(name: "Collections", package: "swift-collections")
],
path: "Sources",
swiftSettings: [
Expand Down
1 change: 0 additions & 1 deletion Sources/LiveKit/Core/SignalClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import Foundation
import Promises
import WebRTC
import Collections

internal class SignalClient: MulticastDelegate<SignalClientDelegate> {

Expand Down
12 changes: 6 additions & 6 deletions Sources/LiveKit/SwiftUI/ObservableRoom.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,24 @@

import SwiftUI
import WebRTC
import OrderedCollections
import Promises

open class ObservableRoom: ObservableObject, RoomDelegate, Loggable {

public let room: Room

public var remoteParticipants: OrderedDictionary<Sid, ObservableParticipant> {
OrderedDictionary(uniqueKeysWithValues: room.remoteParticipants.map { (sid, participant) in (sid, ObservableParticipant(participant)) })
public var remoteParticipants: [Sid: ObservableParticipant] {
Dictionary(uniqueKeysWithValues: room.remoteParticipants.map { (sid, participant) in (sid, ObservableParticipant(participant)) })
}

public var allParticipants: OrderedDictionary<Sid, ObservableParticipant> {
public var allParticipants: [Sid: ObservableParticipant] {
var result = remoteParticipants

if let localParticipant = room.localParticipant {
result.updateValue(ObservableParticipant(localParticipant),
forKey: localParticipant.sid,
insertingAt: 0)
forKey: localParticipant.sid)
}

return result
}

Expand Down
19 changes: 9 additions & 10 deletions Sources/LiveKit/Track/Capturers/CameraCapturer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import Foundation
import WebRTC
import Promises
import ReplayKit
import OrderedCollections

public class CameraCapturer: VideoCapturer {

Expand Down Expand Up @@ -97,21 +96,21 @@ public class CameraCapturer: VideoCapturer {

// list of all formats in order of dimensions size
let formats = DispatchQueue.webRTC.sync { RTCCameraVideoCapturer.supportedFormats(for: device) }
// create a dictionary sorted by dimensions size
let sortedFormats = OrderedDictionary(uniqueKeysWithValues: formats.map { ($0, CMVideoFormatDescriptionGetDimensions($0.formatDescription)) })
.sorted { $0.value.area < $1.value.area }
// create an array of sorted touples by dimensions size
let sortedFormats = formats.map({ (format: $0, dimensions: CMVideoFormatDescriptionGetDimensions($0.formatDescription)) })
.sorted { $0.dimensions.area < $1.dimensions.area }

// default to the smallest
var selectedFormat = sortedFormats.first

// find preferred capture format if specified in options
if let preferredFormat = self.options.preferredFormat,
let foundFormat = sortedFormats.first(where: { $0.key == preferredFormat }) {
let foundFormat = sortedFormats.first(where: { $0.format == preferredFormat }) {
selectedFormat = foundFormat
} else {
self.log("formats: \(sortedFormats.map { String(describing: $0.value) }), target: \(self.options.dimensions)")
self.log("formats: \(sortedFormats.map { String(describing: $0.dimensions) }), target: \(self.options.dimensions)")
// find format that satisfies preferred dimensions
selectedFormat = sortedFormats.first(where: { $0.value.area >= self.options.dimensions.area })
selectedFormat = sortedFormats.first(where: { $0.dimensions.area >= self.options.dimensions.area })
}

// format should be resolved at this point
Expand All @@ -120,7 +119,7 @@ public class CameraCapturer: VideoCapturer {
throw TrackError.capturer(message: "Unable to determine format for camera capturer")
}

guard let fpsRange = selectedFormat.key.fpsRange() else {
guard let fpsRange = selectedFormat.format.fpsRange() else {
self.log("unable to resolve fps range", .error)
throw TrackError.capturer(message: "Unable to determine supported fps range for format: \(selectedFormat)")
}
Expand All @@ -139,7 +138,7 @@ public class CameraCapturer: VideoCapturer {

// adapt if requested dimensions and camera's dimensions don't match
if let videoSource = self.delegate as? RTCVideoSource,
selectedFormat.value != self.options.dimensions {
selectedFormat.dimensions != self.options.dimensions {

// self.log("adaptOutputFormat to: \(options.dimensions) fps: \(self.options.fps)")
videoSource.adaptOutputFormat(toWidth: self.options.dimensions.width,
Expand All @@ -150,7 +149,7 @@ public class CameraCapturer: VideoCapturer {
// return promise that waits for capturer to start
return Promise<Bool>(on: .webRTC) { resolve, fail in
// start the RTCCameraVideoCapturer
self.capturer.startCapture(with: device, format: selectedFormat.key, fps: selectedFps) { error in
self.capturer.startCapture(with: device, format: selectedFormat.format, fps: selectedFps) { error in
if let error = error {
self.log("CameraCapturer failed to start \(error)", .error)
fail(error)
Expand Down

0 comments on commit 39207e8

Please sign in to comment.