@viostream/viostream-player-svelte 0.2.5 → 0.2.7
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/ViostreamPlayer.svelte +39 -5
- package/dist/version.d.ts +2 -0
- package/dist/version.js +3 -0
- package/package.json +6 -3
|
@@ -25,7 +25,8 @@
|
|
|
25
25
|
-->
|
|
26
26
|
<script lang="ts">
|
|
27
27
|
import { onMount, type Snippet } from 'svelte';
|
|
28
|
-
import
|
|
28
|
+
import Debug from 'debug';
|
|
29
|
+
import { getViostreamApi, wrapRawPlayer } from '@viostream/viostream-player-core';
|
|
29
30
|
import type {
|
|
30
31
|
ViostreamEmbedOptions,
|
|
31
32
|
ViostreamPlayer,
|
|
@@ -33,6 +34,9 @@
|
|
|
33
34
|
ViostreamEventHandler,
|
|
34
35
|
} from '@viostream/viostream-player-core';
|
|
35
36
|
import type { ViostreamPlayerProps } from './types.js';
|
|
37
|
+
import { SDK_NAME, SDK_VERSION } from './version.js';
|
|
38
|
+
|
|
39
|
+
const debug = Debug('viostream:svelte');
|
|
36
40
|
|
|
37
41
|
let {
|
|
38
42
|
// Required props
|
|
@@ -132,42 +136,62 @@
|
|
|
132
136
|
];
|
|
133
137
|
|
|
134
138
|
onMount(() => {
|
|
139
|
+
debug('onMount publicKey=%s accountKey=%s containerId=%s', publicKey, accountKey, containerId);
|
|
140
|
+
|
|
135
141
|
let destroyed = false;
|
|
136
142
|
const unsubscribers: Array<() => void> = [];
|
|
137
143
|
|
|
138
144
|
async function init() {
|
|
139
145
|
try {
|
|
140
|
-
|
|
146
|
+
debug('init: getting embed API');
|
|
147
|
+
const api = getViostreamApi();
|
|
141
148
|
|
|
142
|
-
if (destroyed)
|
|
149
|
+
if (destroyed) {
|
|
150
|
+
debug('init: stale closure detected after getViostreamApi — aborting publicKey=%s', publicKey);
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
143
153
|
|
|
144
154
|
const embedOpts = buildEmbedOptions();
|
|
155
|
+
debug('init: calling api.embed publicKey=%s containerId=%s options=%o', publicKey, containerId, embedOpts);
|
|
145
156
|
const raw: RawViostreamPlayerInstance = api.embed(publicKey, containerId, embedOpts);
|
|
157
|
+
debug('init: api.embed returned raw player');
|
|
158
|
+
|
|
146
159
|
const wrappedPlayer = wrapRawPlayer(raw, containerId);
|
|
160
|
+
debug('init: wrapRawPlayer completed containerId=%s', containerId);
|
|
147
161
|
|
|
148
162
|
if (destroyed) {
|
|
163
|
+
debug('init: stale closure detected after wrapRawPlayer — destroying and aborting publicKey=%s', publicKey);
|
|
149
164
|
wrappedPlayer.destroy();
|
|
150
165
|
return;
|
|
151
166
|
}
|
|
152
167
|
|
|
153
168
|
player = wrappedPlayer;
|
|
154
169
|
isLoading = false;
|
|
170
|
+
debug('init: player set, isLoading -> false publicKey=%s', publicKey);
|
|
155
171
|
|
|
156
172
|
// Wire up event callbacks from props
|
|
173
|
+
const wiredEvents: string[] = [];
|
|
157
174
|
for (const [eventName, getHandler] of EVENT_MAP) {
|
|
158
175
|
const handler = getHandler();
|
|
159
176
|
if (handler) {
|
|
160
177
|
const unsub = wrappedPlayer.on(eventName, handler);
|
|
161
178
|
unsubscribers.push(unsub);
|
|
179
|
+
wiredEvents.push(eventName);
|
|
162
180
|
}
|
|
163
181
|
}
|
|
182
|
+
debug('init: event wiring subscribed to [%s]', wiredEvents.join(', '));
|
|
164
183
|
|
|
165
184
|
// Notify consumer that the player is ready
|
|
185
|
+
debug('init: firing onplayerready publicKey=%s', publicKey);
|
|
166
186
|
onplayerready?.(wrappedPlayer);
|
|
167
187
|
} catch (err) {
|
|
168
188
|
if (!destroyed) {
|
|
169
|
-
|
|
189
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
190
|
+
debug('init: error caught publicKey=%s error=%s', publicKey, msg);
|
|
191
|
+
errorMsg = msg;
|
|
170
192
|
isLoading = false;
|
|
193
|
+
} else {
|
|
194
|
+
debug('init: error caught but destroyed — ignoring publicKey=%s', publicKey);
|
|
171
195
|
}
|
|
172
196
|
}
|
|
173
197
|
}
|
|
@@ -175,6 +199,7 @@
|
|
|
175
199
|
init();
|
|
176
200
|
|
|
177
201
|
return () => {
|
|
202
|
+
debug('cleanup publicKey=%s hasPlayer=%s unsubscribers=%d', publicKey, !!player, unsubscribers.length);
|
|
178
203
|
destroyed = true;
|
|
179
204
|
for (const unsub of unsubscribers) {
|
|
180
205
|
unsub();
|
|
@@ -187,19 +212,27 @@
|
|
|
187
212
|
// Re-wire event handlers reactively when callback props change
|
|
188
213
|
// This handles the case where a consumer conditionally provides callbacks
|
|
189
214
|
$effect(() => {
|
|
190
|
-
if (!player)
|
|
215
|
+
if (!player) {
|
|
216
|
+
debug('$effect event wiring skipped — no player');
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
191
219
|
|
|
192
220
|
const currentUnsubscribers: Array<() => void> = [];
|
|
221
|
+
const wiredEvents: string[] = [];
|
|
193
222
|
|
|
194
223
|
for (const [eventName, getHandler] of EVENT_MAP) {
|
|
195
224
|
const handler = getHandler();
|
|
196
225
|
if (handler) {
|
|
197
226
|
const unsub = player.on(eventName, handler);
|
|
198
227
|
currentUnsubscribers.push(unsub);
|
|
228
|
+
wiredEvents.push(eventName);
|
|
199
229
|
}
|
|
200
230
|
}
|
|
201
231
|
|
|
232
|
+
debug('$effect event wiring: subscribed to [%s]', wiredEvents.join(', '));
|
|
233
|
+
|
|
202
234
|
return () => {
|
|
235
|
+
debug('$effect event wiring cleanup: unsubscribing %d events', currentUnsubscribers.length);
|
|
203
236
|
for (const unsub of currentUnsubscribers) {
|
|
204
237
|
unsub();
|
|
205
238
|
}
|
|
@@ -213,6 +246,7 @@
|
|
|
213
246
|
bind:this={containerEl}
|
|
214
247
|
data-viostream-player
|
|
215
248
|
data-viostream-public-key={publicKey}
|
|
249
|
+
data-viostream-sdk={`${SDK_NAME}@${SDK_VERSION}`}
|
|
216
250
|
>
|
|
217
251
|
{#if isLoading}
|
|
218
252
|
{#if loadingSnippet}
|
package/dist/version.js
ADDED
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.7",
|
|
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": {
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
},
|
|
9
9
|
"type": "module",
|
|
10
10
|
"scripts": {
|
|
11
|
+
"prebuild": "node ../../scripts/sync-version.mjs src/lib/version.ts",
|
|
11
12
|
"package": "svelte-kit sync && svelte-package && publint",
|
|
12
13
|
"build": "npm run package",
|
|
13
14
|
"prepublishOnly": "npm run package",
|
|
@@ -30,7 +31,8 @@
|
|
|
30
31
|
"!dist/**/*.spec.*"
|
|
31
32
|
],
|
|
32
33
|
"dependencies": {
|
|
33
|
-
"@viostream/viostream-player-core": "^0.2.
|
|
34
|
+
"@viostream/viostream-player-core": "^0.2.7",
|
|
35
|
+
"debug": "^4.4.3"
|
|
34
36
|
},
|
|
35
37
|
"peerDependencies": {
|
|
36
38
|
"svelte": "^5.0.0"
|
|
@@ -41,6 +43,7 @@
|
|
|
41
43
|
"@sveltejs/vite-plugin-svelte": "^5.0.0",
|
|
42
44
|
"@testing-library/jest-dom": "^6.9.1",
|
|
43
45
|
"@testing-library/svelte": "^5.3.1",
|
|
46
|
+
"@types/debug": "^4.1.13",
|
|
44
47
|
"jsdom": "^28.1.0",
|
|
45
48
|
"publint": "^0.3.0",
|
|
46
49
|
"svelte": "^5.0.0",
|
|
@@ -58,4 +61,4 @@
|
|
|
58
61
|
"embed",
|
|
59
62
|
"sdk"
|
|
60
63
|
]
|
|
61
|
-
}
|
|
64
|
+
}
|