@file-viewer/renderer-media 2.2.3 → 2.2.4
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/dist/video.js +92 -4
- package/package.json +2 -2
package/dist/video.js
CHANGED
|
@@ -81,10 +81,13 @@ export default async function renderVideo(buffer, target, type, context) {
|
|
|
81
81
|
return objectUrl;
|
|
82
82
|
};
|
|
83
83
|
const mountVideo = async () => {
|
|
84
|
+
var _a;
|
|
84
85
|
const source = resolveSource();
|
|
85
86
|
if (normalizedType === 'm3u8') {
|
|
86
87
|
if (video.canPlayType('application/vnd.apple.mpegurl')) {
|
|
87
88
|
video.src = source;
|
|
89
|
+
video.load();
|
|
90
|
+
await waitForVideoMetadata(video, context === null || context === void 0 ? void 0 : context.signal);
|
|
88
91
|
return;
|
|
89
92
|
}
|
|
90
93
|
const { default: HlsConstructor } = await import('hls.js');
|
|
@@ -93,15 +96,53 @@ export default async function renderVideo(buffer, target, type, context) {
|
|
|
93
96
|
}
|
|
94
97
|
if (HlsConstructor.isSupported()) {
|
|
95
98
|
hls = new HlsConstructor({ enableWorker: true, lowLatencyMode: false });
|
|
96
|
-
|
|
97
|
-
|
|
99
|
+
if ((_a = context === null || context === void 0 ? void 0 : context.signal) === null || _a === void 0 ? void 0 : _a.aborted) {
|
|
100
|
+
throw new DOMException('The video request was aborted.', 'AbortError');
|
|
101
|
+
}
|
|
102
|
+
await new Promise((resolve, reject) => {
|
|
103
|
+
var _a;
|
|
104
|
+
const events = HlsConstructor.Events;
|
|
105
|
+
const timeoutId = window.setTimeout(() => {
|
|
106
|
+
cleanupListeners();
|
|
107
|
+
reject(new Error('Timed out while loading the HLS manifest.'));
|
|
108
|
+
}, 30000);
|
|
109
|
+
const onManifest = () => {
|
|
110
|
+
cleanupListeners();
|
|
111
|
+
resolve();
|
|
112
|
+
};
|
|
113
|
+
const onError = (_event, data) => {
|
|
114
|
+
if (!(data === null || data === void 0 ? void 0 : data.fatal))
|
|
115
|
+
return;
|
|
116
|
+
cleanupListeners();
|
|
117
|
+
reject(new Error(data.details || 'Unable to load the HLS video stream.'));
|
|
118
|
+
};
|
|
119
|
+
const onAbort = () => {
|
|
120
|
+
cleanupListeners();
|
|
121
|
+
reject(new DOMException('The video request was aborted.', 'AbortError'));
|
|
122
|
+
};
|
|
123
|
+
const cleanupListeners = () => {
|
|
124
|
+
var _a;
|
|
125
|
+
window.clearTimeout(timeoutId);
|
|
126
|
+
hls === null || hls === void 0 ? void 0 : hls.off(events.MANIFEST_PARSED, onManifest);
|
|
127
|
+
hls === null || hls === void 0 ? void 0 : hls.off(events.ERROR, onError);
|
|
128
|
+
(_a = context === null || context === void 0 ? void 0 : context.signal) === null || _a === void 0 ? void 0 : _a.removeEventListener('abort', onAbort);
|
|
129
|
+
};
|
|
130
|
+
hls === null || hls === void 0 ? void 0 : hls.on(events.MANIFEST_PARSED, onManifest);
|
|
131
|
+
hls === null || hls === void 0 ? void 0 : hls.on(events.ERROR, onError);
|
|
132
|
+
(_a = context === null || context === void 0 ? void 0 : context.signal) === null || _a === void 0 ? void 0 : _a.addEventListener('abort', onAbort, { once: true });
|
|
133
|
+
hls === null || hls === void 0 ? void 0 : hls.attachMedia(video);
|
|
134
|
+
hls === null || hls === void 0 ? void 0 : hls.loadSource(source);
|
|
135
|
+
});
|
|
136
|
+
await waitForVideoMetadata(video, context === null || context === void 0 ? void 0 : context.signal);
|
|
98
137
|
return;
|
|
99
138
|
}
|
|
139
|
+
throw new Error('This browser cannot play HLS video.');
|
|
100
140
|
}
|
|
101
141
|
video.src = source;
|
|
142
|
+
video.load();
|
|
143
|
+
await waitForVideoMetadata(video, context === null || context === void 0 ? void 0 : context.signal);
|
|
102
144
|
};
|
|
103
|
-
|
|
104
|
-
return createRenderedInstance(target, () => {
|
|
145
|
+
const cleanup = () => {
|
|
105
146
|
disposed = true;
|
|
106
147
|
hls === null || hls === void 0 ? void 0 : hls.destroy();
|
|
107
148
|
hls = null;
|
|
@@ -112,5 +153,52 @@ export default async function renderVideo(buffer, target, type, context) {
|
|
|
112
153
|
URL.revokeObjectURL(objectUrl);
|
|
113
154
|
objectUrl = '';
|
|
114
155
|
}
|
|
156
|
+
};
|
|
157
|
+
try {
|
|
158
|
+
await mountVideo();
|
|
159
|
+
}
|
|
160
|
+
catch (error) {
|
|
161
|
+
cleanup();
|
|
162
|
+
target.replaceChildren();
|
|
163
|
+
throw error;
|
|
164
|
+
}
|
|
165
|
+
return createRenderedInstance(target, () => {
|
|
166
|
+
cleanup();
|
|
115
167
|
});
|
|
116
168
|
}
|
|
169
|
+
const waitForVideoMetadata = async (video, signal) => {
|
|
170
|
+
if (video.readyState >= HTMLMediaElement.HAVE_METADATA)
|
|
171
|
+
return;
|
|
172
|
+
if (signal === null || signal === void 0 ? void 0 : signal.aborted)
|
|
173
|
+
throw new DOMException('The video request was aborted.', 'AbortError');
|
|
174
|
+
await new Promise((resolve, reject) => {
|
|
175
|
+
const timeoutId = window.setTimeout(() => {
|
|
176
|
+
cleanup();
|
|
177
|
+
reject(new Error('Timed out while loading video metadata.'));
|
|
178
|
+
}, 30000);
|
|
179
|
+
const cleanup = () => {
|
|
180
|
+
window.clearTimeout(timeoutId);
|
|
181
|
+
video.removeEventListener('loadedmetadata', onReady);
|
|
182
|
+
video.removeEventListener('canplay', onReady);
|
|
183
|
+
video.removeEventListener('error', onError);
|
|
184
|
+
signal === null || signal === void 0 ? void 0 : signal.removeEventListener('abort', onAbort);
|
|
185
|
+
};
|
|
186
|
+
const onReady = () => {
|
|
187
|
+
cleanup();
|
|
188
|
+
resolve();
|
|
189
|
+
};
|
|
190
|
+
const onError = () => {
|
|
191
|
+
var _a;
|
|
192
|
+
cleanup();
|
|
193
|
+
reject(new Error(((_a = video.error) === null || _a === void 0 ? void 0 : _a.message) || 'The browser could not decode this video.'));
|
|
194
|
+
};
|
|
195
|
+
const onAbort = () => {
|
|
196
|
+
cleanup();
|
|
197
|
+
reject(new DOMException('The video request was aborted.', 'AbortError'));
|
|
198
|
+
};
|
|
199
|
+
video.addEventListener('loadedmetadata', onReady, { once: true });
|
|
200
|
+
video.addEventListener('canplay', onReady, { once: true });
|
|
201
|
+
video.addEventListener('error', onError, { once: true });
|
|
202
|
+
signal === null || signal === void 0 ? void 0 : signal.addEventListener('abort', onAbort, { once: true });
|
|
203
|
+
});
|
|
204
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@file-viewer/renderer-media",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.4",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Standalone audio and video renderer plugin for File Viewer with native media playback, HLS fallback, MIDI parsing, and offline-friendly lazy loading.",
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"LICENSE"
|
|
56
56
|
],
|
|
57
57
|
"dependencies": {
|
|
58
|
-
"@file-viewer/core": "2.2.
|
|
58
|
+
"@file-viewer/core": "2.2.4",
|
|
59
59
|
"@tonejs/midi": "^2.0.28",
|
|
60
60
|
"hls.js": "^1.6.16"
|
|
61
61
|
},
|