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