@scalemule/nextjs 0.1.48 → 0.1.49
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/README.md +4 -0
- package/dist/audio.css +229 -0
- package/dist/audio.d.mts +130 -2
- package/dist/audio.d.ts +130 -2
- package/dist/audio.js +782 -2
- package/dist/audio.mjs +784 -1
- package/docs/network-audio.md +218 -0
- package/package.json +2 -1
package/dist/audio.js
CHANGED
|
@@ -22,12 +22,18 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
22
22
|
// src/audio.ts
|
|
23
23
|
var audio_exports = {};
|
|
24
24
|
__export(audio_exports, {
|
|
25
|
+
ArticleAudioControls: () => ArticleAudioControls,
|
|
25
26
|
AudioPlayer: () => AudioPlayer,
|
|
26
27
|
NarrationHighlighter: () => NarrationHighlighter,
|
|
28
|
+
NetworkAudioController: () => NetworkAudioController,
|
|
29
|
+
NetworkAudioPlayer: () => NetworkAudioPlayer,
|
|
30
|
+
NetworkAudioProvider: () => NetworkAudioProvider,
|
|
27
31
|
SENTENCE_HIGHLIGHT: () => SENTENCE_HIGHLIGHT,
|
|
28
32
|
WORD_HIGHLIGHT: () => WORD_HIGHLIGHT,
|
|
29
33
|
narrationHighlightSupported: () => narrationHighlightSupported,
|
|
30
|
-
parseTimingsPayload: () => parseTimingsPayload
|
|
34
|
+
parseTimingsPayload: () => parseTimingsPayload,
|
|
35
|
+
useArticleNarration: () => useArticleNarration,
|
|
36
|
+
useNetworkAudio: () => useNetworkAudio
|
|
31
37
|
});
|
|
32
38
|
module.exports = __toCommonJS(audio_exports);
|
|
33
39
|
|
|
@@ -795,12 +801,786 @@ function PlayerSession({
|
|
|
795
801
|
}
|
|
796
802
|
);
|
|
797
803
|
}
|
|
804
|
+
|
|
805
|
+
// src/components/network-audio-player.tsx
|
|
806
|
+
var import_react2 = require("react");
|
|
807
|
+
|
|
808
|
+
// src/network-audio/controller.ts
|
|
809
|
+
var EMPTY_SNAPSHOT = {
|
|
810
|
+
queue: [],
|
|
811
|
+
index: -1,
|
|
812
|
+
position: 0,
|
|
813
|
+
duration: 0,
|
|
814
|
+
rate: 1,
|
|
815
|
+
volume: 1,
|
|
816
|
+
status: "idle",
|
|
817
|
+
error: null
|
|
818
|
+
};
|
|
819
|
+
var trackKey = (track) => JSON.stringify([track.publicationId, track.id]);
|
|
820
|
+
var finite = (n) => typeof n === "number" && Number.isFinite(n);
|
|
821
|
+
function safeHttpUrl(value) {
|
|
822
|
+
if (typeof value !== "string" || value.length > 4096) return false;
|
|
823
|
+
try {
|
|
824
|
+
const url = new URL(value);
|
|
825
|
+
return (url.protocol === "https:" || url.protocol === "http:") && !url.username && !url.password;
|
|
826
|
+
} catch {
|
|
827
|
+
return false;
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
function validTrack(value) {
|
|
831
|
+
if (!value || typeof value !== "object") return false;
|
|
832
|
+
const t = value;
|
|
833
|
+
return [t.id, t.publicationId, t.title].every((v) => typeof v === "string" && v.length > 0 && v.length <= 1e3) && (t.publicationName === void 0 || typeof t.publicationName === "string" && t.publicationName.length <= 1e3) && safeHttpUrl(t.articleUrl);
|
|
834
|
+
}
|
|
835
|
+
var copyTrack = (t) => ({
|
|
836
|
+
id: t.id,
|
|
837
|
+
publicationId: t.publicationId,
|
|
838
|
+
title: t.title,
|
|
839
|
+
...t.publicationName ? { publicationName: t.publicationName } : {},
|
|
840
|
+
articleUrl: t.articleUrl
|
|
841
|
+
});
|
|
842
|
+
function validSnapshot(value) {
|
|
843
|
+
if (!value || typeof value !== "object") return false;
|
|
844
|
+
const s = value;
|
|
845
|
+
return Array.isArray(s.queue) && s.queue.length <= 100 && s.queue.every(validTrack) && new Set(s.queue.map(trackKey)).size === s.queue.length && Number.isInteger(s.index) && (s.queue.length ? s.index >= 0 && s.index < s.queue.length : s.index === -1) && finite(s.position) && s.position >= 0 && finite(s.duration) && s.duration >= 0 && finite(s.rate) && s.rate >= 0.5 && s.rate <= 3 && finite(s.volume) && s.volume >= 0 && s.volume <= 1 && ["idle", "loading", "playing", "paused", "error"].includes(s.status) && (s.error === null || typeof s.error === "string" && s.error.length <= 1e3);
|
|
846
|
+
}
|
|
847
|
+
var NetworkAudioController = class {
|
|
848
|
+
constructor(resolve) {
|
|
849
|
+
this.resolve = resolve;
|
|
850
|
+
this.snapshot = EMPTY_SNAPSHOT;
|
|
851
|
+
this.listeners = /* @__PURE__ */ new Set();
|
|
852
|
+
this.audio = null;
|
|
853
|
+
this.cleanup = null;
|
|
854
|
+
this.request = null;
|
|
855
|
+
this.generation = 0;
|
|
856
|
+
this.intent = false;
|
|
857
|
+
this.source = null;
|
|
858
|
+
this.refreshed = false;
|
|
859
|
+
this.resumePosition = null;
|
|
860
|
+
this.getSnapshot = () => this.snapshot;
|
|
861
|
+
this.subscribe = (listener) => {
|
|
862
|
+
this.listeners.add(listener);
|
|
863
|
+
return () => {
|
|
864
|
+
this.listeners.delete(listener);
|
|
865
|
+
};
|
|
866
|
+
};
|
|
867
|
+
}
|
|
868
|
+
setResolver(resolve) {
|
|
869
|
+
this.resolve = resolve;
|
|
870
|
+
}
|
|
871
|
+
patch(patch) {
|
|
872
|
+
this.snapshot = { ...this.snapshot, ...patch };
|
|
873
|
+
this.listeners.forEach((listener) => listener());
|
|
874
|
+
}
|
|
875
|
+
attach(audio) {
|
|
876
|
+
this.detach();
|
|
877
|
+
this.audio = audio;
|
|
878
|
+
audio.preload = "metadata";
|
|
879
|
+
audio.playbackRate = this.snapshot.rate;
|
|
880
|
+
audio.volume = this.snapshot.volume;
|
|
881
|
+
const on = (name, fn) => {
|
|
882
|
+
audio.addEventListener(name, fn);
|
|
883
|
+
return () => audio.removeEventListener(name, fn);
|
|
884
|
+
};
|
|
885
|
+
const off = [
|
|
886
|
+
on("loadedmetadata", () => {
|
|
887
|
+
const duration = finite(audio.duration) && audio.duration > 0 ? audio.duration : this.snapshot.duration;
|
|
888
|
+
if (this.resumePosition !== null) {
|
|
889
|
+
audio.currentTime = duration > 0 ? Math.min(this.resumePosition, duration) : this.resumePosition;
|
|
890
|
+
this.resumePosition = null;
|
|
891
|
+
}
|
|
892
|
+
audio.playbackRate = this.snapshot.rate;
|
|
893
|
+
this.patch({ duration, position: audio.currentTime });
|
|
894
|
+
}),
|
|
895
|
+
on("durationchange", () => {
|
|
896
|
+
if (finite(audio.duration) && audio.duration > 0) this.patch({ duration: audio.duration });
|
|
897
|
+
}),
|
|
898
|
+
on("timeupdate", () => {
|
|
899
|
+
if (this.resumePosition === null) this.patch({ position: audio.currentTime });
|
|
900
|
+
}),
|
|
901
|
+
on("playing", () => {
|
|
902
|
+
if (!this.intent) {
|
|
903
|
+
audio.pause();
|
|
904
|
+
return;
|
|
905
|
+
}
|
|
906
|
+
this.patch({ status: "playing", error: null });
|
|
907
|
+
document.dispatchEvent(new CustomEvent("scalemule:audio:play", { detail: audio }));
|
|
908
|
+
}),
|
|
909
|
+
on("pause", () => {
|
|
910
|
+
if (this.snapshot.status === "playing") this.patch({ status: "paused" });
|
|
911
|
+
}),
|
|
912
|
+
on("ended", () => {
|
|
913
|
+
if (!this.intent) return;
|
|
914
|
+
if (this.snapshot.index + 1 < this.snapshot.queue.length) this.select(this.snapshot.index + 1);
|
|
915
|
+
else {
|
|
916
|
+
this.intent = false;
|
|
917
|
+
this.patch({ status: "paused", position: this.snapshot.duration });
|
|
918
|
+
}
|
|
919
|
+
}),
|
|
920
|
+
on("error", () => {
|
|
921
|
+
if (this.intent && !this.request) void this.recover();
|
|
922
|
+
})
|
|
923
|
+
];
|
|
924
|
+
const exclusive = (event) => {
|
|
925
|
+
if (event.detail !== audio) this.pause();
|
|
926
|
+
};
|
|
927
|
+
document.addEventListener("scalemule:audio:play", exclusive);
|
|
928
|
+
this.cleanup = () => {
|
|
929
|
+
off.forEach((fn) => fn());
|
|
930
|
+
document.removeEventListener("scalemule:audio:play", exclusive);
|
|
931
|
+
};
|
|
932
|
+
}
|
|
933
|
+
detach() {
|
|
934
|
+
this.generation++;
|
|
935
|
+
this.intent = false;
|
|
936
|
+
this.request?.abort();
|
|
937
|
+
this.request = null;
|
|
938
|
+
this.cleanup?.();
|
|
939
|
+
this.cleanup = null;
|
|
940
|
+
this.audio?.pause();
|
|
941
|
+
this.audio?.removeAttribute("src");
|
|
942
|
+
this.audio = null;
|
|
943
|
+
this.source = null;
|
|
944
|
+
}
|
|
945
|
+
enqueue(track) {
|
|
946
|
+
if (!validTrack(track)) throw new Error("A valid publication, article identity, title and HTTP(S) article URL are required.");
|
|
947
|
+
const found = this.snapshot.queue.findIndex((t) => trackKey(t) === trackKey(track));
|
|
948
|
+
if (found !== -1) return found;
|
|
949
|
+
if (this.snapshot.queue.length >= 100) throw new Error("The listening queue holds up to 100 articles.");
|
|
950
|
+
const queue = [...this.snapshot.queue, copyTrack(track)];
|
|
951
|
+
this.patch({ queue, index: this.snapshot.index === -1 ? 0 : this.snapshot.index });
|
|
952
|
+
return queue.length - 1;
|
|
953
|
+
}
|
|
954
|
+
playTrack(track) {
|
|
955
|
+
const index = this.enqueue(track);
|
|
956
|
+
if (index === this.snapshot.index) void this.play();
|
|
957
|
+
else this.select(index);
|
|
958
|
+
}
|
|
959
|
+
select(index) {
|
|
960
|
+
if (!Number.isInteger(index) || index < 0 || index >= this.snapshot.queue.length) return;
|
|
961
|
+
if (index === this.snapshot.index) {
|
|
962
|
+
void this.play();
|
|
963
|
+
return;
|
|
964
|
+
}
|
|
965
|
+
this.cancel();
|
|
966
|
+
this.source = null;
|
|
967
|
+
this.patch({ index, position: 0, duration: 0, error: null, status: "paused" });
|
|
968
|
+
void this.play();
|
|
969
|
+
}
|
|
970
|
+
remove(index) {
|
|
971
|
+
if (!Number.isInteger(index) || index < 0 || index >= this.snapshot.queue.length) return;
|
|
972
|
+
const wasPlaying = this.intent;
|
|
973
|
+
const current = this.snapshot.index;
|
|
974
|
+
const queue = this.snapshot.queue.filter((_, i) => i !== index);
|
|
975
|
+
if (index !== current) {
|
|
976
|
+
this.patch({ queue, index: index < current ? current - 1 : current });
|
|
977
|
+
return;
|
|
978
|
+
}
|
|
979
|
+
this.cancel();
|
|
980
|
+
this.source = null;
|
|
981
|
+
this.patch({ queue, index: queue.length ? Math.min(index, queue.length - 1) : -1, position: 0, duration: 0, status: "paused", error: null });
|
|
982
|
+
if (wasPlaying && queue.length) void this.play();
|
|
983
|
+
}
|
|
984
|
+
cancel() {
|
|
985
|
+
this.intent = false;
|
|
986
|
+
this.generation++;
|
|
987
|
+
this.request?.abort();
|
|
988
|
+
this.request = null;
|
|
989
|
+
this.resumePosition = null;
|
|
990
|
+
this.audio?.pause();
|
|
991
|
+
}
|
|
992
|
+
pause() {
|
|
993
|
+
const pendingPosition = this.resumePosition;
|
|
994
|
+
this.cancel();
|
|
995
|
+
this.resumePosition = pendingPosition;
|
|
996
|
+
this.patch({ status: this.snapshot.queue.length ? "paused" : "idle" });
|
|
997
|
+
}
|
|
998
|
+
clear() {
|
|
999
|
+
this.cancel();
|
|
1000
|
+
this.source = null;
|
|
1001
|
+
this.audio?.removeAttribute("src");
|
|
1002
|
+
this.patch({ ...EMPTY_SNAPSHOT, rate: this.snapshot.rate, volume: this.snapshot.volume });
|
|
1003
|
+
}
|
|
1004
|
+
seek(position) {
|
|
1005
|
+
if (!finite(position)) return;
|
|
1006
|
+
const value = Math.max(0, this.snapshot.duration ? Math.min(position, this.snapshot.duration) : position);
|
|
1007
|
+
if (this.audio?.readyState && this.source) this.audio.currentTime = value;
|
|
1008
|
+
else this.resumePosition = value;
|
|
1009
|
+
this.patch({ position: value });
|
|
1010
|
+
}
|
|
1011
|
+
setRate(rate) {
|
|
1012
|
+
if (!finite(rate) || rate < 0.5 || rate > 3) return;
|
|
1013
|
+
if (this.audio) this.audio.playbackRate = rate;
|
|
1014
|
+
this.patch({ rate });
|
|
1015
|
+
}
|
|
1016
|
+
setVolume(volume) {
|
|
1017
|
+
if (!finite(volume) || volume < 0 || volume > 1) return;
|
|
1018
|
+
if (this.audio) this.audio.volume = volume;
|
|
1019
|
+
this.patch({ volume });
|
|
1020
|
+
}
|
|
1021
|
+
restore(snapshot) {
|
|
1022
|
+
if (!validSnapshot(snapshot)) return;
|
|
1023
|
+
this.cancel();
|
|
1024
|
+
this.source = null;
|
|
1025
|
+
this.patch({
|
|
1026
|
+
queue: snapshot.queue.map(copyTrack),
|
|
1027
|
+
index: snapshot.index,
|
|
1028
|
+
position: snapshot.position,
|
|
1029
|
+
duration: snapshot.duration,
|
|
1030
|
+
rate: snapshot.rate,
|
|
1031
|
+
volume: snapshot.volume,
|
|
1032
|
+
status: snapshot.queue.length ? "paused" : "idle",
|
|
1033
|
+
error: null
|
|
1034
|
+
});
|
|
1035
|
+
if (this.audio) {
|
|
1036
|
+
this.audio.playbackRate = snapshot.rate;
|
|
1037
|
+
this.audio.volume = snapshot.volume;
|
|
1038
|
+
}
|
|
1039
|
+
}
|
|
1040
|
+
async play() {
|
|
1041
|
+
if (!this.audio || !this.snapshot.queue[this.snapshot.index] || this.request) return;
|
|
1042
|
+
this.intent = true;
|
|
1043
|
+
this.refreshed = false;
|
|
1044
|
+
this.patch({ error: null });
|
|
1045
|
+
const expires = this.source?.expires_at ? Date.parse(this.source.expires_at) : Infinity;
|
|
1046
|
+
if (!this.source || expires <= Date.now() + 3e4) await this.load();
|
|
1047
|
+
else {
|
|
1048
|
+
if (this.snapshot.duration && this.snapshot.position >= this.snapshot.duration) this.seek(0);
|
|
1049
|
+
await this.start(this.generation);
|
|
1050
|
+
}
|
|
1051
|
+
}
|
|
1052
|
+
async load() {
|
|
1053
|
+
const track = this.snapshot.queue[this.snapshot.index];
|
|
1054
|
+
if (!track || !this.audio) return;
|
|
1055
|
+
const generation = ++this.generation;
|
|
1056
|
+
const request = new AbortController();
|
|
1057
|
+
this.request?.abort();
|
|
1058
|
+
this.request = request;
|
|
1059
|
+
this.patch({ status: "loading", error: null });
|
|
1060
|
+
let timeout;
|
|
1061
|
+
try {
|
|
1062
|
+
const source = await Promise.race([
|
|
1063
|
+
this.resolve(track, request.signal),
|
|
1064
|
+
new Promise((_, reject) => {
|
|
1065
|
+
timeout = setTimeout(() => {
|
|
1066
|
+
request.abort();
|
|
1067
|
+
reject(new Error("Audio request timed out"));
|
|
1068
|
+
}, 15e3);
|
|
1069
|
+
})
|
|
1070
|
+
]);
|
|
1071
|
+
if (generation !== this.generation || request.signal.aborted || !this.audio) return;
|
|
1072
|
+
if (!safeHttpUrl(source.url)) throw new Error("No playable audio source");
|
|
1073
|
+
this.source = source;
|
|
1074
|
+
this.resumePosition = this.snapshot.position;
|
|
1075
|
+
this.audio.src = source.url;
|
|
1076
|
+
this.audio.playbackRate = this.snapshot.rate;
|
|
1077
|
+
this.audio.volume = this.snapshot.volume;
|
|
1078
|
+
this.patch({ duration: source.duration_ms && source.duration_ms > 0 ? source.duration_ms / 1e3 : 0 });
|
|
1079
|
+
this.request = null;
|
|
1080
|
+
await this.start(generation);
|
|
1081
|
+
} catch {
|
|
1082
|
+
if (generation === this.generation) this.fail("This article could not be loaded. Try playing it again or choose another article.");
|
|
1083
|
+
} finally {
|
|
1084
|
+
clearTimeout(timeout);
|
|
1085
|
+
if (this.request === request) this.request = null;
|
|
1086
|
+
}
|
|
1087
|
+
}
|
|
1088
|
+
async start(generation) {
|
|
1089
|
+
if (!this.intent || !this.audio) return;
|
|
1090
|
+
try {
|
|
1091
|
+
await this.audio.play();
|
|
1092
|
+
} catch (error) {
|
|
1093
|
+
if (generation !== this.generation || !this.intent) return;
|
|
1094
|
+
if (error.name === "NotAllowedError") this.fail("Press Play here to continue listening.");
|
|
1095
|
+
else await this.recover();
|
|
1096
|
+
}
|
|
1097
|
+
}
|
|
1098
|
+
async recover() {
|
|
1099
|
+
if (this.refreshed) {
|
|
1100
|
+
this.fail("Audio playback stopped. Try playing again or choose another article.");
|
|
1101
|
+
return;
|
|
1102
|
+
}
|
|
1103
|
+
this.refreshed = true;
|
|
1104
|
+
await this.load();
|
|
1105
|
+
}
|
|
1106
|
+
fail(error) {
|
|
1107
|
+
this.intent = false;
|
|
1108
|
+
this.audio?.pause();
|
|
1109
|
+
this.patch({ status: "error", error });
|
|
1110
|
+
}
|
|
1111
|
+
};
|
|
1112
|
+
|
|
1113
|
+
// src/network-audio/bridge.ts
|
|
1114
|
+
var PROTOCOL = "scalemule:network-audio:v1";
|
|
1115
|
+
function runCommand(controller, command) {
|
|
1116
|
+
if (!command || typeof command !== "object") return false;
|
|
1117
|
+
const c = command;
|
|
1118
|
+
switch (c.action) {
|
|
1119
|
+
case "play":
|
|
1120
|
+
void controller.play();
|
|
1121
|
+
return true;
|
|
1122
|
+
case "pause":
|
|
1123
|
+
controller.pause();
|
|
1124
|
+
return true;
|
|
1125
|
+
case "clear":
|
|
1126
|
+
controller.clear();
|
|
1127
|
+
return true;
|
|
1128
|
+
case "enqueue":
|
|
1129
|
+
case "playTrack":
|
|
1130
|
+
if (!validTrack(c.track)) return false;
|
|
1131
|
+
controller[c.action](c.track);
|
|
1132
|
+
return true;
|
|
1133
|
+
case "select":
|
|
1134
|
+
case "remove":
|
|
1135
|
+
case "seek":
|
|
1136
|
+
case "rate":
|
|
1137
|
+
case "volume":
|
|
1138
|
+
if (!Number.isFinite(c.value)) return false;
|
|
1139
|
+
if (c.action === "rate") controller.setRate(c.value);
|
|
1140
|
+
else if (c.action === "volume") controller.setVolume(c.value);
|
|
1141
|
+
else controller[c.action](c.value);
|
|
1142
|
+
return true;
|
|
1143
|
+
default:
|
|
1144
|
+
return false;
|
|
1145
|
+
}
|
|
1146
|
+
}
|
|
1147
|
+
function hostNetworkPlayer(controller, options) {
|
|
1148
|
+
const origins = new Set(options.allowedOrigins.map((value) => {
|
|
1149
|
+
if (!safeHttpUrl(value) || new URL(value).origin !== value) throw new Error("Use exact HTTP(S) origins for the network player.");
|
|
1150
|
+
return value;
|
|
1151
|
+
}));
|
|
1152
|
+
const reader = window.opener;
|
|
1153
|
+
if (!reader) return () => {
|
|
1154
|
+
};
|
|
1155
|
+
const trackAllowed = (t) => origins.has(new URL(t.articleUrl).origin);
|
|
1156
|
+
const send = () => {
|
|
1157
|
+
if (reader.closed) return;
|
|
1158
|
+
const data = { protocol: PROTOCOL, networkId: options.networkId, kind: "state", snapshot: controller.getSnapshot() };
|
|
1159
|
+
origins.forEach((origin) => reader.postMessage(data, origin));
|
|
1160
|
+
};
|
|
1161
|
+
const receive = (event) => {
|
|
1162
|
+
if (event.source !== reader || !origins.has(event.origin)) return;
|
|
1163
|
+
const data = event.data;
|
|
1164
|
+
if (!data || data.protocol !== PROTOCOL || data.networkId !== options.networkId) return;
|
|
1165
|
+
try {
|
|
1166
|
+
if (data.kind === "adopt" && validSnapshot(data.snapshot) && data.snapshot.queue.every(trackAllowed) && !controller.getSnapshot().queue.length) {
|
|
1167
|
+
controller.restore(data.snapshot);
|
|
1168
|
+
if (data.play === true) void controller.play();
|
|
1169
|
+
} else if (data.kind === "command") {
|
|
1170
|
+
const command = data.command;
|
|
1171
|
+
if (command && (command.action === "enqueue" || command.action === "playTrack") && (!validTrack(command.track) || !trackAllowed(command.track))) return;
|
|
1172
|
+
runCommand(controller, command);
|
|
1173
|
+
}
|
|
1174
|
+
} catch {
|
|
1175
|
+
reader.postMessage({
|
|
1176
|
+
protocol: PROTOCOL,
|
|
1177
|
+
networkId: options.networkId,
|
|
1178
|
+
kind: "error",
|
|
1179
|
+
error: "The article could not be added. The queue holds up to 100 articles."
|
|
1180
|
+
}, event.origin);
|
|
1181
|
+
}
|
|
1182
|
+
send();
|
|
1183
|
+
};
|
|
1184
|
+
window.addEventListener("message", receive);
|
|
1185
|
+
const timer = window.setInterval(send, 250);
|
|
1186
|
+
send();
|
|
1187
|
+
return () => {
|
|
1188
|
+
clearInterval(timer);
|
|
1189
|
+
window.removeEventListener("message", receive);
|
|
1190
|
+
};
|
|
1191
|
+
}
|
|
1192
|
+
var NetworkPlayerClient = class {
|
|
1193
|
+
constructor(controller, options, update) {
|
|
1194
|
+
this.controller = controller;
|
|
1195
|
+
this.options = options;
|
|
1196
|
+
this.update = update;
|
|
1197
|
+
this.target = null;
|
|
1198
|
+
this.connected = false;
|
|
1199
|
+
this.pending = false;
|
|
1200
|
+
this.openedAt = 0;
|
|
1201
|
+
this.lastSeen = 0;
|
|
1202
|
+
this.latest = null;
|
|
1203
|
+
this.receive = (event) => {
|
|
1204
|
+
if (event.origin !== this.origin || !event.source || this.target && event.source !== this.target) return;
|
|
1205
|
+
const data = event.data;
|
|
1206
|
+
if (!data || data.protocol !== PROTOCOL || data.networkId !== this.options.networkId) return;
|
|
1207
|
+
if (data.kind === "error" && this.connected) {
|
|
1208
|
+
this.update(this.latest, "The article could not be added. The queue holds up to 100 articles.");
|
|
1209
|
+
return;
|
|
1210
|
+
}
|
|
1211
|
+
if (data.kind !== "state" || !validSnapshot(data.snapshot)) return;
|
|
1212
|
+
this.target = event.source;
|
|
1213
|
+
this.lastSeen = Date.now();
|
|
1214
|
+
if (!this.connected) {
|
|
1215
|
+
const local = this.controller.getSnapshot();
|
|
1216
|
+
const handoff = this.pending && !data.snapshot.queue.length && local.queue.length > 0;
|
|
1217
|
+
this.controller.pause();
|
|
1218
|
+
this.connected = true;
|
|
1219
|
+
this.pending = false;
|
|
1220
|
+
if (handoff) this.post({ kind: "adopt", snapshot: local, play: local.status === "playing" || local.status === "loading" });
|
|
1221
|
+
}
|
|
1222
|
+
this.latest = data.snapshot;
|
|
1223
|
+
this.update(data.snapshot, null);
|
|
1224
|
+
};
|
|
1225
|
+
if (!safeHttpUrl(options.playerUrl)) throw new Error("The network player needs a fully qualified HTTP(S) URL.");
|
|
1226
|
+
this.origin = new URL(options.playerUrl).origin;
|
|
1227
|
+
window.addEventListener("message", this.receive);
|
|
1228
|
+
this.timer = window.setInterval(() => {
|
|
1229
|
+
if (this.pending && Date.now() - this.openedAt > 1e4) {
|
|
1230
|
+
this.pending = false;
|
|
1231
|
+
this.update(null, "The network player did not connect. Playback is still on this page.");
|
|
1232
|
+
}
|
|
1233
|
+
if (this.connected && this.target?.closed) this.disconnect("The network player closed. Press Play to resume here.");
|
|
1234
|
+
else if (this.connected && Date.now() - this.lastSeen > 5e3) {
|
|
1235
|
+
this.update(this.latest, "Waiting for the network player. Open its window to check playback.");
|
|
1236
|
+
}
|
|
1237
|
+
}, 1e3);
|
|
1238
|
+
}
|
|
1239
|
+
post(data) {
|
|
1240
|
+
this.target?.postMessage({ protocol: PROTOCOL, networkId: this.options.networkId, ...data }, this.origin);
|
|
1241
|
+
}
|
|
1242
|
+
open() {
|
|
1243
|
+
if (this.target && !this.target.closed) {
|
|
1244
|
+
this.target.focus();
|
|
1245
|
+
return;
|
|
1246
|
+
}
|
|
1247
|
+
this.target = window.open(this.options.playerUrl, "_blank", "popup,width=520,height=720");
|
|
1248
|
+
if (!this.target || this.target.closed) {
|
|
1249
|
+
this.target = null;
|
|
1250
|
+
this.update(null, "Allow the network player window to open, then try again. Playback is still on this page.");
|
|
1251
|
+
return;
|
|
1252
|
+
}
|
|
1253
|
+
this.pending = true;
|
|
1254
|
+
this.openedAt = Date.now();
|
|
1255
|
+
}
|
|
1256
|
+
command(command) {
|
|
1257
|
+
if (this.connected && this.target?.closed) this.disconnect("The network player closed. Press Play to resume here.");
|
|
1258
|
+
if (!this.connected || !this.target || this.target.closed) return false;
|
|
1259
|
+
this.post({ kind: "command", command });
|
|
1260
|
+
return true;
|
|
1261
|
+
}
|
|
1262
|
+
disconnect(notice) {
|
|
1263
|
+
if (this.latest) this.controller.restore(this.latest);
|
|
1264
|
+
this.connected = false;
|
|
1265
|
+
this.target = null;
|
|
1266
|
+
this.latest = null;
|
|
1267
|
+
this.update(null, notice);
|
|
1268
|
+
}
|
|
1269
|
+
dispose() {
|
|
1270
|
+
clearInterval(this.timer);
|
|
1271
|
+
window.removeEventListener("message", this.receive);
|
|
1272
|
+
}
|
|
1273
|
+
};
|
|
1274
|
+
|
|
1275
|
+
// src/components/network-audio-player.tsx
|
|
1276
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
1277
|
+
var Context = (0, import_react2.createContext)(null);
|
|
1278
|
+
var serverSnapshot = () => EMPTY_SNAPSHOT;
|
|
1279
|
+
function NetworkAudioProvider({ children, resolveAudio, connection, host, checkpointStorageKey }) {
|
|
1280
|
+
if (connection && host) throw new Error("Use connection on reader pages and host on the dedicated player route, not both.");
|
|
1281
|
+
const [controller] = (0, import_react2.useState)(() => new NetworkAudioController(resolveAudio));
|
|
1282
|
+
const snapshot = (0, import_react2.useSyncExternalStore)(controller.subscribe, controller.getSnapshot, serverSnapshot);
|
|
1283
|
+
const [remoteSnapshot, setRemoteSnapshot] = (0, import_react2.useState)(null);
|
|
1284
|
+
const [notice, setNotice] = (0, import_react2.useState)(null);
|
|
1285
|
+
const [highlightEnabled, setHighlightEnabled] = (0, import_react2.useState)(false);
|
|
1286
|
+
const client = (0, import_react2.useRef)(null);
|
|
1287
|
+
(0, import_react2.useEffect)(() => {
|
|
1288
|
+
controller.setResolver(resolveAudio);
|
|
1289
|
+
}, [controller, resolveAudio]);
|
|
1290
|
+
(0, import_react2.useEffect)(() => {
|
|
1291
|
+
const audio = document.createElement("audio");
|
|
1292
|
+
controller.attach(audio);
|
|
1293
|
+
return () => controller.detach();
|
|
1294
|
+
}, [controller]);
|
|
1295
|
+
(0, import_react2.useEffect)(() => {
|
|
1296
|
+
if (!checkpointStorageKey) return;
|
|
1297
|
+
try {
|
|
1298
|
+
const data = JSON.parse(sessionStorage.getItem(checkpointStorageKey) ?? "null");
|
|
1299
|
+
if (validSnapshot(data)) controller.restore(data);
|
|
1300
|
+
} catch {
|
|
1301
|
+
}
|
|
1302
|
+
let lastWrite = 0;
|
|
1303
|
+
const save = () => {
|
|
1304
|
+
try {
|
|
1305
|
+
sessionStorage.setItem(checkpointStorageKey, JSON.stringify(controller.getSnapshot()));
|
|
1306
|
+
} catch {
|
|
1307
|
+
}
|
|
1308
|
+
};
|
|
1309
|
+
const unsubscribe = controller.subscribe(() => {
|
|
1310
|
+
if (Date.now() - lastWrite > 1e3) {
|
|
1311
|
+
lastWrite = Date.now();
|
|
1312
|
+
save();
|
|
1313
|
+
}
|
|
1314
|
+
});
|
|
1315
|
+
window.addEventListener("pagehide", save);
|
|
1316
|
+
return () => {
|
|
1317
|
+
save();
|
|
1318
|
+
unsubscribe();
|
|
1319
|
+
window.removeEventListener("pagehide", save);
|
|
1320
|
+
};
|
|
1321
|
+
}, [controller, checkpointStorageKey]);
|
|
1322
|
+
const allowedOrigins = JSON.stringify(host?.allowedOrigins ?? []);
|
|
1323
|
+
(0, import_react2.useEffect)(() => {
|
|
1324
|
+
if (!host) return;
|
|
1325
|
+
return hostNetworkPlayer(controller, { networkId: host.networkId, allowedOrigins: JSON.parse(allowedOrigins) });
|
|
1326
|
+
}, [controller, host?.networkId, allowedOrigins]);
|
|
1327
|
+
(0, import_react2.useEffect)(() => {
|
|
1328
|
+
if (!connection) return;
|
|
1329
|
+
const instance = new NetworkPlayerClient(controller, connection, (state, message) => {
|
|
1330
|
+
setRemoteSnapshot(state);
|
|
1331
|
+
setNotice(message);
|
|
1332
|
+
});
|
|
1333
|
+
client.current = instance;
|
|
1334
|
+
return () => {
|
|
1335
|
+
instance.dispose();
|
|
1336
|
+
client.current = null;
|
|
1337
|
+
};
|
|
1338
|
+
}, [controller, connection?.playerUrl, connection?.networkId]);
|
|
1339
|
+
const command = (0, import_react2.useCallback)((value) => {
|
|
1340
|
+
setNotice(null);
|
|
1341
|
+
try {
|
|
1342
|
+
if (!client.current?.command(value)) runCommand(controller, value);
|
|
1343
|
+
} catch (error) {
|
|
1344
|
+
setNotice(error instanceof Error ? error.message : "The article could not be added.");
|
|
1345
|
+
}
|
|
1346
|
+
}, [controller]);
|
|
1347
|
+
const openNetworkPlayer = (0, import_react2.useCallback)(() => client.current?.open(), []);
|
|
1348
|
+
const activeSnapshot = remoteSnapshot ?? snapshot;
|
|
1349
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(Context.Provider, { value: {
|
|
1350
|
+
snapshot: activeSnapshot,
|
|
1351
|
+
remote: remoteSnapshot !== null,
|
|
1352
|
+
hosted: !!host,
|
|
1353
|
+
notice,
|
|
1354
|
+
command,
|
|
1355
|
+
openNetworkPlayer: connection ? openNetworkPlayer : void 0,
|
|
1356
|
+
highlightEnabled,
|
|
1357
|
+
setHighlightEnabled
|
|
1358
|
+
}, children: [
|
|
1359
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(NetworkMediaSession, {}),
|
|
1360
|
+
children
|
|
1361
|
+
] });
|
|
1362
|
+
}
|
|
1363
|
+
function useNetworkAudio() {
|
|
1364
|
+
const context = (0, import_react2.useContext)(Context);
|
|
1365
|
+
if (!context) throw new Error("Mount NetworkAudioProvider above the player and article controls.");
|
|
1366
|
+
return context;
|
|
1367
|
+
}
|
|
1368
|
+
function NetworkMediaSession() {
|
|
1369
|
+
const { snapshot, remote, command } = useNetworkAudio();
|
|
1370
|
+
const track = snapshot.queue[snapshot.index];
|
|
1371
|
+
(0, import_react2.useEffect)(() => {
|
|
1372
|
+
if (remote || !track || !("mediaSession" in navigator)) return;
|
|
1373
|
+
const mediaSession = navigator.mediaSession;
|
|
1374
|
+
if (typeof MediaMetadata !== "undefined") mediaSession.metadata = new MediaMetadata({ title: track.title, artist: track.publicationName ?? "" });
|
|
1375
|
+
const handlers = [
|
|
1376
|
+
["play", () => command({ action: "play" })],
|
|
1377
|
+
["pause", () => command({ action: "pause" })],
|
|
1378
|
+
["seekto", (details) => {
|
|
1379
|
+
if (details.seekTime != null) command({ action: "seek", value: details.seekTime });
|
|
1380
|
+
}]
|
|
1381
|
+
];
|
|
1382
|
+
handlers.forEach(([action, handler]) => {
|
|
1383
|
+
try {
|
|
1384
|
+
mediaSession.setActionHandler(action, handler);
|
|
1385
|
+
} catch {
|
|
1386
|
+
}
|
|
1387
|
+
});
|
|
1388
|
+
return () => {
|
|
1389
|
+
handlers.forEach(([action]) => {
|
|
1390
|
+
try {
|
|
1391
|
+
mediaSession.setActionHandler(action, null);
|
|
1392
|
+
} catch {
|
|
1393
|
+
}
|
|
1394
|
+
});
|
|
1395
|
+
mediaSession.metadata = null;
|
|
1396
|
+
mediaSession.playbackState = "none";
|
|
1397
|
+
};
|
|
1398
|
+
}, [remote, track, command]);
|
|
1399
|
+
(0, import_react2.useEffect)(() => {
|
|
1400
|
+
if (remote || !track || !("mediaSession" in navigator)) return;
|
|
1401
|
+
navigator.mediaSession.playbackState = snapshot.status === "playing" ? "playing" : "paused";
|
|
1402
|
+
if (snapshot.duration > 0) {
|
|
1403
|
+
try {
|
|
1404
|
+
navigator.mediaSession.setPositionState({
|
|
1405
|
+
duration: snapshot.duration,
|
|
1406
|
+
playbackRate: snapshot.rate,
|
|
1407
|
+
position: Math.min(snapshot.position, snapshot.duration)
|
|
1408
|
+
});
|
|
1409
|
+
} catch {
|
|
1410
|
+
}
|
|
1411
|
+
}
|
|
1412
|
+
}, [remote, track, snapshot.status, snapshot.position, snapshot.duration, snapshot.rate]);
|
|
1413
|
+
return null;
|
|
1414
|
+
}
|
|
1415
|
+
var subscribeCapabilities = () => () => {
|
|
1416
|
+
};
|
|
1417
|
+
function useArticleNarration(track, narration) {
|
|
1418
|
+
const { snapshot, highlightEnabled, setHighlightEnabled } = useNetworkAudio();
|
|
1419
|
+
const supported = (0, import_react2.useSyncExternalStore)(subscribeCapabilities, narrationHighlightSupported, () => false);
|
|
1420
|
+
const active = snapshot.queue[snapshot.index];
|
|
1421
|
+
const matching = !!active && trackKey(active) === trackKey(track);
|
|
1422
|
+
const clock = (0, import_react2.useRef)({ snapshot, received: 0 });
|
|
1423
|
+
(0, import_react2.useEffect)(() => {
|
|
1424
|
+
clock.current = { snapshot, received: performance.now() };
|
|
1425
|
+
}, [snapshot]);
|
|
1426
|
+
(0, import_react2.useEffect)(() => {
|
|
1427
|
+
if (!narration || !matching || !highlightEnabled || !supported) return;
|
|
1428
|
+
const controller = new AbortController();
|
|
1429
|
+
let highlighter = null;
|
|
1430
|
+
let frame = 0;
|
|
1431
|
+
const render = () => {
|
|
1432
|
+
const { snapshot: current, received } = clock.current;
|
|
1433
|
+
const elapsed = current.status === "playing" ? Math.min((performance.now() - received) / 1e3, 0.5) * current.rate : 0;
|
|
1434
|
+
highlighter?.update((current.position + elapsed) * 1e3);
|
|
1435
|
+
frame = requestAnimationFrame(render);
|
|
1436
|
+
};
|
|
1437
|
+
const visibility = () => {
|
|
1438
|
+
cancelAnimationFrame(frame);
|
|
1439
|
+
if (document.visibilityState === "hidden") highlighter?.clear();
|
|
1440
|
+
else if (highlighter) frame = requestAnimationFrame(render);
|
|
1441
|
+
};
|
|
1442
|
+
const timeout = setTimeout(() => controller.abort(), 15e3);
|
|
1443
|
+
void (async () => {
|
|
1444
|
+
try {
|
|
1445
|
+
const response = await fetch(narration.timingsUrl, { signal: controller.signal });
|
|
1446
|
+
if (!response.ok) return;
|
|
1447
|
+
const timings = parseTimingsPayload(await response.json());
|
|
1448
|
+
const target = document.getElementById(narration.targetId);
|
|
1449
|
+
if (controller.signal.aborted || !timings || !target) return;
|
|
1450
|
+
highlighter = new NarrationHighlighter(target, timings);
|
|
1451
|
+
if (highlighter.matchRatio() < 0.5) {
|
|
1452
|
+
highlighter.destroy();
|
|
1453
|
+
highlighter = null;
|
|
1454
|
+
return;
|
|
1455
|
+
}
|
|
1456
|
+
visibility();
|
|
1457
|
+
} catch {
|
|
1458
|
+
} finally {
|
|
1459
|
+
clearTimeout(timeout);
|
|
1460
|
+
}
|
|
1461
|
+
})();
|
|
1462
|
+
document.addEventListener("visibilitychange", visibility);
|
|
1463
|
+
return () => {
|
|
1464
|
+
controller.abort();
|
|
1465
|
+
clearTimeout(timeout);
|
|
1466
|
+
cancelAnimationFrame(frame);
|
|
1467
|
+
highlighter?.destroy();
|
|
1468
|
+
document.removeEventListener("visibilitychange", visibility);
|
|
1469
|
+
};
|
|
1470
|
+
}, [matching, highlightEnabled, supported, narration?.targetId, narration?.timingsUrl, track.id, track.publicationId]);
|
|
1471
|
+
return { highlightAvailable: !!narration && supported, highlightEnabled, setHighlightEnabled, matching };
|
|
1472
|
+
}
|
|
1473
|
+
function ArticleAudioControls({ track, narration, className = "" }) {
|
|
1474
|
+
const { snapshot, command } = useNetworkAudio();
|
|
1475
|
+
const { highlightAvailable, highlightEnabled, setHighlightEnabled, matching } = useArticleNarration(track, narration);
|
|
1476
|
+
const playing = matching && (snapshot.status === "playing" || snapshot.status === "loading");
|
|
1477
|
+
const queued = snapshot.queue.some((item) => trackKey(item) === trackKey(track));
|
|
1478
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: `sm-network-article ${className}`, "aria-label": "Article audio", children: [
|
|
1479
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { type: "button", onClick: () => command(playing ? { action: "pause" } : { action: "playTrack", track }), children: playing ? "Pause article" : "Listen to article" }),
|
|
1480
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { type: "button", disabled: queued, onClick: () => command({ action: "enqueue", track }), children: queued ? "In your queue" : "Add to queue" }),
|
|
1481
|
+
highlightAvailable && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { type: "button", "aria-pressed": highlightEnabled, onClick: () => setHighlightEnabled(!highlightEnabled), children: "Highlight words" })
|
|
1482
|
+
] });
|
|
1483
|
+
}
|
|
1484
|
+
var formatTime = (seconds) => `${Math.floor(seconds / 60)}:${String(Math.floor(seconds % 60)).padStart(2, "0")}`;
|
|
1485
|
+
function NetworkAudioPlayer({ networkName = "Your listening queue", advertisement, className = "", style, fixed = true, renderArticleLink }) {
|
|
1486
|
+
const { snapshot, remote, hosted, notice, command, openNetworkPlayer } = useNetworkAudio();
|
|
1487
|
+
const [expanded, setExpanded] = (0, import_react2.useState)(false);
|
|
1488
|
+
const [height, setHeight] = (0, import_react2.useState)(0);
|
|
1489
|
+
const bar = (0, import_react2.useRef)(null);
|
|
1490
|
+
const detailsId = (0, import_react2.useId)();
|
|
1491
|
+
const track = snapshot.queue[snapshot.index];
|
|
1492
|
+
const playing = snapshot.status === "playing" || snapshot.status === "loading";
|
|
1493
|
+
(0, import_react2.useEffect)(() => {
|
|
1494
|
+
const element = bar.current;
|
|
1495
|
+
if (!fixed || !element) return;
|
|
1496
|
+
const measure = () => setHeight(element.getBoundingClientRect().height);
|
|
1497
|
+
measure();
|
|
1498
|
+
if (typeof ResizeObserver === "undefined") {
|
|
1499
|
+
window.addEventListener("resize", measure);
|
|
1500
|
+
return () => window.removeEventListener("resize", measure);
|
|
1501
|
+
}
|
|
1502
|
+
const observer = new ResizeObserver(measure);
|
|
1503
|
+
observer.observe(element);
|
|
1504
|
+
return () => observer.disconnect();
|
|
1505
|
+
}, [fixed, !!track, expanded, notice, snapshot.error]);
|
|
1506
|
+
if (!track) return notice ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { role: "status", children: notice }) : null;
|
|
1507
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
1508
|
+
fixed && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { "aria-hidden": "true", style: { height } }),
|
|
1509
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("section", { ref: bar, className: `sm-network-player ${fixed ? "sm-network-player--fixed" : ""} ${className}`, style, "aria-label": "Network audio player", children: [
|
|
1510
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "sm-network-player__row", children: [
|
|
1511
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { type: "button", className: "sm-network-player__play", "aria-label": playing ? "Pause playback" : "Play playback", onClick: () => command({ action: playing ? "pause" : "play" }), children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("svg", { viewBox: "0 0 24 24", "aria-hidden": "true", children: playing ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M6 4h4v16H6zm8 0h4v16h-4z" }) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M7 3v18l15-9z" }) }) }),
|
|
1512
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "sm-network-player__story", children: [
|
|
1513
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: remote ? "Playing in network window" : networkName }),
|
|
1514
|
+
!hosted && renderArticleLink ? renderArticleLink(track) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("a", { href: track.articleUrl, target: "_blank", rel: "noopener noreferrer", children: track.title }),
|
|
1515
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("small", { children: track.publicationName })
|
|
1516
|
+
] }),
|
|
1517
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "sm-network-player__timeline", children: [
|
|
1518
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("input", { type: "range", min: "0", max: snapshot.duration || 0, step: "0.1", value: Math.min(snapshot.position, snapshot.duration), disabled: !snapshot.duration, "aria-label": "Seek article audio", onChange: (e) => command({ action: "seek", value: Number(e.target.value) }) }),
|
|
1519
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { children: [
|
|
1520
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: formatTime(snapshot.position) }),
|
|
1521
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { children: [
|
|
1522
|
+
formatTime(Math.max(0, snapshot.duration - snapshot.position) / snapshot.rate),
|
|
1523
|
+
" remaining"
|
|
1524
|
+
] })
|
|
1525
|
+
] })
|
|
1526
|
+
] }),
|
|
1527
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { type: "button", disabled: snapshot.index + 1 >= snapshot.queue.length, onClick: () => command({ action: "select", value: snapshot.index + 1 }), children: "Next" }),
|
|
1528
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { type: "button", "aria-expanded": expanded, "aria-controls": detailsId, onClick: () => setExpanded(!expanded), children: expanded ? "Collapse" : `Queue (${snapshot.queue.length})` })
|
|
1529
|
+
] }),
|
|
1530
|
+
(notice || snapshot.error) && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { role: "status", className: "sm-network-player__notice", children: notice ?? snapshot.error }),
|
|
1531
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { id: detailsId, hidden: !expanded, className: "sm-network-player__details", children: [
|
|
1532
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "sm-network-player__tools", children: [
|
|
1533
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { type: "button", onClick: () => command({ action: "seek", value: snapshot.position - 15 }), children: "Back 15 seconds" }),
|
|
1534
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { type: "button", onClick: () => command({ action: "seek", value: snapshot.position + 30 }), children: "Forward 30 seconds" }),
|
|
1535
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("label", { children: [
|
|
1536
|
+
"Speed ",
|
|
1537
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("select", { value: snapshot.rate, onChange: (e) => command({ action: "rate", value: Number(e.target.value) }), children: [0.5, 0.75, 1, 1.25, 1.5, 1.75, 2, 2.5, 3].map((rate) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("option", { value: rate, children: [
|
|
1538
|
+
rate,
|
|
1539
|
+
"\xD7"
|
|
1540
|
+
] }, rate)) })
|
|
1541
|
+
] }),
|
|
1542
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("label", { children: [
|
|
1543
|
+
"Volume ",
|
|
1544
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("input", { type: "range", min: "0", max: "1", step: "0.05", value: snapshot.volume, onChange: (e) => command({ action: "volume", value: Number(e.target.value) }) })
|
|
1545
|
+
] }),
|
|
1546
|
+
openNetworkPlayer && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { type: "button", onClick: openNetworkPlayer, children: remote ? "Open player window" : "Listen across sites \u2197" }),
|
|
1547
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { type: "button", onClick: () => command({ action: "clear" }), children: "Stop and clear queue" })
|
|
1548
|
+
] }),
|
|
1549
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "sm-network-player__expanded", children: [
|
|
1550
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { children: [
|
|
1551
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("h2", { children: "Up next" }),
|
|
1552
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("ol", { children: snapshot.queue.map((item, index) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("li", { "aria-current": index === snapshot.index ? "true" : void 0, children: [
|
|
1553
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("button", { type: "button", className: "sm-network-player__queue-title", onClick: () => command({ action: "select", value: index }), children: [
|
|
1554
|
+
item.title,
|
|
1555
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("small", { children: [
|
|
1556
|
+
item.publicationName,
|
|
1557
|
+
index === snapshot.index ? " \u2014 Current article" : ""
|
|
1558
|
+
] })
|
|
1559
|
+
] }),
|
|
1560
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { type: "button", "aria-label": `Remove ${item.title} from queue`, onClick: () => command({ action: "remove", value: index }), children: "Remove" })
|
|
1561
|
+
] }, trackKey(item))) })
|
|
1562
|
+
] }),
|
|
1563
|
+
advertisement && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("aside", { "aria-label": "Advertisement", children: [
|
|
1564
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: "Advertisement" }),
|
|
1565
|
+
advertisement
|
|
1566
|
+
] })
|
|
1567
|
+
] })
|
|
1568
|
+
] })
|
|
1569
|
+
] })
|
|
1570
|
+
] });
|
|
1571
|
+
}
|
|
798
1572
|
// Annotate the CommonJS export names for ESM import in node:
|
|
799
1573
|
0 && (module.exports = {
|
|
1574
|
+
ArticleAudioControls,
|
|
800
1575
|
AudioPlayer,
|
|
801
1576
|
NarrationHighlighter,
|
|
1577
|
+
NetworkAudioController,
|
|
1578
|
+
NetworkAudioPlayer,
|
|
1579
|
+
NetworkAudioProvider,
|
|
802
1580
|
SENTENCE_HIGHLIGHT,
|
|
803
1581
|
WORD_HIGHLIGHT,
|
|
804
1582
|
narrationHighlightSupported,
|
|
805
|
-
parseTimingsPayload
|
|
1583
|
+
parseTimingsPayload,
|
|
1584
|
+
useArticleNarration,
|
|
1585
|
+
useNetworkAudio
|
|
806
1586
|
});
|