@viostream/viostream-player-svelte 0.2.7 → 0.2.9
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 +1 -0
- package/dist/ViostreamPlayer.svelte +24 -27
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -89,6 +89,7 @@ All embed options are optional and passed directly to the Viostream embed API.
|
|
|
89
89
|
| `startTime` | `string` | Seek to a time (seconds) before playback. |
|
|
90
90
|
| `transcriptDownload` | `boolean` | Allow transcript download. Default: `false`. |
|
|
91
91
|
| `useSettingsMenu` | `boolean` | Enable the settings menu on the control bar. Default: `false`. |
|
|
92
|
+
| `forceAspectRatio` | `number` | Force a specific aspect ratio (e.g. `1.7778` for 16:9). Disables dynamic sizing. Must be a finite positive number; invalid values are ignored. |
|
|
92
93
|
|
|
93
94
|
#### Event Callbacks
|
|
94
95
|
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
<script lang="ts">
|
|
27
27
|
import { onMount, type Snippet } from 'svelte';
|
|
28
28
|
import Debug from 'debug';
|
|
29
|
-
import { getViostreamApi, wrapRawPlayer } from '@viostream/viostream-player-core';
|
|
29
|
+
import { getViostreamApi, wrapRawPlayer, normalizeForceAspectRatio } from '@viostream/viostream-player-core';
|
|
30
30
|
import type {
|
|
31
31
|
ViostreamEmbedOptions,
|
|
32
32
|
ViostreamPlayer,
|
|
@@ -60,6 +60,7 @@
|
|
|
60
60
|
startTime,
|
|
61
61
|
transcriptDownload,
|
|
62
62
|
useSettingsMenu,
|
|
63
|
+
forceAspectRatio,
|
|
63
64
|
|
|
64
65
|
// Event callbacks
|
|
65
66
|
onplay,
|
|
@@ -92,13 +93,11 @@
|
|
|
92
93
|
|
|
93
94
|
// Internal state
|
|
94
95
|
let containerEl: HTMLDivElement | undefined = $state();
|
|
96
|
+
let embedTargetEl: HTMLDivElement | undefined = $state();
|
|
95
97
|
let player: ViostreamPlayer | undefined = $state();
|
|
96
98
|
let errorMsg: string | undefined = $state();
|
|
97
99
|
let isLoading = $state(true);
|
|
98
100
|
|
|
99
|
-
// Unique ID for the container
|
|
100
|
-
const containerId = `viostream-player-${Math.random().toString(36).slice(2, 10)}`;
|
|
101
|
-
|
|
102
101
|
// Build the embed options object from props
|
|
103
102
|
function buildEmbedOptions(): ViostreamEmbedOptions {
|
|
104
103
|
const opts: ViostreamEmbedOptions = {};
|
|
@@ -136,10 +135,19 @@
|
|
|
136
135
|
];
|
|
137
136
|
|
|
138
137
|
onMount(() => {
|
|
139
|
-
|
|
138
|
+
// Generate unique IDs on the client only and assign them imperatively
|
|
139
|
+
// to the DOM elements. This avoids SSR/hydration mismatches caused by
|
|
140
|
+
// Math.random() producing different values on server vs client.
|
|
141
|
+
const containerId = `viostream-player-${Math.random().toString(36).slice(2, 10)}`;
|
|
142
|
+
const embedTargetId = `viostream-embed-${Math.random().toString(36).slice(2, 10)}`;
|
|
143
|
+
|
|
144
|
+
containerEl!.id = containerId;
|
|
145
|
+
containerEl!.setAttribute('data-viostream-sdk', `${SDK_NAME}@${SDK_VERSION}`);
|
|
146
|
+
embedTargetEl!.id = embedTargetId;
|
|
147
|
+
|
|
148
|
+
debug('onMount publicKey=%s accountKey=%s containerId=%s embedTargetId=%s', publicKey, accountKey, containerId, embedTargetId);
|
|
140
149
|
|
|
141
150
|
let destroyed = false;
|
|
142
|
-
const unsubscribers: Array<() => void> = [];
|
|
143
151
|
|
|
144
152
|
async function init() {
|
|
145
153
|
try {
|
|
@@ -152,12 +160,12 @@
|
|
|
152
160
|
}
|
|
153
161
|
|
|
154
162
|
const embedOpts = buildEmbedOptions();
|
|
155
|
-
debug('init: calling api.embed publicKey=%s
|
|
156
|
-
const raw: RawViostreamPlayerInstance = api.embed(publicKey,
|
|
163
|
+
debug('init: calling api.embed publicKey=%s embedTargetId=%s options=%o', publicKey, embedTargetId, embedOpts);
|
|
164
|
+
const raw: RawViostreamPlayerInstance = api.embed(publicKey, embedTargetId, embedOpts, normalizeForceAspectRatio(forceAspectRatio));
|
|
157
165
|
debug('init: api.embed returned raw player');
|
|
158
166
|
|
|
159
|
-
const wrappedPlayer = wrapRawPlayer(raw,
|
|
160
|
-
debug('init: wrapRawPlayer completed
|
|
167
|
+
const wrappedPlayer = wrapRawPlayer(raw, embedTargetId);
|
|
168
|
+
debug('init: wrapRawPlayer completed embedTargetId=%s', embedTargetId);
|
|
161
169
|
|
|
162
170
|
if (destroyed) {
|
|
163
171
|
debug('init: stale closure detected after wrapRawPlayer — destroying and aborting publicKey=%s', publicKey);
|
|
@@ -169,17 +177,9 @@
|
|
|
169
177
|
isLoading = false;
|
|
170
178
|
debug('init: player set, isLoading -> false publicKey=%s', publicKey);
|
|
171
179
|
|
|
172
|
-
//
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
const handler = getHandler();
|
|
176
|
-
if (handler) {
|
|
177
|
-
const unsub = wrappedPlayer.on(eventName, handler);
|
|
178
|
-
unsubscribers.push(unsub);
|
|
179
|
-
wiredEvents.push(eventName);
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
debug('init: event wiring subscribed to [%s]', wiredEvents.join(', '));
|
|
180
|
+
// Event wiring is handled by the $effect block below, which
|
|
181
|
+
// runs reactively when `player` is set and re-wires when
|
|
182
|
+
// callback props change.
|
|
183
183
|
|
|
184
184
|
// Notify consumer that the player is ready
|
|
185
185
|
debug('init: firing onplayerready publicKey=%s', publicKey);
|
|
@@ -199,11 +199,8 @@
|
|
|
199
199
|
init();
|
|
200
200
|
|
|
201
201
|
return () => {
|
|
202
|
-
debug('cleanup publicKey=%s hasPlayer=%s
|
|
202
|
+
debug('cleanup publicKey=%s hasPlayer=%s', publicKey, !!player);
|
|
203
203
|
destroyed = true;
|
|
204
|
-
for (const unsub of unsubscribers) {
|
|
205
|
-
unsub();
|
|
206
|
-
}
|
|
207
204
|
player?.destroy();
|
|
208
205
|
player = undefined;
|
|
209
206
|
};
|
|
@@ -241,13 +238,13 @@
|
|
|
241
238
|
</script>
|
|
242
239
|
|
|
243
240
|
<div
|
|
244
|
-
id={containerId}
|
|
245
241
|
class={className}
|
|
246
242
|
bind:this={containerEl}
|
|
247
243
|
data-viostream-player
|
|
248
244
|
data-viostream-public-key={publicKey}
|
|
249
|
-
data-viostream-sdk={`${SDK_NAME}@${SDK_VERSION}`}
|
|
250
245
|
>
|
|
246
|
+
<div bind:this={embedTargetEl} data-viostream-embed-target></div>
|
|
247
|
+
|
|
251
248
|
{#if isLoading}
|
|
252
249
|
{#if loadingSnippet}
|
|
253
250
|
{@render loadingSnippet()}
|
package/dist/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export declare const SDK_NAME = "viostream-player-svelte";
|
|
2
|
-
export declare const SDK_VERSION = "0.2.
|
|
2
|
+
export declare const SDK_VERSION = "0.2.9";
|
package/dist/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@viostream/viostream-player-svelte",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.9",
|
|
4
4
|
"description": "Svelte 5 SDK for the Viostream video player — embed, control, and listen to player events",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"!dist/**/*.spec.*"
|
|
32
32
|
],
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@viostream/viostream-player-core": "^0.2.
|
|
34
|
+
"@viostream/viostream-player-core": "^0.2.9",
|
|
35
35
|
"debug": "^4.4.3"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|