|
1 | 1 | /*
|
2 |
| - * Copyright 2023 LiveKit |
| 2 | + * Copyright 2024 LiveKit |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
14 | 14 | * limitations under the License.
|
15 | 15 | */
|
16 | 16 |
|
17 |
| -import SwiftUI |
18 | 17 | import LiveKit
|
| 18 | +import SwiftUI |
19 | 19 |
|
20 |
| -public struct TrackReference { |
21 |
| - let participantSid: Sid? |
22 |
| - let publicationSid: Sid |
23 |
| - let source: Track.Source |
24 |
| -} |
25 |
| - |
26 |
| -public struct TrackFinder<FoundView: View, NotFoundView: View>: View { |
27 |
| - |
28 |
| - @EnvironmentObject var room: Room |
29 |
| - |
30 |
| - let reference: TrackReference |
31 |
| - let foundBuilder: ComponentBuilder<FoundView> |
32 |
| - let notFoundBuilder: ComponentBuilder<NotFoundView> |
33 |
| - |
34 |
| - public init(_ reference: TrackReference, |
35 |
| - @ViewBuilder found: @escaping ComponentBuilder<FoundView>, |
36 |
| - @ViewBuilder notFound: @escaping ComponentBuilder<NotFoundView>) { |
37 |
| - |
38 |
| - self.reference = reference |
39 |
| - self.foundBuilder = found |
40 |
| - self.notFoundBuilder = notFound |
| 20 | +open class TrackReference: ObservableObject { |
| 21 | + public let participant: Participant |
| 22 | + public let publication: TrackPublication? |
| 23 | + public let name: String? |
| 24 | + public let source: Track.Source? |
| 25 | + |
| 26 | + public init(participant: Participant, publication: TrackPublication? = nil, name: String? = nil, source: Track.Source? = nil) { |
| 27 | + self.participant = participant |
| 28 | + self.publication = publication |
| 29 | + self.name = name |
| 30 | + self.source = source |
41 | 31 | }
|
42 | 32 |
|
43 |
| - public var body: some View { |
44 |
| - |
45 |
| - // TODO: Implement logic... |
| 33 | + /// Attempts to reseolve ``TrackPublication`` in order: publication, name, source. |
| 34 | + public func resolve() -> TrackPublication? { |
| 35 | + if let publication { |
| 36 | + return publication |
| 37 | + } else if let name, let source, let publication = participant.trackPublications.first(where: { $0.value.name == name && $0.value.source == source })?.value { |
| 38 | + return publication |
| 39 | + } else if let name, let publication = participant.trackPublications.first(where: { $0.value.name == name })?.value { |
| 40 | + return publication |
| 41 | + } else if let source, let publication = participant.trackPublications.first(where: { $0.value.source == source })?.value { |
| 42 | + return publication |
| 43 | + } |
| 44 | + |
| 45 | + return nil |
| 46 | + } |
46 | 47 |
|
47 |
| - AnyView(foundBuilder()) |
| 48 | + public var isResolvable: Bool { |
| 49 | + resolve() != nil |
48 | 50 | }
|
49 | 51 | }
|
0 commit comments