react-native-audio-browser 1.0.0-next.1 → 1.0.0-next.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/src/main/java/com/audiobrowser/AudioBrowser.kt +19 -2
- package/android/src/main/java/com/audiobrowser/browser/BrowserManager.kt +29 -8
- package/android/src/main/java/com/audiobrowser/http/RequestConfigBuilder.kt +8 -10
- package/android/src/main/java/com/audiobrowser/model/PlayerSetupOptions.kt +2 -2
- package/android/src/main/java/com/audiobrowser/player/AutomaticBufferManager.kt +17 -16
- package/android/src/main/java/com/audiobrowser/player/InterceptingPlayer.kt +11 -0
- package/android/src/main/java/com/audiobrowser/player/Player.kt +8 -4
- package/android/src/test/java/com/audiobrowser/ContentRefreshNavigationErrorTest.kt +236 -0
- package/android/src/test/java/com/audiobrowser/browser/BrowserManagerUnparsableResponseTest.kt +82 -0
- package/android/src/test/java/com/audiobrowser/browser/BrowserUrlResolutionTest.kt +15 -0
- package/android/src/test/java/com/audiobrowser/http/RequestConfigBuilderTest.kt +26 -0
- package/android/src/test/java/com/audiobrowser/model/PlayerSetupOptionsTest.kt +19 -2
- package/android/src/test/java/com/audiobrowser/player/AutomaticBufferManagerTest.kt +17 -0
- package/android/src/test/java/com/audiobrowser/player/SessionQueueShuffleOrderTest.kt +38 -0
- package/ios/Browser/BrowserError.swift +8 -0
- package/ios/Browser/BrowserManager.swift +29 -28
- package/ios/Browser/BrowserPathHelper.swift +26 -24
- package/ios/Browser/FavoriteSet.swift +16 -8
- package/ios/Browser/Favorites.swift +66 -0
- package/ios/Browser/JsonModels.swift +27 -7
- package/ios/Browser/NavigationErrorState.swift +18 -1
- package/ios/Browser/PageResolver.swift +2 -2
- package/ios/Browser/RequestLayer.swift +11 -4
- package/ios/Browser/RequestPipeline.swift +8 -4
- package/ios/Browser/TabBarEntries.swift +7 -0
- package/ios/CarPlay/CarPlayImageLoader.swift +3 -7
- package/ios/CarPlay/CarPlaySession+Navigator.swift +3 -1
- package/ios/CarPlay/IntentHandlers.swift +1 -7
- package/ios/CarPlay/MediaIntentCriteria.swift +4 -4
- package/ios/Extension/CGSize+AspectFit.swift +11 -0
- package/ios/Extension/Dictionary+Headers.swift +8 -0
- package/ios/Extension/NavigationError+Conversion.swift +4 -3
- package/ios/Extension/ResolvedTrack+Copying.swift +15 -0
- package/ios/Http/HttpClient.swift +37 -11
- package/ios/HybridAudioBrowser+Browser.swift +9 -16
- package/ios/HybridAudioBrowser+Options.swift +1 -0
- package/ios/HybridAudioBrowser+Player.swift +24 -23
- package/ios/HybridAudioBrowser+PlayerCallbacks.swift +1 -2
- package/ios/Model/NitroTypeStubs.swift +39 -0
- package/ios/Model/TrackPlayerError.swift +21 -2
- package/ios/Player/AudioSessionController.swift +2 -2
- package/ios/Player/MediaLoader.swift +1 -1
- package/ios/Player/PlaybackStateMachine.swift +13 -12
- package/ios/Player/Player.swift +60 -21
- package/ios/Player/PlayerEngine.swift +5 -0
- package/ios/Player/QueueManager.swift +21 -4
- package/ios/Tests/BrowserErrorTests.swift +21 -0
- package/ios/Tests/BrowserPathHelperTests.swift +18 -0
- package/ios/Tests/CGSizeAspectFitTests.swift +36 -0
- package/ios/Tests/ClampedVolumeTests.swift +26 -0
- package/ios/Tests/FavoriteSetTests.swift +68 -3
- package/ios/Tests/FavoritesTests.swift +102 -0
- package/ios/Tests/HttpClientUserAgentTests.swift +45 -0
- package/ios/Tests/JsonModelsTests.swift +74 -6
- package/ios/Tests/MediaIntentCriteriaTests.swift +11 -1
- package/ios/Tests/MediaLoaderAssetOptionsTests.swift +7 -0
- package/ios/Tests/NavigationErrorStateTests.swift +73 -0
- package/ios/Tests/PlaybackStateMachineTests.swift +21 -12
- package/ios/Tests/PlayerPolicyTests.swift +103 -0
- package/ios/Tests/PlayerProgressTests.swift +109 -0
- package/ios/Tests/PlayerTests.swift +106 -0
- package/ios/Tests/QueueIndexTests.swift +43 -0
- package/ios/Tests/QueueManagerTests.swift +79 -15
- package/ios/Tests/RequestLayerTests.swift +22 -3
- package/ios/Tests/TabBarEntriesTests.swift +19 -0
- package/ios/Tests/TrackSelectorTests.swift +154 -0
- package/ios/Tests/UnparsableResponseTests.swift +91 -0
- package/ios/TrackSelector.swift +28 -8
- package/ios/Util/ArtworkImageFetcher.swift +9 -8
- package/ios/Util/SVGProcessor.swift +6 -17
- package/lib/commonjs/features/browser-config.js +6 -3
- package/lib/commonjs/features/browser-config.js.map +1 -1
- package/lib/commonjs/features/errors.js +12 -7
- package/lib/commonjs/features/errors.js.map +1 -1
- package/lib/commonjs/features/nowPlaying.js +9 -3
- package/lib/commonjs/features/nowPlaying.js.map +1 -1
- package/lib/commonjs/features/playback/trackPlaybackTime.js +2 -1
- package/lib/commonjs/features/playback/trackPlaybackTime.js.map +1 -1
- package/lib/commonjs/features/player/setup.js +2 -2
- package/lib/commonjs/features/queue/activeTrack.js +4 -2
- package/lib/commonjs/features/queue/activeTrack.js.map +1 -1
- package/lib/commonjs/features/sleepTimer.js +6 -5
- package/lib/commonjs/features/sleepTimer.js.map +1 -1
- package/lib/commonjs/utils/LazyNativeEmitter.js +2 -1
- package/lib/commonjs/utils/LazyNativeEmitter.js.map +1 -1
- package/lib/commonjs/utils/NativeUpdatedValue.js +2 -1
- package/lib/commonjs/utils/NativeUpdatedValue.js.map +1 -1
- package/lib/commonjs/utils/callListener.js +23 -0
- package/lib/commonjs/utils/callListener.js.map +1 -0
- package/lib/module/features/browser-config.js +6 -3
- package/lib/module/features/browser-config.js.map +1 -1
- package/lib/module/features/errors.js +12 -7
- package/lib/module/features/errors.js.map +1 -1
- package/lib/module/features/nowPlaying.js +9 -3
- package/lib/module/features/nowPlaying.js.map +1 -1
- package/lib/module/features/playback/trackPlaybackTime.js +2 -1
- package/lib/module/features/playback/trackPlaybackTime.js.map +1 -1
- package/lib/module/features/player/setup.js +2 -2
- package/lib/module/features/queue/activeTrack.js +4 -2
- package/lib/module/features/queue/activeTrack.js.map +1 -1
- package/lib/module/features/sleepTimer.js +6 -5
- package/lib/module/features/sleepTimer.js.map +1 -1
- package/lib/module/utils/LazyNativeEmitter.js +2 -1
- package/lib/module/utils/LazyNativeEmitter.js.map +1 -1
- package/lib/module/utils/NativeUpdatedValue.js +2 -1
- package/lib/module/utils/NativeUpdatedValue.js.map +1 -1
- package/lib/module/utils/callListener.js +19 -0
- package/lib/module/utils/callListener.js.map +1 -0
- package/lib/typescript/src/features/browser-config.d.ts.map +1 -1
- package/lib/typescript/src/features/errors.d.ts +8 -6
- package/lib/typescript/src/features/errors.d.ts.map +1 -1
- package/lib/typescript/src/features/nowPlaying.d.ts +2 -1
- package/lib/typescript/src/features/nowPlaying.d.ts.map +1 -1
- package/lib/typescript/src/features/playback/trackPlaybackTime.d.ts.map +1 -1
- package/lib/typescript/src/features/player/setup.d.ts +2 -2
- package/lib/typescript/src/features/queue/activeTrack.d.ts +2 -1
- package/lib/typescript/src/features/queue/activeTrack.d.ts.map +1 -1
- package/lib/typescript/src/features/sleepTimer.d.ts +2 -1
- package/lib/typescript/src/features/sleepTimer.d.ts.map +1 -1
- package/lib/typescript/src/types/browser.d.ts +3 -2
- package/lib/typescript/src/types/browser.d.ts.map +1 -1
- package/lib/typescript/src/utils/LazyNativeEmitter.d.ts.map +1 -1
- package/lib/typescript/src/utils/NativeUpdatedValue.d.ts.map +1 -1
- package/lib/typescript/src/utils/callListener.d.ts +7 -0
- package/lib/typescript/src/utils/callListener.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/features/browser-config.test.ts +15 -0
- package/src/features/browser-config.ts +6 -3
- package/src/features/errors.test.ts +83 -0
- package/src/features/errors.ts +12 -7
- package/src/features/hook-wiring.test.ts +11 -10
- package/src/features/nowPlaying.ts +9 -3
- package/src/features/playback/trackPlaybackTime.test.ts +24 -1
- package/src/features/playback/trackPlaybackTime.ts +2 -1
- package/src/features/player/setup.ts +2 -2
- package/src/features/queue/activeTrack.test.ts +32 -0
- package/src/features/queue/activeTrack.ts +8 -2
- package/src/features/sleepTimer.test.ts +24 -0
- package/src/features/sleepTimer.ts +6 -5
- package/src/types/browser.ts +3 -2
- package/src/utils/LazyNativeEmitter.test.ts +32 -0
- package/src/utils/LazyNativeEmitter.ts +3 -1
- package/src/utils/NativeUpdatedValue.test.ts +32 -0
- package/src/utils/NativeUpdatedValue.ts +3 -1
- package/src/utils/callListener.ts +17 -0
- package/website/guide/configuration.md +3 -3
- package/website/guide/errors.md +3 -1
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import Testing
|
|
2
|
+
|
|
3
|
+
@testable import AudioBrowserTestable
|
|
4
|
+
|
|
5
|
+
@Suite("Int(queueIndex:)")
|
|
6
|
+
struct QueueIndexTests {
|
|
7
|
+
@Test(arguments: [
|
|
8
|
+
Double.nan,
|
|
9
|
+
.infinity,
|
|
10
|
+
-Double.infinity,
|
|
11
|
+
1e19,
|
|
12
|
+
-1e19,
|
|
13
|
+
Double(Int.max),
|
|
14
|
+
])
|
|
15
|
+
func numberNoIntHolds_throwsInvalidIndex(number: Double) {
|
|
16
|
+
let error = #expect(throws: TrackPlayerError.QueueError.self) {
|
|
17
|
+
_ = try Int(queueIndex: number)
|
|
18
|
+
}
|
|
19
|
+
guard case .invalidIndex(nil, _)? = error else {
|
|
20
|
+
Issue.record("expected invalidIndex without an index, got \(String(describing: error))")
|
|
21
|
+
return
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
@Test(arguments: [
|
|
26
|
+
(0.0, 0),
|
|
27
|
+
(2.0, 2),
|
|
28
|
+
(1.7, 1),
|
|
29
|
+
(-0.5, 0),
|
|
30
|
+
(-1.0, -1),
|
|
31
|
+
(Double(Int.min), Int.min),
|
|
32
|
+
])
|
|
33
|
+
func representableNumber_dropsTheFraction(number: Double, index: Int) throws {
|
|
34
|
+
#expect(try Int(queueIndex: number) == index)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@Test func unrepresentableNumber_isNamedInTheMessage() {
|
|
38
|
+
let error = #expect(throws: TrackPlayerError.QueueError.self) {
|
|
39
|
+
_ = try Int(queueIndex: .nan)
|
|
40
|
+
}
|
|
41
|
+
#expect(error?.localizedDescription == "Invalid track index: index must be a finite number within the range of Int, got nan")
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -155,7 +155,7 @@ struct NextTests {
|
|
|
155
155
|
#expect(visited.count == 4)
|
|
156
156
|
}
|
|
157
157
|
|
|
158
|
-
@Test func
|
|
158
|
+
@Test func shuffle_atEnd_repeatOff_returnsNoChange() {
|
|
159
159
|
let q = QueueManager()
|
|
160
160
|
q.setQueue(tracks("a", "b", "c"))
|
|
161
161
|
q.shuffleEnabled = true
|
|
@@ -163,8 +163,21 @@ struct NextTests {
|
|
|
163
163
|
for _ in 0 ..< 2 {
|
|
164
164
|
_ = q.next()
|
|
165
165
|
}
|
|
166
|
-
let
|
|
167
|
-
#expect(
|
|
166
|
+
let last = q.currentIndex
|
|
167
|
+
#expect(q.next() == .noChange)
|
|
168
|
+
#expect(q.currentIndex == last)
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
@Test func shuffle_atEnd_repeatQueue_wrapsToFirstInOrder() {
|
|
172
|
+
let q = QueueManager()
|
|
173
|
+
q.setQueue(tracks("a", "b", "c"))
|
|
174
|
+
q.shuffleEnabled = true
|
|
175
|
+
q.repeatMode = .queue
|
|
176
|
+
for _ in 0 ..< 2 {
|
|
177
|
+
_ = q.next()
|
|
178
|
+
}
|
|
179
|
+
#expect(q.next() == .trackChanged)
|
|
180
|
+
#expect(q.currentIndex == q.shuffleOrder.firstIndex)
|
|
168
181
|
}
|
|
169
182
|
|
|
170
183
|
@Test func multipleTrack_repeatTrack_behavesLikeOff() {
|
|
@@ -202,17 +215,25 @@ struct PreviousTests {
|
|
|
202
215
|
#expect(q.currentIndex == 1)
|
|
203
216
|
}
|
|
204
217
|
|
|
205
|
-
@Test func
|
|
218
|
+
@Test func shuffle_atBeginning_repeatOff_returnsNoChange() {
|
|
206
219
|
let q = QueueManager()
|
|
207
220
|
q.setQueue(tracks("a", "b", "c"))
|
|
208
221
|
q.shuffleEnabled = true
|
|
209
222
|
q.repeatMode = .off
|
|
223
|
+
let first = q.currentIndex
|
|
224
|
+
#expect(q.shuffleOrder.isFirst(first))
|
|
225
|
+
#expect(q.previous() == .noChange)
|
|
226
|
+
#expect(q.currentIndex == first)
|
|
227
|
+
}
|
|
210
228
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
229
|
+
@Test func shuffle_atBeginning_repeatQueue_wrapsToLastInOrder() {
|
|
230
|
+
let q = QueueManager()
|
|
231
|
+
q.setQueue(tracks("a", "b", "c"))
|
|
232
|
+
q.shuffleEnabled = true
|
|
233
|
+
q.repeatMode = .queue
|
|
234
|
+
#expect(q.shuffleOrder.isFirst(q.currentIndex))
|
|
235
|
+
#expect(q.previous() == .trackChanged)
|
|
236
|
+
#expect(q.currentIndex == q.shuffleOrder.lastIndex)
|
|
216
237
|
}
|
|
217
238
|
|
|
218
239
|
@Test func singleTrack_repeatQueue_returnsSameTrackReplay() {
|
|
@@ -713,6 +734,27 @@ struct OtherMutationTests {
|
|
|
713
734
|
#expect(q.tracks[1].id == "B")
|
|
714
735
|
}
|
|
715
736
|
|
|
737
|
+
@Test func replaceEach_replacesTheTracksTheTransformReturns() {
|
|
738
|
+
let q = QueueManager()
|
|
739
|
+
q.setQueue(tracks("a", "b", "c"), initialIndex: 1)
|
|
740
|
+
|
|
741
|
+
let change = q.replaceEach { $0.id == "b" || $0.id == "c" ? Track(id: $0.id, title: "new") : nil }
|
|
742
|
+
|
|
743
|
+
#expect(change == .tracksOnly)
|
|
744
|
+
#expect(q.tracks.map(\.id) == ["a", "b", "c"])
|
|
745
|
+
#expect(q.tracks.map(\.title) == ["", "new", "new"])
|
|
746
|
+
#expect(q.currentIndex == 1)
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
@Test func replaceEach_changesNothingWhenNoTrackIsReplaced() {
|
|
750
|
+
let q = QueueManager()
|
|
751
|
+
q.setQueue(tracks("a", "b"))
|
|
752
|
+
let version = q.version
|
|
753
|
+
|
|
754
|
+
#expect(q.replaceEach { _ in nil } == .none)
|
|
755
|
+
#expect(q.version == version)
|
|
756
|
+
}
|
|
757
|
+
|
|
716
758
|
@Test func removeUpcomingTracks_alsoTrimsShuffleOrder() {
|
|
717
759
|
let q = QueueManager()
|
|
718
760
|
q.shuffleEnabled = true
|
|
@@ -871,6 +913,7 @@ struct ComputedPropertyTests {
|
|
|
871
913
|
_ = q.next()
|
|
872
914
|
}
|
|
873
915
|
#expect(q.isLastInPlaybackOrder == true)
|
|
916
|
+
q.repeatMode = .queue
|
|
874
917
|
_ = q.next()
|
|
875
918
|
#expect(q.isLastInPlaybackOrder == false)
|
|
876
919
|
}
|
|
@@ -1057,8 +1100,7 @@ struct SkipAvailabilityTests {
|
|
|
1057
1100
|
#expect(q.canPrevious == true)
|
|
1058
1101
|
}
|
|
1059
1102
|
|
|
1060
|
-
|
|
1061
|
-
@Test func shuffleEnd_repeatOff_canNextTrue() {
|
|
1103
|
+
@Test func shuffleEnd_repeatOff_previousOnly() {
|
|
1062
1104
|
let q = QueueManager()
|
|
1063
1105
|
q.setQueue(tracks("a", "b", "c", "d"))
|
|
1064
1106
|
q.shuffleEnabled = true
|
|
@@ -1066,17 +1108,39 @@ struct SkipAvailabilityTests {
|
|
|
1066
1108
|
while !q.isLastInPlaybackOrder {
|
|
1067
1109
|
_ = q.next()
|
|
1068
1110
|
}
|
|
1069
|
-
#expect(q.canNext ==
|
|
1111
|
+
#expect(q.canNext == false)
|
|
1112
|
+
#expect(q.canPrevious == true)
|
|
1070
1113
|
}
|
|
1071
1114
|
|
|
1072
|
-
@Test func
|
|
1115
|
+
@Test func shuffleStart_repeatOff_nextOnly() {
|
|
1073
1116
|
let q = QueueManager()
|
|
1074
1117
|
q.setQueue(tracks("a", "b", "c", "d"))
|
|
1075
1118
|
q.shuffleEnabled = true
|
|
1076
1119
|
q.repeatMode = .off
|
|
1077
|
-
|
|
1078
|
-
|
|
1120
|
+
#expect(q.shuffleOrder.isFirst(q.currentIndex))
|
|
1121
|
+
#expect(q.canNext == true)
|
|
1122
|
+
#expect(q.canPrevious == false)
|
|
1123
|
+
}
|
|
1124
|
+
|
|
1125
|
+
@Test func shuffleEnd_repeatQueue_bothTrue() {
|
|
1126
|
+
let q = QueueManager()
|
|
1127
|
+
q.setQueue(tracks("a", "b", "c", "d"))
|
|
1128
|
+
q.shuffleEnabled = true
|
|
1129
|
+
q.repeatMode = .queue
|
|
1130
|
+
while !q.isLastInPlaybackOrder {
|
|
1131
|
+
_ = q.next()
|
|
1079
1132
|
}
|
|
1133
|
+
#expect(q.canNext == true)
|
|
1134
|
+
#expect(q.canPrevious == true)
|
|
1135
|
+
}
|
|
1136
|
+
|
|
1137
|
+
@Test func shuffleStart_repeatQueue_bothTrue() {
|
|
1138
|
+
let q = QueueManager()
|
|
1139
|
+
q.setQueue(tracks("a", "b", "c", "d"))
|
|
1140
|
+
q.shuffleEnabled = true
|
|
1141
|
+
q.repeatMode = .queue
|
|
1142
|
+
#expect(q.shuffleOrder.isFirst(q.currentIndex))
|
|
1143
|
+
#expect(q.canNext == true)
|
|
1080
1144
|
#expect(q.canPrevious == true)
|
|
1081
1145
|
}
|
|
1082
1146
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import Foundation
|
|
1
2
|
import Testing
|
|
2
3
|
|
|
3
4
|
@testable import AudioBrowserTestable
|
|
@@ -79,10 +80,23 @@ struct RequestLayerTests {
|
|
|
79
80
|
#expect(applied == Config(path: "/page", baseUrl: "https://b"))
|
|
80
81
|
}
|
|
81
82
|
|
|
82
|
-
@Test func
|
|
83
|
-
struct Boom:
|
|
84
|
-
|
|
83
|
+
@Test func aFailingTransformThrowsACallbackErrorWithItsMessage() async {
|
|
84
|
+
struct Boom: LocalizedError {
|
|
85
|
+
var errorDescription: String? { "token expired" }
|
|
86
|
+
}
|
|
87
|
+
do {
|
|
85
88
|
_ = try await RequestLayer.apply(Config(), transforms: [{ _ in throw Boom() }], to: Config())
|
|
89
|
+
Issue.record("apply returned")
|
|
90
|
+
} catch let BrowserError.callbackError(message) {
|
|
91
|
+
#expect(message == "token expired")
|
|
92
|
+
} catch {
|
|
93
|
+
Issue.record("threw \(error)")
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
@Test func aCancelledTransformStaysACancellation() async {
|
|
98
|
+
await #expect(throws: CancellationError.self) {
|
|
99
|
+
_ = try await RequestLayer.apply(Config(), transforms: [{ _ in throw CancellationError() }], to: Config())
|
|
86
100
|
}
|
|
87
101
|
}
|
|
88
102
|
|
|
@@ -212,6 +226,7 @@ struct RequestLayerTests {
|
|
|
212
226
|
#expect(RequestLayer.imageHeaders(Config()) == nil)
|
|
213
227
|
#expect(RequestLayer.imageHeaders(Config(userAgent: "UA")) == ["User-Agent": "UA"])
|
|
214
228
|
#expect(RequestLayer.imageHeaders(Config(headers: ["User-Agent": "mine"], userAgent: "UA")) == ["User-Agent": "mine"])
|
|
229
|
+
#expect(RequestLayer.imageHeaders(Config(headers: ["user-agent": "mine"], userAgent: "UA")) == ["user-agent": "mine"])
|
|
215
230
|
}
|
|
216
231
|
|
|
217
232
|
@Test func imageHeadersAddTheContentTypeUnlessAHeaderSetsIt() {
|
|
@@ -220,6 +235,10 @@ struct RequestLayerTests {
|
|
|
220
235
|
RequestLayer.imageHeaders(Config(headers: ["Content-Type": "mine"], contentType: "image/png"))
|
|
221
236
|
== ["Content-Type": "mine"],
|
|
222
237
|
)
|
|
238
|
+
#expect(
|
|
239
|
+
RequestLayer.imageHeaders(Config(headers: ["content-type": "mine"], contentType: "image/png"))
|
|
240
|
+
== ["content-type": "mine"],
|
|
241
|
+
)
|
|
223
242
|
#expect(
|
|
224
243
|
RequestLayer.imageHeaders(Config(contentType: "image/png", userAgent: "UA"))
|
|
225
244
|
== ["Content-Type": "image/png", "User-Agent": "UA"],
|
|
@@ -66,4 +66,23 @@ struct TabBarEntriesTests {
|
|
|
66
66
|
[tab("Explore", path: "/explore", artist: "b")],
|
|
67
67
|
))
|
|
68
68
|
}
|
|
69
|
+
|
|
70
|
+
@Test func tabsThatGoAwayEmitAnEmptyList() {
|
|
71
|
+
#expect(TabBarEntries.change(from: [tab("Explore", path: "/explore")], to: nil)?.isEmpty == true)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
@Test func noTabsBeforeOrAfterEmitsNothing() {
|
|
75
|
+
#expect(TabBarEntries.change(from: nil, to: nil) == nil)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
@Test func newTabsEmitThem() {
|
|
79
|
+
let tabs = [tab("Explore", path: "/explore")]
|
|
80
|
+
#expect(TabBarEntries.change(from: nil, to: tabs)?.map(\.path) == ["/explore"])
|
|
81
|
+
#expect(TabBarEntries.change(from: [tab("Browse", path: "/browse")], to: tabs)?.map(\.path) == ["/explore"])
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
@Test func sameEntriesEmitNothing() {
|
|
85
|
+
let tabs = [tab("Explore", path: "/explore")]
|
|
86
|
+
#expect(TabBarEntries.change(from: tabs, to: tabs) == nil)
|
|
87
|
+
}
|
|
69
88
|
}
|
|
@@ -13,13 +13,34 @@ private final class BrowserMock: TrackSelectionBrowser {
|
|
|
13
13
|
var trackLoadEvents: [TrackLoadEvent] = []
|
|
14
14
|
var expandedPaths: [String] = []
|
|
15
15
|
|
|
16
|
+
/// Expansions of these paths, and track-load handlers for these track ids, answer only after
|
|
17
|
+
/// `release()`.
|
|
18
|
+
var held: Set<String> = []
|
|
19
|
+
private(set) var waiting: [CheckedContinuation<Void, Never>] = []
|
|
20
|
+
|
|
21
|
+
func release() {
|
|
22
|
+
let resuming = waiting
|
|
23
|
+
waiting = []
|
|
24
|
+
held = []
|
|
25
|
+
for continuation in resuming {
|
|
26
|
+
continuation.resume()
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
private func hold(_ key: String?) async {
|
|
31
|
+
guard let key, held.contains(key) else { return }
|
|
32
|
+
await withCheckedContinuation { waiting.append($0) }
|
|
33
|
+
}
|
|
34
|
+
|
|
16
35
|
func awaitTrackLoadHandler(event: TrackLoadEvent) async -> Bool {
|
|
17
36
|
trackLoadEvents.append(event)
|
|
37
|
+
await hold(event.track.id)
|
|
18
38
|
return trackLoadHandlerResult
|
|
19
39
|
}
|
|
20
40
|
|
|
21
41
|
func expandQueueFromContextualPath(_ path: String) async throws -> (tracks: [Track], selectedIndex: Int)? {
|
|
22
42
|
expandedPaths.append(path)
|
|
43
|
+
await hold(path)
|
|
23
44
|
if let error = expandQueueError {
|
|
24
45
|
throw error
|
|
25
46
|
}
|
|
@@ -47,6 +68,14 @@ private func makeSelector() -> (TrackSelector, BrowserMock, PlayerMock) {
|
|
|
47
68
|
return (selector, browser, player)
|
|
48
69
|
}
|
|
49
70
|
|
|
71
|
+
@MainActor
|
|
72
|
+
private func yieldUntil(_ condition: () -> Bool, sourceLocation: SourceLocation = #_sourceLocation) async {
|
|
73
|
+
for _ in 0 ..< 1000 where !condition() {
|
|
74
|
+
await Task.yield()
|
|
75
|
+
}
|
|
76
|
+
#expect(condition(), sourceLocation: sourceLocation)
|
|
77
|
+
}
|
|
78
|
+
|
|
50
79
|
// MARK: - Browsable Track
|
|
51
80
|
|
|
52
81
|
@Suite("browsable track")
|
|
@@ -389,3 +418,128 @@ struct DisabledTrackTests {
|
|
|
389
418
|
#expect(browser.expandedPaths.isEmpty)
|
|
390
419
|
}
|
|
391
420
|
}
|
|
421
|
+
|
|
422
|
+
// MARK: - Selection Order
|
|
423
|
+
|
|
424
|
+
@Suite("selection order")
|
|
425
|
+
@MainActor
|
|
426
|
+
struct SelectionOrderTests {
|
|
427
|
+
/// A selection running beside the test, and its result once it has one.
|
|
428
|
+
@MainActor
|
|
429
|
+
private final class PendingSelection {
|
|
430
|
+
private var result: TrackSelector.SelectionResult?
|
|
431
|
+
|
|
432
|
+
init(_ selector: TrackSelector, _ track: Track, _ player: PlayerMock) {
|
|
433
|
+
Task { result = await selector.select(track: track, player: player) }
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
func value() async -> TrackSelector.SelectionResult? {
|
|
437
|
+
await yieldUntil { result != nil }
|
|
438
|
+
return result
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
/// Starts selecting a contextual track whose expansion stays held until `browser.release()`.
|
|
443
|
+
private func selectHeldInExpansion(
|
|
444
|
+
_ selector: TrackSelector, _ browser: BrowserMock, _ player: PlayerMock,
|
|
445
|
+
) async -> PendingSelection {
|
|
446
|
+
let path = BrowserPathHelper.build(parentPath: "/library/radio", trackId: "older")
|
|
447
|
+
browser.held = [path]
|
|
448
|
+
browser.expandQueueResult = (tracks: [Track(id: "older", src: "older.mp3")], selectedIndex: 0)
|
|
449
|
+
let selection = PendingSelection(selector, Track(id: "older", path: path, src: "older.mp3"), player)
|
|
450
|
+
await yieldUntil { browser.waiting.count == 1 }
|
|
451
|
+
return selection
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
@Test func olderExpansionFinishingLast_isSupersededAndNotOfferedToTheApp() async {
|
|
455
|
+
let (selector, browser, player) = makeSelector()
|
|
456
|
+
let older = await selectHeldInExpansion(selector, browser, player)
|
|
457
|
+
|
|
458
|
+
let newer = await selector.select(track: Track(id: "newer", src: "newer.mp3"), player: player)
|
|
459
|
+
guard case let .play(.loadTrack(loaded)) = newer else {
|
|
460
|
+
Issue.record("expected .play(.loadTrack), got \(newer)")
|
|
461
|
+
return
|
|
462
|
+
}
|
|
463
|
+
#expect(loaded.id == "newer")
|
|
464
|
+
|
|
465
|
+
browser.release()
|
|
466
|
+
let olderResult = await older.value()
|
|
467
|
+
guard case .superseded = olderResult else {
|
|
468
|
+
Issue.record("expected .superseded, got \(String(describing: olderResult))")
|
|
469
|
+
return
|
|
470
|
+
}
|
|
471
|
+
#expect(browser.trackLoadEvents.map(\.track.id) == ["newer"])
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
@Test func olderTrackLoadHandlerFinishingLast_isSuperseded() async {
|
|
475
|
+
let (selector, browser, player) = makeSelector()
|
|
476
|
+
browser.held = ["older"]
|
|
477
|
+
let older = PendingSelection(selector, Track(id: "older", src: "older.mp3"), player)
|
|
478
|
+
await yieldUntil { browser.waiting.count == 1 }
|
|
479
|
+
|
|
480
|
+
let newer = await selector.select(track: Track(id: "newer", src: "newer.mp3"), player: player)
|
|
481
|
+
guard case .play = newer else {
|
|
482
|
+
Issue.record("expected .play, got \(newer)")
|
|
483
|
+
return
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
browser.release()
|
|
487
|
+
let olderResult = await older.value()
|
|
488
|
+
guard case .superseded = olderResult else {
|
|
489
|
+
Issue.record("expected .superseded, got \(String(describing: olderResult))")
|
|
490
|
+
return
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
@Test func laterInterceptedSelection_supersedesTheOlderOne() async {
|
|
495
|
+
let (selector, browser, player) = makeSelector()
|
|
496
|
+
let older = await selectHeldInExpansion(selector, browser, player)
|
|
497
|
+
|
|
498
|
+
browser.trackLoadHandlerResult = true
|
|
499
|
+
let newer = await selector.select(track: Track(id: "newer", src: "newer.mp3"), player: player)
|
|
500
|
+
guard case .intercepted = newer else {
|
|
501
|
+
Issue.record("expected .intercepted, got \(newer)")
|
|
502
|
+
return
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
browser.release()
|
|
506
|
+
let olderResult = await older.value()
|
|
507
|
+
guard case .superseded = olderResult else {
|
|
508
|
+
Issue.record("expected .superseded, got \(String(describing: olderResult))")
|
|
509
|
+
return
|
|
510
|
+
}
|
|
511
|
+
#expect(browser.trackLoadEvents.map(\.track.id) == ["newer"])
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
@Test func laterBrowse_leavesTheOlderSelectionToPlay() async {
|
|
515
|
+
let (selector, browser, player) = makeSelector()
|
|
516
|
+
let older = await selectHeldInExpansion(selector, browser, player)
|
|
517
|
+
|
|
518
|
+
let browse = await selector.select(track: Track(id: "folder", path: "/library"), player: player)
|
|
519
|
+
guard case .browse = browse else {
|
|
520
|
+
Issue.record("expected .browse, got \(browse)")
|
|
521
|
+
return
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
browser.release()
|
|
525
|
+
let olderResult = await older.value()
|
|
526
|
+
guard case .play(.setQueue) = olderResult else {
|
|
527
|
+
Issue.record("expected .play(.setQueue), got \(String(describing: olderResult))")
|
|
528
|
+
return
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
@Test func laterDisabledTrack_leavesTheOlderSelectionToPlay() async {
|
|
533
|
+
let (selector, browser, player) = makeSelector()
|
|
534
|
+
let older = await selectHeldInExpansion(selector, browser, player)
|
|
535
|
+
|
|
536
|
+
_ = await selector.select(track: Track(id: "gone", src: "gone.mp3", disabled: true), player: player)
|
|
537
|
+
|
|
538
|
+
browser.release()
|
|
539
|
+
let olderResult = await older.value()
|
|
540
|
+
guard case .play(.setQueue) = olderResult else {
|
|
541
|
+
Issue.record("expected .play(.setQueue), got \(String(describing: olderResult))")
|
|
542
|
+
return
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
@testable import AudioBrowserTestable
|
|
2
|
+
import Foundation
|
|
3
|
+
import Testing
|
|
4
|
+
|
|
5
|
+
/// Answers every request from its own URL: the status is the path, the body the `body` query item.
|
|
6
|
+
private final class StubResponseProtocol: URLProtocol {
|
|
7
|
+
static func url(status: Int, body: String) -> String {
|
|
8
|
+
var components = URLComponents()
|
|
9
|
+
components.scheme = "https"
|
|
10
|
+
components.host = "stub.invalid"
|
|
11
|
+
components.path = "/\(status)"
|
|
12
|
+
components.queryItems = [URLQueryItem(name: "body", value: body)]
|
|
13
|
+
return components.string!
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
override class func canInit(with _: URLRequest) -> Bool {
|
|
17
|
+
true
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
override class func canonicalRequest(for request: URLRequest) -> URLRequest {
|
|
21
|
+
request
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
override func startLoading() {
|
|
25
|
+
let url = request.url!
|
|
26
|
+
let body = URLComponents(url: url, resolvingAgainstBaseURL: false)!.queryItems!.first { $0.name == "body" }!.value!
|
|
27
|
+
let response = HTTPURLResponse(
|
|
28
|
+
url: url, statusCode: Int(url.lastPathComponent)!, httpVersion: "HTTP/1.1", headerFields: nil,
|
|
29
|
+
)!
|
|
30
|
+
client?.urlProtocol(self, didReceive: response, cacheStoragePolicy: .notAllowed)
|
|
31
|
+
client?.urlProtocol(self, didLoad: Data(body.utf8))
|
|
32
|
+
client?.urlProtocolDidFinishLoading(self)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
override func stopLoading() {}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
@Suite("A 2xx response that does not parse")
|
|
39
|
+
struct UnparsableResponseTests {
|
|
40
|
+
/// The navigation error of requesting `body`, served with `status`, as `type`.
|
|
41
|
+
private func navigationError(status: Int, body: String, as type: (some Decodable).Type) async -> NavigationError? {
|
|
42
|
+
let configuration = URLSessionConfiguration.ephemeral
|
|
43
|
+
configuration.protocolClasses = [StubResponseProtocol.self]
|
|
44
|
+
let request = HttpClient.HttpRequest(
|
|
45
|
+
url: StubResponseProtocol.url(status: status, body: body), method: .get, headers: nil, body: nil,
|
|
46
|
+
contentType: HttpClient.defaultContentType, userAgent: HttpClient.defaultUserAgent,
|
|
47
|
+
)
|
|
48
|
+
let session = URLSession(configuration: configuration)
|
|
49
|
+
defer { session.finishTasksAndInvalidate() }
|
|
50
|
+
do {
|
|
51
|
+
_ = try await HttpClient(session: session).requestJson(request, as: type)
|
|
52
|
+
return nil
|
|
53
|
+
} catch {
|
|
54
|
+
return NavigationError.from(error)
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
@Test(arguments: [
|
|
59
|
+
("<html><body>Maintenance</body></html>", "not valid JSON"),
|
|
60
|
+
(#"{"path": "/library"}"#, "Missing required key 'title'"),
|
|
61
|
+
(#"{"path": "/library", "title": "Library", "duration": "12"}"#, "Type mismatch for Double at path: duration"),
|
|
62
|
+
])
|
|
63
|
+
func aPageIsAnHttpErrorWithItsStatus(body: String, reason: String) async throws {
|
|
64
|
+
let result = await navigationError(status: 200, body: body, as: JsonBrowsePage.self)
|
|
65
|
+
let error = try #require(result)
|
|
66
|
+
|
|
67
|
+
#expect(error.code == .httpError)
|
|
68
|
+
#expect(error.statusCode == 200)
|
|
69
|
+
#expect(error.statusCodeSuccess == true)
|
|
70
|
+
#expect(error.message.contains(reason))
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
@Test
|
|
74
|
+
func searchResultsAreAnHttpErrorWithTheirStatus() async throws {
|
|
75
|
+
let result = await navigationError(status: 201, body: #"{"results": []}"#, as: [JsonTrack].self)
|
|
76
|
+
let error = try #require(result)
|
|
77
|
+
|
|
78
|
+
#expect(error.code == .httpError)
|
|
79
|
+
#expect(error.statusCode == 201)
|
|
80
|
+
#expect(error.statusCodeSuccess == true)
|
|
81
|
+
#expect(error.message.contains("Type mismatch"))
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
@Test
|
|
85
|
+
func itsDefaultTitleIsServerError() async throws {
|
|
86
|
+
let result = await navigationError(status: 200, body: "<html></html>", as: JsonResolvedTrack.self)
|
|
87
|
+
let error = try #require(result)
|
|
88
|
+
|
|
89
|
+
#expect(error.defaultFormatted().title == "Server Error")
|
|
90
|
+
}
|
|
91
|
+
}
|
package/ios/TrackSelector.swift
CHANGED
|
@@ -19,6 +19,9 @@ import os.log
|
|
|
19
19
|
class TrackSelector {
|
|
20
20
|
private let logger = Logger(subsystem: "com.audiobrowser", category: "TrackSelector")
|
|
21
21
|
private nonisolated(unsafe) let browserManager: any TrackSelectionBrowser
|
|
22
|
+
/// Bumped by every selection that would play, whether or not the app's `handleTrackLoad`
|
|
23
|
+
/// intercepts it; one that finds it bumped has been superseded.
|
|
24
|
+
private var latestSelection: UInt = 0
|
|
22
25
|
|
|
23
26
|
nonisolated init(browserManager: any TrackSelectionBrowser) {
|
|
24
27
|
self.browserManager = browserManager
|
|
@@ -32,6 +35,8 @@ class TrackSelector {
|
|
|
32
35
|
case intercepted
|
|
33
36
|
/// The track has no `src`; the caller navigates to `path`.
|
|
34
37
|
case browse(path: String)
|
|
38
|
+
/// A later selection began to play before this one resolved; the caller plays nothing.
|
|
39
|
+
case superseded
|
|
35
40
|
case none
|
|
36
41
|
}
|
|
37
42
|
|
|
@@ -47,6 +52,8 @@ class TrackSelector {
|
|
|
47
52
|
/// the current queue when it came from the same parent, else the parent expanded into a queue
|
|
48
53
|
/// (the track alone if expansion fails); a single track for a `src`; browse for a bare `path`.
|
|
49
54
|
/// A playback is first offered to the app's `handleTrackLoad`, which can intercept it.
|
|
55
|
+
/// Of the playbacks still resolving, only the latest plays, even when the app intercepts it:
|
|
56
|
+
/// an earlier one is `superseded`, and is not offered to the app once it is.
|
|
50
57
|
func select(
|
|
51
58
|
track: Track,
|
|
52
59
|
player: some TrackSelectionPlayer,
|
|
@@ -56,17 +63,20 @@ class TrackSelector {
|
|
|
56
63
|
return .none
|
|
57
64
|
}
|
|
58
65
|
|
|
59
|
-
let
|
|
60
|
-
if
|
|
61
|
-
|
|
62
|
-
} else if track.src != nil {
|
|
63
|
-
playback = .single(track)
|
|
64
|
-
} else if let path = track.path {
|
|
65
|
-
return .browse(path: path)
|
|
66
|
-
} else {
|
|
66
|
+
let contextualPath = track.path.flatMap { BrowserPathHelper.isContextual($0) ? $0 : nil }
|
|
67
|
+
if contextualPath == nil, track.src == nil {
|
|
68
|
+
if let path = track.path { return .browse(path: path) }
|
|
67
69
|
return .none
|
|
68
70
|
}
|
|
69
71
|
|
|
72
|
+
let selection = beginSelection()
|
|
73
|
+
let playback: PlannedPlayback = if let contextualPath {
|
|
74
|
+
await contextualPlayback(contextualPath, track: track, player: player)
|
|
75
|
+
} else {
|
|
76
|
+
.single(track)
|
|
77
|
+
}
|
|
78
|
+
guard isLatest(selection) else { return .superseded }
|
|
79
|
+
|
|
70
80
|
let event = TrackLoadEvent(
|
|
71
81
|
track: track,
|
|
72
82
|
queue: playback.queue,
|
|
@@ -76,11 +86,21 @@ class TrackSelector {
|
|
|
76
86
|
if await browserManager.awaitTrackLoadHandler(event: event) {
|
|
77
87
|
return .intercepted
|
|
78
88
|
}
|
|
89
|
+
guard isLatest(selection) else { return .superseded }
|
|
79
90
|
return .play(playback.intent)
|
|
80
91
|
}
|
|
81
92
|
|
|
82
93
|
// MARK: - Private Helpers
|
|
83
94
|
|
|
95
|
+
private func beginSelection() -> UInt {
|
|
96
|
+
latestSelection += 1
|
|
97
|
+
return latestSelection
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
private func isLatest(_ selection: UInt) -> Bool {
|
|
101
|
+
selection == latestSelection
|
|
102
|
+
}
|
|
103
|
+
|
|
84
104
|
/// What a selection plays, and the queue and index the track-load handler is shown.
|
|
85
105
|
private struct PlannedPlayback {
|
|
86
106
|
let queue: [Track]
|
|
@@ -9,14 +9,15 @@ enum ArtworkImageFetcher {
|
|
|
9
9
|
private static let logger = Logger(subsystem: "com.audiobrowser", category: "ArtworkImageFetcher")
|
|
10
10
|
|
|
11
11
|
/// Returns nil when the image cannot be loaded, logging a failed fetch (not an unparseable URI). A stale image whose refetch fails
|
|
12
|
-
/// falls back to the cached copy.
|
|
12
|
+
/// falls back to the cached copy.
|
|
13
|
+
/// - Parameter fitting: Fits the image into `size` points at `scale`, rasterizing it as an SVG
|
|
14
|
+
/// when `isSvg`; nil keeps the image as fetched.
|
|
13
15
|
/// - Parameter waitsForConnectivity: A fetch that fails for want of a connection waits for one
|
|
14
16
|
/// and tries again. A cancelled fetch that is waiting ends when the connection returns.
|
|
15
17
|
@MainActor
|
|
16
18
|
static func fetchImage(
|
|
17
19
|
from source: ImageSource,
|
|
18
|
-
|
|
19
|
-
downsampleTo: (size: CGSize, scale: CGFloat)? = nil,
|
|
20
|
+
fitting: (size: CGSize, scale: CGFloat, isSvg: Bool)? = nil,
|
|
20
21
|
waitsForConnectivity: Bool = false,
|
|
21
22
|
) async -> UIImage? {
|
|
22
23
|
guard let url = URL(string: source.uri) else { return nil }
|
|
@@ -33,14 +34,14 @@ enum ArtworkImageFetcher {
|
|
|
33
34
|
options.append(.requestModifier(modifier))
|
|
34
35
|
}
|
|
35
36
|
let processor: (any ImageProcessor)?
|
|
36
|
-
if let
|
|
37
|
-
processor = SVGProcessor(
|
|
38
|
-
} else if let
|
|
37
|
+
if let fitting, fitting.isSvg {
|
|
38
|
+
processor = SVGProcessor(slot: fitting.size, scale: fitting.scale)
|
|
39
|
+
} else if let fitting {
|
|
39
40
|
// The only sizing that is guaranteed: a size hint sent upstream is advisory and a CDN may
|
|
40
41
|
// return the original. cacheOriginalImage keeps the original on disk so another target
|
|
41
42
|
// size re-processes it instead of downloading it again.
|
|
42
|
-
processor = DownsamplingImageProcessor(size:
|
|
43
|
-
options.append(.scaleFactor(
|
|
43
|
+
processor = DownsamplingImageProcessor(size: fitting.size)
|
|
44
|
+
options.append(.scaleFactor(fitting.scale))
|
|
44
45
|
options.append(.cacheOriginalImage)
|
|
45
46
|
} else {
|
|
46
47
|
processor = nil
|