one 2.11.5 → 2.12.1
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/margelo/nitro/one/HybridOneAudio.kt +309 -124
- package/dist/cjs/cli/build.cjs +31 -33
- package/dist/cjs/cli/build.native.cjs +31 -33
- package/dist/cjs/cli/build.native.js +31 -33
- package/dist/cjs/cli/build.native.js.map +1 -1
- package/dist/cjs/cli/buildPage.cjs +11 -7
- package/dist/cjs/cli/buildPage.native.cjs +11 -7
- package/dist/cjs/cli/buildPage.native.js +11 -7
- package/dist/cjs/cli/buildPage.native.js.map +1 -1
- package/dist/cjs/cli/buildPageWorker.cjs +1 -1
- package/dist/cjs/cli/buildPageWorker.native.cjs +1 -1
- package/dist/cjs/cli/buildPageWorker.native.js +1 -1
- package/dist/cjs/cli/buildPageWorker.native.js.map +1 -1
- package/dist/cjs/cli-dev-memory.cjs +43 -0
- package/dist/cjs/cli-dev-memory.native.cjs +84 -0
- package/dist/cjs/cli-dev-memory.native.js +86 -0
- package/dist/cjs/cli-dev-memory.native.js.map +1 -0
- package/dist/cjs/headless-server.cjs +2 -5
- package/dist/cjs/headless-server.native.cjs +2 -5
- package/dist/cjs/headless-server.native.js +2 -5
- package/dist/cjs/headless-server.native.js.map +1 -1
- package/dist/cjs/platform/audio/index.cjs +83 -76
- package/dist/cjs/platform/audio/index.native.cjs +2 -2
- package/dist/cjs/platform/audio/index.native.js +2 -2
- package/dist/cjs/platform/audio/index.native.js.map +1 -1
- package/dist/cjs/platform/audio/nowPlaying.cjs +126 -0
- package/dist/cjs/platform/audio/nowPlaying.native.cjs +160 -0
- package/dist/cjs/platform/audio/nowPlaying.native.js +162 -0
- package/dist/cjs/platform/audio/nowPlaying.native.js.map +1 -0
- package/dist/cjs/platform/audio/player.cjs +15 -0
- package/dist/cjs/platform/audio/player.native.cjs +14 -0
- package/dist/cjs/platform/audio/player.native.js +14 -0
- package/dist/cjs/platform/audio/player.native.js.map +1 -1
- package/dist/cjs/platform/audio/unavailable.cjs +1 -1
- package/dist/cjs/platform/audio/unavailable.native.cjs +1 -1
- package/dist/cjs/platform/audio/unavailable.native.js +1 -1
- package/dist/cjs/platform/audio/unavailable.native.js.map +1 -1
- package/dist/cjs/serve-worker.cjs +0 -3
- package/dist/cjs/serve-worker.native.cjs +0 -3
- package/dist/cjs/serve-worker.native.js +0 -3
- package/dist/cjs/serve-worker.native.js.map +1 -1
- package/dist/cjs/server/oneServe.cjs +0 -6
- package/dist/cjs/server/oneServe.native.cjs +0 -6
- package/dist/cjs/server/oneServe.native.js +0 -6
- package/dist/cjs/server/oneServe.native.js.map +1 -1
- package/dist/cjs/server/workerHandler.cjs +12 -10
- package/dist/cjs/server/workerHandler.native.cjs +14 -10
- package/dist/cjs/server/workerHandler.native.js +14 -10
- package/dist/cjs/server/workerHandler.native.js.map +1 -1
- package/dist/cjs/vite/plugins/workerdDevPlugin.cjs +33 -37
- package/dist/cjs/vite/plugins/workerdDevPlugin.native.cjs +33 -37
- package/dist/cjs/vite/plugins/workerdDevPlugin.native.js +33 -37
- package/dist/cjs/vite/plugins/workerdDevPlugin.native.js.map +1 -1
- package/dist/esm/cli/build.mjs +31 -33
- package/dist/esm/cli/build.mjs.map +1 -1
- package/dist/esm/cli/build.native.js +31 -33
- package/dist/esm/cli/build.native.js.map +1 -1
- package/dist/esm/cli/buildPage.mjs +11 -7
- package/dist/esm/cli/buildPage.mjs.map +1 -1
- package/dist/esm/cli/buildPage.native.js +11 -7
- package/dist/esm/cli/buildPage.native.js.map +1 -1
- package/dist/esm/cli/buildPageWorker.mjs +1 -1
- package/dist/esm/cli/buildPageWorker.mjs.map +1 -1
- package/dist/esm/cli/buildPageWorker.native.js +1 -1
- package/dist/esm/cli/buildPageWorker.native.js.map +1 -1
- package/dist/esm/cli-dev-memory.mjs +23 -0
- package/dist/esm/cli-dev-memory.mjs.map +1 -0
- package/dist/esm/cli-dev-memory.native.js +62 -0
- package/dist/esm/cli-dev-memory.native.js.map +1 -0
- package/dist/esm/headless-server.mjs +2 -3
- package/dist/esm/headless-server.mjs.map +1 -1
- package/dist/esm/headless-server.native.js +2 -3
- package/dist/esm/headless-server.native.js.map +1 -1
- package/dist/esm/platform/audio/index.mjs +83 -76
- package/dist/esm/platform/audio/index.mjs.map +1 -1
- package/dist/esm/platform/audio/index.native.js +2 -2
- package/dist/esm/platform/audio/index.native.js.map +1 -1
- package/dist/esm/platform/audio/nowPlaying.mjs +102 -0
- package/dist/esm/platform/audio/nowPlaying.mjs.map +1 -0
- package/dist/esm/platform/audio/nowPlaying.native.js +134 -0
- package/dist/esm/platform/audio/nowPlaying.native.js.map +1 -0
- package/dist/esm/platform/audio/player.mjs +15 -0
- package/dist/esm/platform/audio/player.mjs.map +1 -1
- package/dist/esm/platform/audio/player.native.js +14 -0
- package/dist/esm/platform/audio/player.native.js.map +1 -1
- package/dist/esm/platform/audio/unavailable.mjs +1 -1
- package/dist/esm/platform/audio/unavailable.mjs.map +1 -1
- package/dist/esm/platform/audio/unavailable.native.js +1 -1
- package/dist/esm/platform/audio/unavailable.native.js.map +1 -1
- package/dist/esm/serve-worker.mjs +1 -2
- package/dist/esm/serve-worker.mjs.map +1 -1
- package/dist/esm/serve-worker.native.js +1 -2
- package/dist/esm/serve-worker.native.js.map +1 -1
- package/dist/esm/server/oneServe.mjs +0 -6
- package/dist/esm/server/oneServe.mjs.map +1 -1
- package/dist/esm/server/oneServe.native.js +0 -6
- package/dist/esm/server/oneServe.native.js.map +1 -1
- package/dist/esm/server/workerHandler.mjs +12 -10
- package/dist/esm/server/workerHandler.mjs.map +1 -1
- package/dist/esm/server/workerHandler.native.js +14 -10
- package/dist/esm/server/workerHandler.native.js.map +1 -1
- package/dist/esm/vite/plugins/workerdDevPlugin.mjs +33 -37
- package/dist/esm/vite/plugins/workerdDevPlugin.mjs.map +1 -1
- package/dist/esm/vite/plugins/workerdDevPlugin.native.js +33 -37
- package/dist/esm/vite/plugins/workerdDevPlugin.native.js.map +1 -1
- package/ios/Nitro/HybridOneAudio.swift +309 -96
- package/nitrogen/generated/android/c++/JAudioPlayOptions.hpp +61 -0
- package/nitrogen/generated/android/c++/JAudioRemoteCommandEvent.hpp +8 -3
- package/nitrogen/generated/android/c++/JFunc_void_AudioRemoteCommandEvent.hpp +1 -0
- package/nitrogen/generated/android/c++/JHybridOneAudioSpec.cpp +37 -3
- package/nitrogen/generated/android/c++/JHybridOneAudioSpec.hpp +3 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/one/AudioPlayOptions.kt +56 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/one/AudioRemoteCommandEvent.kt +9 -4
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/one/HybridOneAudioSpec.kt +40 -32
- package/nitrogen/generated/ios/One-Swift-Cxx-Umbrella.hpp +3 -0
- package/nitrogen/generated/ios/c++/HybridOneAudioSpecSwift.hpp +21 -2
- package/nitrogen/generated/ios/swift/AudioPlayOptions.swift +60 -0
- package/nitrogen/generated/ios/swift/AudioRemoteCommandEvent.swift +19 -1
- package/nitrogen/generated/ios/swift/HybridOneAudioSpec.swift +3 -1
- package/nitrogen/generated/ios/swift/HybridOneAudioSpec_cxx.swift +70 -32
- package/nitrogen/generated/shared/c++/AudioPlayOptions.hpp +87 -0
- package/nitrogen/generated/shared/c++/AudioRemoteCommandEvent.hpp +7 -2
- package/nitrogen/generated/shared/c++/HybridOneAudioSpec.cpp +2 -0
- package/nitrogen/generated/shared/c++/HybridOneAudioSpec.hpp +6 -1
- package/package.json +13 -13
- package/run.mjs +5 -1
- package/src/cli/build.ts +35 -32
- package/src/cli/buildPage.test.ts +152 -0
- package/src/cli/buildPage.ts +14 -9
- package/src/cli/buildPageWorker.ts +2 -1
- package/src/cli/workerPool.ts +1 -0
- package/src/cli-dev-memory.ts +24 -0
- package/src/headless-server.ts +2 -2
- package/src/index.ts +1 -0
- package/src/platform/audio/index.native.ts +4 -2
- package/src/platform/audio/index.ts +102 -74
- package/src/platform/audio/nowPlaying.ts +122 -0
- package/src/platform/audio/player.native.ts +17 -1
- package/src/platform/audio/player.ts +23 -1
- package/src/platform/audio/types.ts +6 -1
- package/src/platform/audio/unavailable.ts +3 -1
- package/src/platform/index.native.ts +1 -0
- package/src/platform/index.ts +1 -0
- package/src/platform/specs/OneAudio.nitro.ts +11 -1
- package/src/serve-worker.ts +2 -3
- package/src/server/oneServe.ts +0 -6
- package/src/server/workerHandler.ts +34 -18
- package/src/vite/plugins/workerdDevPlugin.ts +33 -37
- package/src/vite/resolveResponse.ts +2 -2
- package/types/cli/build.d.ts.map +1 -1
- package/types/cli/buildPage.d.ts +1 -1
- package/types/cli/buildPage.d.ts.map +1 -1
- package/types/cli/workerPool.d.ts +1 -0
- package/types/cli/workerPool.d.ts.map +1 -1
- package/types/cli-dev-memory.d.ts +2 -0
- package/types/cli-dev-memory.d.ts.map +1 -0
- package/types/headless-server.d.ts +3 -3
- package/types/headless-server.d.ts.map +1 -1
- package/types/index.d.ts +1 -1
- package/types/index.d.ts.map +1 -1
- package/types/platform/audio/index.d.ts +2 -2
- package/types/platform/audio/index.d.ts.map +1 -1
- package/types/platform/audio/index.native.d.ts +3 -3
- package/types/platform/audio/index.native.d.ts.map +1 -1
- package/types/platform/audio/nowPlaying.d.ts +12 -0
- package/types/platform/audio/nowPlaying.d.ts.map +1 -0
- package/types/platform/audio/player.d.ts +3 -1
- package/types/platform/audio/player.d.ts.map +1 -1
- package/types/platform/audio/player.native.d.ts +3 -1
- package/types/platform/audio/player.native.d.ts.map +1 -1
- package/types/platform/audio/types.d.ts +3 -1
- package/types/platform/audio/types.d.ts.map +1 -1
- package/types/platform/audio/unavailable.d.ts +3 -3
- package/types/platform/audio/unavailable.d.ts.map +1 -1
- package/types/platform/index.d.ts +1 -1
- package/types/platform/index.d.ts.map +1 -1
- package/types/platform/index.native.d.ts +1 -1
- package/types/platform/index.native.d.ts.map +1 -1
- package/types/platform/specs/OneAudio.nitro.d.ts +8 -1
- package/types/platform/specs/OneAudio.nitro.d.ts.map +1 -1
- package/types/serve-worker.d.ts +3 -3
- package/types/serve-worker.d.ts.map +1 -1
- package/types/server/oneServe.d.ts.map +1 -1
- package/types/server/workerHandler.d.ts +1 -1
- package/types/server/workerHandler.d.ts.map +1 -1
- package/types/vite/plugins/workerdDevPlugin.d.ts.map +1 -1
- package/types/vite/resolveResponse.d.ts +1 -1
- package/types/vite/resolveResponse.d.ts.map +1 -1
- package/dist/cjs/server/staticHtmlFetcher.cjs +0 -33
- package/dist/cjs/server/staticHtmlFetcher.native.cjs +0 -35
- package/dist/cjs/server/staticHtmlFetcher.native.js +0 -37
- package/dist/cjs/server/staticHtmlFetcher.native.js.map +0 -1
- package/dist/esm/server/staticHtmlFetcher.mjs +0 -10
- package/dist/esm/server/staticHtmlFetcher.mjs.map +0 -1
- package/dist/esm/server/staticHtmlFetcher.native.js +0 -10
- package/dist/esm/server/staticHtmlFetcher.native.js.map +0 -1
- package/src/server/staticHtmlFetcher.ts +0 -12
- package/types/server/staticHtmlFetcher.d.ts +0 -3
- package/types/server/staticHtmlFetcher.d.ts.map +0 -1
|
@@ -23,14 +23,14 @@ __export(audio_exports, { Audio: () => Audio });
|
|
|
23
23
|
module.exports = __toCommonJS(audio_exports);
|
|
24
24
|
var import_unavailable = require("./unavailable.cjs");
|
|
25
25
|
var import_validateCallback = require("../validateCallback.cjs");
|
|
26
|
+
var import_nowPlaying = require("./nowPlaying.cjs");
|
|
26
27
|
var import_player = require("./player.cjs");
|
|
27
28
|
let player;
|
|
29
|
+
let pendingLoad;
|
|
28
30
|
let playbackError;
|
|
29
31
|
let permission = "undetermined";
|
|
30
32
|
let openingRecording = false;
|
|
31
33
|
let recording;
|
|
32
|
-
const remoteListeners = /* @__PURE__ */ new Set();
|
|
33
|
-
let remoteInstalled = false;
|
|
34
34
|
async function getRecordingPermissionStatus() {
|
|
35
35
|
if (typeof window === "undefined" || !navigator.mediaDevices?.getUserMedia) return "denied";
|
|
36
36
|
try {
|
|
@@ -66,7 +66,7 @@ function playbackStatus() {
|
|
|
66
66
|
positionMs: 0
|
|
67
67
|
};
|
|
68
68
|
return {
|
|
69
|
-
state: player.error || playbackError ? "failed" : player.ended ? "ended" : player.readyState < 2 ? "loading" : player.paused ? "paused" : "playing",
|
|
69
|
+
state: player.error || playbackError ? "failed" : player.ended ? "ended" : pendingLoad || player.readyState < 2 ? "loading" : player.paused ? "paused" : "playing",
|
|
70
70
|
uri: player.src,
|
|
71
71
|
positionMs: player.currentTime * 1e3,
|
|
72
72
|
...Number.isFinite(player.duration) && { durationMs: player.duration * 1e3 },
|
|
@@ -78,7 +78,9 @@ function requirePlayer() {
|
|
|
78
78
|
return player;
|
|
79
79
|
}
|
|
80
80
|
function clearPlayer() {
|
|
81
|
-
|
|
81
|
+
(0, import_nowPlaying.releaseNowPlaying)("global");
|
|
82
|
+
pendingLoad?.cancel?.();
|
|
83
|
+
pendingLoad = void 0;
|
|
82
84
|
if (player) {
|
|
83
85
|
player.pause();
|
|
84
86
|
player.removeAttribute("src");
|
|
@@ -134,56 +136,46 @@ function recorderChange(event) {
|
|
|
134
136
|
}
|
|
135
137
|
});
|
|
136
138
|
}
|
|
137
|
-
function
|
|
138
|
-
|
|
139
|
-
return
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
}
|
|
171
|
-
function installRemote() {
|
|
172
|
-
if (remoteInstalled) return;
|
|
173
|
-
const session = mediaSession();
|
|
174
|
-
session.setActionHandler("play", () => remote({ type: "play" }));
|
|
175
|
-
session.setActionHandler("pause", () => remote({ type: "pause" }));
|
|
176
|
-
session.setActionHandler("seekto", (event) => remote({
|
|
177
|
-
type: "seek",
|
|
178
|
-
positionMs: (event.seekTime ?? 0) * 1e3
|
|
179
|
-
}));
|
|
180
|
-
remoteInstalled = true;
|
|
139
|
+
function prepareAt(load, positionMs) {
|
|
140
|
+
const { audio } = load;
|
|
141
|
+
return new Promise((resolve, reject) => {
|
|
142
|
+
const cleanup = () => {
|
|
143
|
+
audio.removeEventListener("loadedmetadata", ready);
|
|
144
|
+
audio.removeEventListener("seeked", done);
|
|
145
|
+
audio.removeEventListener("error", failed);
|
|
146
|
+
load.cancel = void 0;
|
|
147
|
+
};
|
|
148
|
+
let seconds = 0;
|
|
149
|
+
const done = () => {
|
|
150
|
+
cleanup();
|
|
151
|
+
if (Math.abs(audio.currentTime - seconds) > .25) reject(new Error("Audio.play: the source cannot seek to the position"));
|
|
152
|
+
else resolve();
|
|
153
|
+
};
|
|
154
|
+
const failed = () => {
|
|
155
|
+
cleanup();
|
|
156
|
+
reject(new Error(`Audio.play: ${audio.error?.message || "decoding failed"}`));
|
|
157
|
+
};
|
|
158
|
+
function ready() {
|
|
159
|
+
audio.removeEventListener("loadedmetadata", ready);
|
|
160
|
+
seconds = Math.min(positionMs / 1e3, Number.isFinite(audio.duration) ? audio.duration : Infinity);
|
|
161
|
+
if (audio.currentTime === seconds) return done();
|
|
162
|
+
audio.addEventListener("seeked", done, { once: true });
|
|
163
|
+
audio.currentTime = seconds;
|
|
164
|
+
}
|
|
165
|
+
load.cancel = () => {
|
|
166
|
+
cleanup();
|
|
167
|
+
reject(new Error("Audio.play: playback was replaced"));
|
|
168
|
+
};
|
|
169
|
+
audio.addEventListener("error", failed, { once: true });
|
|
170
|
+
if (audio.readyState >= 1) ready();
|
|
171
|
+
else audio.addEventListener("loadedmetadata", ready, { once: true });
|
|
172
|
+
});
|
|
181
173
|
}
|
|
182
174
|
const Audio = Object.freeze({
|
|
183
175
|
getRecordingPermissionStatus,
|
|
184
176
|
requestRecordingPermission,
|
|
185
|
-
play: async (uri) => {
|
|
186
|
-
if (typeof window === "undefined") return import_unavailable.Audio.play(uri);
|
|
177
|
+
play: async (uri, options) => {
|
|
178
|
+
if (typeof window === "undefined") return import_unavailable.Audio.play(uri, options);
|
|
187
179
|
if (openingRecording || recording) throw new Error("Audio.play: stop the current recording first");
|
|
188
180
|
const url = new URL(uri, document.baseURI);
|
|
189
181
|
if (![
|
|
@@ -192,17 +184,35 @@ const Audio = Object.freeze({
|
|
|
192
184
|
"blob:",
|
|
193
185
|
"data:"
|
|
194
186
|
].includes(url.protocol)) throw new Error("Audio.play: invalid browser audio URI");
|
|
187
|
+
const prepare = options?.positionMs !== void 0 || options?.paused !== void 0;
|
|
188
|
+
const positionMs = options?.positionMs ?? 0;
|
|
189
|
+
if (typeof positionMs !== "number" || !Number.isFinite(positionMs) || positionMs < 0) throw new Error("Audio.play: position must be finite and nonnegative");
|
|
195
190
|
clearPlayer();
|
|
196
191
|
const audio = new window.Audio(url.href);
|
|
197
192
|
player = audio;
|
|
198
|
-
for (const event of [
|
|
199
|
-
"play",
|
|
200
|
-
"pause",
|
|
201
|
-
"ended"
|
|
202
|
-
]) audio.addEventListener(event, syncNowPlaying);
|
|
203
193
|
audio.addEventListener("error", () => {
|
|
204
194
|
if (player === audio) playbackError = audio.error?.message ?? "Audio.play: decoding failed";
|
|
205
195
|
});
|
|
196
|
+
if (prepare) {
|
|
197
|
+
const load = {
|
|
198
|
+
audio,
|
|
199
|
+
paused: options?.paused ?? false
|
|
200
|
+
};
|
|
201
|
+
pendingLoad = load;
|
|
202
|
+
audio.preload = "auto";
|
|
203
|
+
try {
|
|
204
|
+
await prepareAt(load, positionMs);
|
|
205
|
+
} catch (error) {
|
|
206
|
+
if (pendingLoad === load) {
|
|
207
|
+
pendingLoad = void 0;
|
|
208
|
+
playbackError = error.message;
|
|
209
|
+
}
|
|
210
|
+
throw error;
|
|
211
|
+
}
|
|
212
|
+
if (player !== audio || pendingLoad !== load) throw new Error("Audio.play: playback was replaced");
|
|
213
|
+
pendingLoad = void 0;
|
|
214
|
+
if (load.paused) return playbackStatus();
|
|
215
|
+
}
|
|
206
216
|
try {
|
|
207
217
|
await audio.play();
|
|
208
218
|
} catch (error) {
|
|
@@ -216,6 +226,10 @@ const Audio = Object.freeze({
|
|
|
216
226
|
pause: async () => {
|
|
217
227
|
if (typeof window === "undefined") return import_unavailable.Audio.pause();
|
|
218
228
|
const audio = requirePlayer();
|
|
229
|
+
if (pendingLoad) {
|
|
230
|
+
pendingLoad.paused = true;
|
|
231
|
+
return playbackStatus();
|
|
232
|
+
}
|
|
219
233
|
if (!audio.paused) await new Promise((resolve) => {
|
|
220
234
|
audio.addEventListener("pause", () => resolve(), { once: true });
|
|
221
235
|
audio.pause();
|
|
@@ -225,6 +239,10 @@ const Audio = Object.freeze({
|
|
|
225
239
|
resume: async () => {
|
|
226
240
|
if (typeof window === "undefined") return import_unavailable.Audio.resume();
|
|
227
241
|
const audio = requirePlayer();
|
|
242
|
+
if (pendingLoad) {
|
|
243
|
+
pendingLoad.paused = false;
|
|
244
|
+
return playbackStatus();
|
|
245
|
+
}
|
|
228
246
|
if (audio.ended) audio.currentTime = 0;
|
|
229
247
|
await audio.play();
|
|
230
248
|
if (player !== audio) throw new Error("Audio.resume: playback was replaced");
|
|
@@ -234,7 +252,7 @@ const Audio = Object.freeze({
|
|
|
234
252
|
if (typeof window === "undefined") return import_unavailable.Audio.seek(positionMs);
|
|
235
253
|
if (!Number.isFinite(positionMs) || positionMs < 0) throw new Error("Audio.seek: position must be finite and nonnegative");
|
|
236
254
|
const audio = requirePlayer();
|
|
237
|
-
if (audio.readyState < 1) throw new Error("Audio.seek: playback is not ready");
|
|
255
|
+
if (audio.readyState < 1 || pendingLoad) throw new Error("Audio.seek: playback is not ready");
|
|
238
256
|
const seconds = Math.min(positionMs / 1e3, Number.isFinite(audio.duration) ? audio.duration : Infinity);
|
|
239
257
|
if (audio.currentTime === seconds) return playbackStatus();
|
|
240
258
|
await new Promise((resolve, reject) => {
|
|
@@ -373,34 +391,23 @@ const Audio = Object.freeze({
|
|
|
373
391
|
watchInterruptions: import_unavailable.Audio.watchInterruptions,
|
|
374
392
|
setNowPlayingInfo: async (info) => {
|
|
375
393
|
if (typeof window === "undefined") return import_unavailable.Audio.setNowPlayingInfo(info);
|
|
376
|
-
if (!info.title.trim()) throw new Error("Audio.setNowPlayingInfo: title must not be empty");
|
|
377
394
|
const audio = requirePlayer();
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
title: info.title,
|
|
386
|
-
artist: info.artist,
|
|
387
|
-
album: info.albumTitle,
|
|
388
|
-
artwork: info.artworkUri ? [{ src: info.artworkUri }] : []
|
|
389
|
-
});
|
|
390
|
-
installRemote();
|
|
391
|
-
syncNowPlaying();
|
|
395
|
+
await (0, import_nowPlaying.claimNowPlaying)({
|
|
396
|
+
key: "global",
|
|
397
|
+
element: audio,
|
|
398
|
+
play: Audio.resume,
|
|
399
|
+
pause: Audio.pause,
|
|
400
|
+
seek: Audio.seek
|
|
401
|
+
}, info, "Audio.setNowPlayingInfo", () => player === audio);
|
|
392
402
|
},
|
|
393
403
|
clearNowPlayingInfo: async () => {
|
|
394
404
|
if (typeof window === "undefined") return import_unavailable.Audio.clearNowPlayingInfo();
|
|
395
|
-
|
|
405
|
+
(0, import_nowPlaying.releaseNowPlaying)("global");
|
|
396
406
|
},
|
|
397
407
|
watchRemoteCommands: (onEvent) => {
|
|
398
408
|
(0, import_validateCallback.validateCallback)(onEvent, "Audio.watchRemoteCommands: onEvent must be a function");
|
|
399
409
|
if (typeof window === "undefined" || !navigator.mediaSession) return import_unavailable.Audio.watchRemoteCommands(onEvent);
|
|
400
|
-
|
|
401
|
-
return () => {
|
|
402
|
-
remoteListeners.delete(onEvent);
|
|
403
|
-
};
|
|
410
|
+
return (0, import_nowPlaying.addRemoteListener)(onEvent);
|
|
404
411
|
},
|
|
405
412
|
AudioPlayer: import_player.AudioPlayer,
|
|
406
413
|
createPlayer: import_player.createPlayer
|
|
@@ -34,8 +34,8 @@ var Audio = Object.freeze({
|
|
|
34
34
|
requestRecordingPermission: function requestRecordingPermission() {
|
|
35
35
|
return (0, import_hybrid.audioNative)().requestRecordingPermission().catch(import_nativeError.rethrowNativeError);
|
|
36
36
|
},
|
|
37
|
-
play: function play(uri) {
|
|
38
|
-
return (0, import_hybrid.audioNative)().play(uri).catch(import_nativeError.rethrowNativeError);
|
|
37
|
+
play: function play(uri, options) {
|
|
38
|
+
return (0, import_hybrid.audioNative)().play(uri, options !== null && options !== void 0 ? options : {}).catch(import_nativeError.rethrowNativeError);
|
|
39
39
|
},
|
|
40
40
|
getPlaybackStatus: function getPlaybackStatus() {
|
|
41
41
|
return (0, import_hybrid.audioNative)().getPlaybackStatus().catch(import_nativeError.rethrowNativeError);
|
|
@@ -34,8 +34,8 @@ var Audio = Object.freeze({
|
|
|
34
34
|
requestRecordingPermission: function requestRecordingPermission() {
|
|
35
35
|
return (0, import_hybrid.audioNative)().requestRecordingPermission().catch(import_nativeError.rethrowNativeError);
|
|
36
36
|
},
|
|
37
|
-
play: function play(uri) {
|
|
38
|
-
return (0, import_hybrid.audioNative)().play(uri).catch(import_nativeError.rethrowNativeError);
|
|
37
|
+
play: function play(uri, options) {
|
|
38
|
+
return (0, import_hybrid.audioNative)().play(uri, options !== null && options !== void 0 ? options : {}).catch(import_nativeError.rethrowNativeError);
|
|
39
39
|
},
|
|
40
40
|
getPlaybackStatus: function getPlaybackStatus() {
|
|
41
41
|
return (0, import_hybrid.audioNative)().getPlaybackStatus().catch(import_nativeError.rethrowNativeError);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.native.js","names":[],"sources":["cjs/platform/audio/index.native.js"],"sourcesContent":["\"use strict\";\nvar __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\nvar __hasOwnProp = Object.prototype.hasOwnProperty;\nvar __export = (target, all) => {\n for (var name in all)\n __defProp(target, name, { get: all[name], enumerable: true });\n};\nvar __copyProps = (to, from, except, desc) => {\n if (from && typeof from === \"object\" || typeof from === \"function\") {\n for (let key of __getOwnPropNames(from))\n if (!__hasOwnProp.call(to, key) && key !== except)\n __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });\n }\n return to;\n};\nvar __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\nvar index_native_exports = {};\n__export(index_native_exports, {\n Audio: () => Audio\n});\nmodule.exports = __toCommonJS(index_native_exports);\nvar import_validateCallback = require(\"../validateCallback\");\nvar import_nativeError = require(\"../nativeError\");\nvar import_hybrid = require(\"./hybrid.native\");\nvar import_player = require(\"./player.native\");\nvar Audio = Object.freeze({\n getRecordingPermissionStatus: function getRecordingPermissionStatus() {\n return (0, import_hybrid.audioNative)().getRecordingPermissionStatus().catch(import_nativeError.rethrowNativeError);\n },\n requestRecordingPermission: function requestRecordingPermission() {\n return (0, import_hybrid.audioNative)().requestRecordingPermission().catch(import_nativeError.rethrowNativeError);\n },\n play: function play(uri) {\n return (0, import_hybrid.audioNative)().play(uri).catch(import_nativeError.rethrowNativeError);\n },\n getPlaybackStatus: function getPlaybackStatus() {\n return (0, import_hybrid.audioNative)().getPlaybackStatus().catch(import_nativeError.rethrowNativeError);\n },\n pause: function pause() {\n return (0, import_hybrid.audioNative)().pause().catch(import_nativeError.rethrowNativeError);\n },\n resume: function resume() {\n return (0, import_hybrid.audioNative)().resume().catch(import_nativeError.rethrowNativeError);\n },\n seek: function seek(positionMs) {\n return (0, import_hybrid.audioNative)().seek(positionMs).catch(import_nativeError.rethrowNativeError);\n },\n stop: function stop() {\n return (0, import_hybrid.audioNative)().stop().catch(import_nativeError.rethrowNativeError);\n },\n startRecording: function startRecording() {\n return (0, import_hybrid.audioNative)().startRecording().catch(import_nativeError.rethrowNativeError);\n },\n getRecordingStatus: function getRecordingStatus() {\n return (0, import_hybrid.audioNative)().getRecordingStatus().catch(import_nativeError.rethrowNativeError);\n },\n pauseRecording: function pauseRecording() {\n return (0, import_hybrid.audioNative)().pauseRecording().catch(import_nativeError.rethrowNativeError);\n },\n resumeRecording: function resumeRecording() {\n return (0, import_hybrid.audioNative)().resumeRecording().catch(import_nativeError.rethrowNativeError);\n },\n stopRecording: function stopRecording() {\n return (0, import_hybrid.audioNative)().stopRecording().catch(import_nativeError.rethrowNativeError);\n },\n watchInterruptions: function watchInterruptions(onEvent) {\n (0, import_validateCallback.validateCallback)(onEvent, \"Audio.watchInterruptions: onEvent must be a function\");\n return (0, import_hybrid.audioNative)().addInterruptionListener(onEvent);\n },\n setNowPlayingInfo: function setNowPlayingInfo(info) {\n return (0, import_hybrid.audioNative)().setNowPlayingInfo(info).catch(import_nativeError.rethrowNativeError);\n },\n clearNowPlayingInfo: function clearNowPlayingInfo() {\n return (0, import_hybrid.audioNative)().clearNowPlayingInfo().catch(import_nativeError.rethrowNativeError);\n },\n watchRemoteCommands: function watchRemoteCommands(onEvent) {\n (0, import_validateCallback.validateCallback)(onEvent, \"Audio.watchRemoteCommands: onEvent must be a function\");\n return (0, import_hybrid.audioNative)().addRemoteCommandListener(onEvent);\n },\n AudioPlayer: import_player.AudioPlayer,\n createPlayer: import_player.createPlayer\n});\n//# sourceMappingURL=index.native.js.map\n"],"mappings":";;;AACA,IAAI,YAAY,OAAO;AACvB,IAAI,mBAAmB,OAAO;AAC9B,IAAI,oBAAoB,OAAO;AAC/B,IAAI,eAAe,OAAO,UAAU;AACpC,IAAI,YAAY,QAAQ,QAAQ;CAC9B,KAAK,IAAI,QAAQ,KACf,UAAU,QAAQ,MAAM;EAAE,KAAK,IAAI;EAAO,YAAY;CAAK,CAAC;AAChE;AACA,IAAI,eAAe,IAAI,MAAM,QAAQ,SAAS;CAC5C,IAAI,QAAQ,OAAO,SAAS,YAAY,OAAO,SAAS,YAAY;EAClE,KAAK,IAAI,OAAO,kBAAkB,IAAI,GACpC,IAAI,CAAC,aAAa,KAAK,IAAI,GAAG,KAAK,QAAQ,QACzC,UAAU,IAAI,KAAK;GAAE,WAAW,KAAK;GAAM,YAAY,EAAE,OAAO,iBAAiB,MAAM,GAAG,MAAM,KAAK;EAAW,CAAC;CACvH;CACA,OAAO;AACT;AACA,IAAI,gBAAgB,QAAQ,YAAY,UAAU,CAAC,GAAG,cAAc,EAAE,OAAO,KAAK,CAAC,GAAG,GAAG;AACzF,IAAI,uBAAuB,CAAC;AAC5B,SAAS,sBAAsB,EAC7B,aAAa,MACf,CAAC;AACD,OAAO,UAAU,aAAa,oBAAoB;AAClD,IAAI,0BAA0B,QAAQ,+BAAqB;AAC3D,IAAI,qBAAqB,QAAQ,0BAAgB;AACjD,IAAI,gBAAgB,QAAQ,oBAAiB;AAC7C,IAAI,gBAAgB,QAAQ,oBAAiB;AAC7C,IAAI,QAAQ,OAAO,OAAO;CACxB,8BAA8B,SAAS,+BAA+B;EACpE,QAAQ,GAAG,cAAc,YAAW,CAAE,CAAC,CAAC,6BAA6B,CAAC,CAAC,MAAM,mBAAmB,kBAAkB;CACpH;CACA,4BAA4B,SAAS,6BAA6B;EAChE,QAAQ,GAAG,cAAc,YAAW,CAAE,CAAC,CAAC,2BAA2B,CAAC,CAAC,MAAM,mBAAmB,kBAAkB;CAClH;CACA,MAAM,SAAS,KAAK,KAAK;
|
|
1
|
+
{"version":3,"file":"index.native.js","names":[],"sources":["cjs/platform/audio/index.native.js"],"sourcesContent":["\"use strict\";\nvar __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\nvar __hasOwnProp = Object.prototype.hasOwnProperty;\nvar __export = (target, all) => {\n for (var name in all)\n __defProp(target, name, { get: all[name], enumerable: true });\n};\nvar __copyProps = (to, from, except, desc) => {\n if (from && typeof from === \"object\" || typeof from === \"function\") {\n for (let key of __getOwnPropNames(from))\n if (!__hasOwnProp.call(to, key) && key !== except)\n __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });\n }\n return to;\n};\nvar __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\nvar index_native_exports = {};\n__export(index_native_exports, {\n Audio: () => Audio\n});\nmodule.exports = __toCommonJS(index_native_exports);\nvar import_validateCallback = require(\"../validateCallback\");\nvar import_nativeError = require(\"../nativeError\");\nvar import_hybrid = require(\"./hybrid.native\");\nvar import_player = require(\"./player.native\");\nvar Audio = Object.freeze({\n getRecordingPermissionStatus: function getRecordingPermissionStatus() {\n return (0, import_hybrid.audioNative)().getRecordingPermissionStatus().catch(import_nativeError.rethrowNativeError);\n },\n requestRecordingPermission: function requestRecordingPermission() {\n return (0, import_hybrid.audioNative)().requestRecordingPermission().catch(import_nativeError.rethrowNativeError);\n },\n play: function play(uri, options) {\n return (0, import_hybrid.audioNative)().play(uri, options !== null && options !== void 0 ? options : {}).catch(import_nativeError.rethrowNativeError);\n },\n getPlaybackStatus: function getPlaybackStatus() {\n return (0, import_hybrid.audioNative)().getPlaybackStatus().catch(import_nativeError.rethrowNativeError);\n },\n pause: function pause() {\n return (0, import_hybrid.audioNative)().pause().catch(import_nativeError.rethrowNativeError);\n },\n resume: function resume() {\n return (0, import_hybrid.audioNative)().resume().catch(import_nativeError.rethrowNativeError);\n },\n seek: function seek(positionMs) {\n return (0, import_hybrid.audioNative)().seek(positionMs).catch(import_nativeError.rethrowNativeError);\n },\n stop: function stop() {\n return (0, import_hybrid.audioNative)().stop().catch(import_nativeError.rethrowNativeError);\n },\n startRecording: function startRecording() {\n return (0, import_hybrid.audioNative)().startRecording().catch(import_nativeError.rethrowNativeError);\n },\n getRecordingStatus: function getRecordingStatus() {\n return (0, import_hybrid.audioNative)().getRecordingStatus().catch(import_nativeError.rethrowNativeError);\n },\n pauseRecording: function pauseRecording() {\n return (0, import_hybrid.audioNative)().pauseRecording().catch(import_nativeError.rethrowNativeError);\n },\n resumeRecording: function resumeRecording() {\n return (0, import_hybrid.audioNative)().resumeRecording().catch(import_nativeError.rethrowNativeError);\n },\n stopRecording: function stopRecording() {\n return (0, import_hybrid.audioNative)().stopRecording().catch(import_nativeError.rethrowNativeError);\n },\n watchInterruptions: function watchInterruptions(onEvent) {\n (0, import_validateCallback.validateCallback)(onEvent, \"Audio.watchInterruptions: onEvent must be a function\");\n return (0, import_hybrid.audioNative)().addInterruptionListener(onEvent);\n },\n setNowPlayingInfo: function setNowPlayingInfo(info) {\n return (0, import_hybrid.audioNative)().setNowPlayingInfo(info).catch(import_nativeError.rethrowNativeError);\n },\n clearNowPlayingInfo: function clearNowPlayingInfo() {\n return (0, import_hybrid.audioNative)().clearNowPlayingInfo().catch(import_nativeError.rethrowNativeError);\n },\n watchRemoteCommands: function watchRemoteCommands(onEvent) {\n (0, import_validateCallback.validateCallback)(onEvent, \"Audio.watchRemoteCommands: onEvent must be a function\");\n return (0, import_hybrid.audioNative)().addRemoteCommandListener(onEvent);\n },\n AudioPlayer: import_player.AudioPlayer,\n createPlayer: import_player.createPlayer\n});\n//# sourceMappingURL=index.native.js.map\n"],"mappings":"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"}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all) __defProp(target, name, {
|
|
7
|
+
get: all[name],
|
|
8
|
+
enumerable: true
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
14
|
+
get: () => from[key],
|
|
15
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
21
|
+
var nowPlaying_exports = {};
|
|
22
|
+
__export(nowPlaying_exports, {
|
|
23
|
+
addRemoteListener: () => addRemoteListener,
|
|
24
|
+
claimNowPlaying: () => claimNowPlaying,
|
|
25
|
+
releaseNowPlaying: () => releaseNowPlaying
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(nowPlaying_exports);
|
|
28
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
29
|
+
const syncEvents = [
|
|
30
|
+
"play",
|
|
31
|
+
"pause",
|
|
32
|
+
"ended"
|
|
33
|
+
];
|
|
34
|
+
let owner;
|
|
35
|
+
let claim = 0;
|
|
36
|
+
let pendingKey;
|
|
37
|
+
let installed = false;
|
|
38
|
+
function sync() {
|
|
39
|
+
if (!owner || !navigator.mediaSession?.metadata) return;
|
|
40
|
+
navigator.mediaSession.playbackState = owner.element.paused || owner.element.ended ? "paused" : "playing";
|
|
41
|
+
}
|
|
42
|
+
function setOwner(next) {
|
|
43
|
+
if (owner?.element !== next?.element) {
|
|
44
|
+
for (const event of syncEvents) {
|
|
45
|
+
owner?.element.removeEventListener(event, sync);
|
|
46
|
+
next?.element.addEventListener(event, sync);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
owner = next;
|
|
50
|
+
}
|
|
51
|
+
async function remote(event) {
|
|
52
|
+
const current = owner;
|
|
53
|
+
if (!current || !navigator.mediaSession?.metadata) return;
|
|
54
|
+
try {
|
|
55
|
+
if (event.type === "play") await current.play();
|
|
56
|
+
else if (event.type === "pause") await current.pause();
|
|
57
|
+
else await current.seek(event.positionMs);
|
|
58
|
+
} catch {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
if (owner !== current) return;
|
|
62
|
+
sync();
|
|
63
|
+
const emitted = current.key === "global" ? event : {
|
|
64
|
+
...event,
|
|
65
|
+
playerId: current.key
|
|
66
|
+
};
|
|
67
|
+
for (const listener of [...listeners]) listener(emitted);
|
|
68
|
+
}
|
|
69
|
+
function install(session) {
|
|
70
|
+
if (installed) return;
|
|
71
|
+
session.setActionHandler("play", () => remote({ type: "play" }));
|
|
72
|
+
session.setActionHandler("pause", () => remote({ type: "pause" }));
|
|
73
|
+
session.setActionHandler("seekto", (event) => remote({
|
|
74
|
+
type: "seek",
|
|
75
|
+
positionMs: (event.seekTime ?? 0) * 1e3
|
|
76
|
+
}));
|
|
77
|
+
installed = true;
|
|
78
|
+
}
|
|
79
|
+
async function claimNowPlaying(next, info, verb, alive) {
|
|
80
|
+
if (!info.title.trim()) throw new Error(`${verb}: title must not be empty`);
|
|
81
|
+
if (!navigator.mediaSession) throw new Error("Audio: Media Session is unavailable");
|
|
82
|
+
const ticket = ++claim;
|
|
83
|
+
pendingKey = next.key;
|
|
84
|
+
if (info.artworkUri) {
|
|
85
|
+
const artwork = new window.Image();
|
|
86
|
+
artwork.src = info.artworkUri;
|
|
87
|
+
await artwork.decode();
|
|
88
|
+
if (!alive()) throw new Error(`${verb}: playback was replaced`);
|
|
89
|
+
if (ticket !== claim) throw new Error(`${verb}: now playing was claimed or cleared again`);
|
|
90
|
+
}
|
|
91
|
+
if (pendingKey === next.key) pendingKey = void 0;
|
|
92
|
+
const session = navigator.mediaSession;
|
|
93
|
+
setOwner(next);
|
|
94
|
+
session.metadata = new MediaMetadata({
|
|
95
|
+
title: info.title,
|
|
96
|
+
artist: info.artist,
|
|
97
|
+
album: info.albumTitle,
|
|
98
|
+
artwork: info.artworkUri ? [{ src: info.artworkUri }] : []
|
|
99
|
+
});
|
|
100
|
+
install(session);
|
|
101
|
+
sync();
|
|
102
|
+
}
|
|
103
|
+
function releaseNowPlaying(key) {
|
|
104
|
+
if (pendingKey === key) {
|
|
105
|
+
claim++;
|
|
106
|
+
pendingKey = void 0;
|
|
107
|
+
}
|
|
108
|
+
if (owner?.key !== key) return;
|
|
109
|
+
setOwner(void 0);
|
|
110
|
+
if (typeof window === "undefined" || !navigator.mediaSession) return;
|
|
111
|
+
const session = navigator.mediaSession;
|
|
112
|
+
if (installed) for (const action of [
|
|
113
|
+
"play",
|
|
114
|
+
"pause",
|
|
115
|
+
"seekto"
|
|
116
|
+
]) session.setActionHandler(action, null);
|
|
117
|
+
installed = false;
|
|
118
|
+
session.metadata = null;
|
|
119
|
+
session.playbackState = "none";
|
|
120
|
+
}
|
|
121
|
+
function addRemoteListener(onEvent) {
|
|
122
|
+
listeners.add(onEvent);
|
|
123
|
+
return () => {
|
|
124
|
+
listeners.delete(onEvent);
|
|
125
|
+
};
|
|
126
|
+
}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: true
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
16
|
+
get: () => from[key],
|
|
17
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
23
|
+
var nowPlaying_exports = {};
|
|
24
|
+
__export(nowPlaying_exports, {
|
|
25
|
+
addRemoteListener: () => addRemoteListener,
|
|
26
|
+
claimNowPlaying: () => claimNowPlaying,
|
|
27
|
+
releaseNowPlaying: () => releaseNowPlaying
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(nowPlaying_exports);
|
|
30
|
+
var listeners = /* @__PURE__ */ new Set();
|
|
31
|
+
var syncEvents = [
|
|
32
|
+
"play",
|
|
33
|
+
"pause",
|
|
34
|
+
"ended"
|
|
35
|
+
];
|
|
36
|
+
var owner;
|
|
37
|
+
var claim = 0;
|
|
38
|
+
var pendingKey;
|
|
39
|
+
var installed = false;
|
|
40
|
+
function sync() {
|
|
41
|
+
var _navigator_mediaSession;
|
|
42
|
+
if (!owner || !((_navigator_mediaSession = navigator.mediaSession) === null || _navigator_mediaSession === void 0 ? void 0 : _navigator_mediaSession.metadata)) return;
|
|
43
|
+
navigator.mediaSession.playbackState = owner.element.paused || owner.element.ended ? "paused" : "playing";
|
|
44
|
+
}
|
|
45
|
+
function setOwner(next) {
|
|
46
|
+
if ((owner === null || owner === void 0 ? void 0 : owner.element) !== (next === null || next === void 0 ? void 0 : next.element)) {
|
|
47
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
|
|
48
|
+
try {
|
|
49
|
+
for (var _iterator = syncEvents[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
50
|
+
var event = _step.value;
|
|
51
|
+
owner === null || owner === void 0 ? void 0 : owner.element.removeEventListener(event, sync);
|
|
52
|
+
next === null || next === void 0 ? void 0 : next.element.addEventListener(event, sync);
|
|
53
|
+
}
|
|
54
|
+
} catch (err) {
|
|
55
|
+
_didIteratorError = true;
|
|
56
|
+
_iteratorError = err;
|
|
57
|
+
} finally {
|
|
58
|
+
try {
|
|
59
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
60
|
+
_iterator.return();
|
|
61
|
+
}
|
|
62
|
+
} finally {
|
|
63
|
+
if (_didIteratorError) {
|
|
64
|
+
throw _iteratorError;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
owner = next;
|
|
70
|
+
}
|
|
71
|
+
async function remote(event) {
|
|
72
|
+
var _navigator_mediaSession;
|
|
73
|
+
var current = owner;
|
|
74
|
+
if (!current || !((_navigator_mediaSession = navigator.mediaSession) === null || _navigator_mediaSession === void 0 ? void 0 : _navigator_mediaSession.metadata)) return;
|
|
75
|
+
try {
|
|
76
|
+
if (event.type === "play") await current.play();
|
|
77
|
+
else if (event.type === "pause") await current.pause();
|
|
78
|
+
else await current.seek(event.positionMs);
|
|
79
|
+
} catch (unused) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
if (owner !== current) return;
|
|
83
|
+
sync();
|
|
84
|
+
var emitted = current.key === "global" ? event : {
|
|
85
|
+
...event,
|
|
86
|
+
playerId: current.key
|
|
87
|
+
};
|
|
88
|
+
for (var _i = 0, _iter = [...listeners]; _i < _iter.length; _i++) {
|
|
89
|
+
var listener = _iter[_i];
|
|
90
|
+
listener(emitted);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
function install(session) {
|
|
94
|
+
if (installed) return;
|
|
95
|
+
session.setActionHandler("play", function() {
|
|
96
|
+
return remote({ type: "play" });
|
|
97
|
+
});
|
|
98
|
+
session.setActionHandler("pause", function() {
|
|
99
|
+
return remote({ type: "pause" });
|
|
100
|
+
});
|
|
101
|
+
session.setActionHandler("seekto", function(event) {
|
|
102
|
+
var _event_seekTime;
|
|
103
|
+
return remote({
|
|
104
|
+
type: "seek",
|
|
105
|
+
positionMs: ((_event_seekTime = event.seekTime) !== null && _event_seekTime !== void 0 ? _event_seekTime : 0) * 1e3
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
installed = true;
|
|
109
|
+
}
|
|
110
|
+
async function claimNowPlaying(next, info, verb, alive) {
|
|
111
|
+
if (!info.title.trim()) throw new Error(`${verb}: title must not be empty`);
|
|
112
|
+
if (!navigator.mediaSession) throw new Error("Audio: Media Session is unavailable");
|
|
113
|
+
var ticket = ++claim;
|
|
114
|
+
pendingKey = next.key;
|
|
115
|
+
if (info.artworkUri) {
|
|
116
|
+
var artwork = new window.Image();
|
|
117
|
+
artwork.src = info.artworkUri;
|
|
118
|
+
await artwork.decode();
|
|
119
|
+
if (!alive()) throw new Error(`${verb}: playback was replaced`);
|
|
120
|
+
if (ticket !== claim) throw new Error(`${verb}: now playing was claimed or cleared again`);
|
|
121
|
+
}
|
|
122
|
+
if (pendingKey === next.key) pendingKey = void 0;
|
|
123
|
+
var session = navigator.mediaSession;
|
|
124
|
+
setOwner(next);
|
|
125
|
+
session.metadata = new MediaMetadata({
|
|
126
|
+
title: info.title,
|
|
127
|
+
artist: info.artist,
|
|
128
|
+
album: info.albumTitle,
|
|
129
|
+
artwork: info.artworkUri ? [{ src: info.artworkUri }] : []
|
|
130
|
+
});
|
|
131
|
+
install(session);
|
|
132
|
+
sync();
|
|
133
|
+
}
|
|
134
|
+
function releaseNowPlaying(key) {
|
|
135
|
+
if (pendingKey === key) {
|
|
136
|
+
claim++;
|
|
137
|
+
pendingKey = void 0;
|
|
138
|
+
}
|
|
139
|
+
if ((owner === null || owner === void 0 ? void 0 : owner.key) !== key) return;
|
|
140
|
+
setOwner(void 0);
|
|
141
|
+
if (typeof window === "undefined" || !navigator.mediaSession) return;
|
|
142
|
+
var session = navigator.mediaSession;
|
|
143
|
+
if (installed) for (var _i = 0, _iter = [
|
|
144
|
+
"play",
|
|
145
|
+
"pause",
|
|
146
|
+
"seekto"
|
|
147
|
+
]; _i < _iter.length; _i++) {
|
|
148
|
+
var action = _iter[_i];
|
|
149
|
+
session.setActionHandler(action, null);
|
|
150
|
+
}
|
|
151
|
+
installed = false;
|
|
152
|
+
session.metadata = null;
|
|
153
|
+
session.playbackState = "none";
|
|
154
|
+
}
|
|
155
|
+
function addRemoteListener(onEvent) {
|
|
156
|
+
listeners.add(onEvent);
|
|
157
|
+
return function() {
|
|
158
|
+
listeners.delete(onEvent);
|
|
159
|
+
};
|
|
160
|
+
}
|