@viostream/viostream-player-svelte 0.2.6 → 0.2.8

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 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
 
@@ -25,7 +25,8 @@
25
25
  -->
26
26
  <script lang="ts">
27
27
  import { onMount, type Snippet } from 'svelte';
28
- import { getViostreamApi, wrapRawPlayer } from '@viostream/viostream-player-core';
28
+ import Debug from 'debug';
29
+ import { getViostreamApi, wrapRawPlayer, normalizeForceAspectRatio } from '@viostream/viostream-player-core';
29
30
  import type {
30
31
  ViostreamEmbedOptions,
31
32
  ViostreamPlayer,
@@ -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,
@@ -57,6 +60,7 @@
57
60
  startTime,
58
61
  transcriptDownload,
59
62
  useSettingsMenu,
63
+ forceAspectRatio,
60
64
 
61
65
  // Event callbacks
62
66
  onplay,
@@ -133,42 +137,53 @@
133
137
  ];
134
138
 
135
139
  onMount(() => {
140
+ debug('onMount publicKey=%s accountKey=%s containerId=%s', publicKey, accountKey, containerId);
141
+
136
142
  let destroyed = false;
137
- 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();
146
- const raw: RawViostreamPlayerInstance = api.embed(publicKey, containerId, embedOpts);
155
+ debug('init: calling api.embed publicKey=%s containerId=%s options=%o', publicKey, containerId, embedOpts);
156
+ const raw: RawViostreamPlayerInstance = api.embed(publicKey, containerId, embedOpts, normalizeForceAspectRatio(forceAspectRatio));
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
- // Wire up event callbacks from props
158
- for (const [eventName, getHandler] of EVENT_MAP) {
159
- const handler = getHandler();
160
- if (handler) {
161
- const unsub = wrappedPlayer.on(eventName, handler);
162
- unsubscribers.push(unsub);
163
- }
164
- }
172
+ // Event wiring is handled by the $effect block below, which
173
+ // runs reactively when `player` is set and re-wires when
174
+ // callback props change.
165
175
 
166
176
  // Notify consumer that the player is ready
177
+ debug('init: firing onplayerready publicKey=%s', publicKey);
167
178
  onplayerready?.(wrappedPlayer);
168
179
  } catch (err) {
169
180
  if (!destroyed) {
170
- errorMsg = err instanceof Error ? err.message : String(err);
181
+ const msg = err instanceof Error ? err.message : String(err);
182
+ debug('init: error caught publicKey=%s error=%s', publicKey, msg);
183
+ errorMsg = msg;
171
184
  isLoading = false;
185
+ } else {
186
+ debug('init: error caught but destroyed — ignoring publicKey=%s', publicKey);
172
187
  }
173
188
  }
174
189
  }
@@ -176,10 +191,8 @@
176
191
  init();
177
192
 
178
193
  return () => {
194
+ debug('cleanup publicKey=%s hasPlayer=%s', publicKey, !!player);
179
195
  destroyed = true;
180
- for (const unsub of unsubscribers) {
181
- unsub();
182
- }
183
196
  player?.destroy();
184
197
  player = undefined;
185
198
  };
@@ -188,19 +201,27 @@
188
201
  // Re-wire event handlers reactively when callback props change
189
202
  // This handles the case where a consumer conditionally provides callbacks
190
203
  $effect(() => {
191
- if (!player) return;
204
+ if (!player) {
205
+ debug('$effect event wiring skipped — no player');
206
+ return;
207
+ }
192
208
 
193
209
  const currentUnsubscribers: Array<() => void> = [];
210
+ const wiredEvents: string[] = [];
194
211
 
195
212
  for (const [eventName, getHandler] of EVENT_MAP) {
196
213
  const handler = getHandler();
197
214
  if (handler) {
198
215
  const unsub = player.on(eventName, handler);
199
216
  currentUnsubscribers.push(unsub);
217
+ wiredEvents.push(eventName);
200
218
  }
201
219
  }
202
220
 
221
+ debug('$effect event wiring: subscribed to [%s]', wiredEvents.join(', '));
222
+
203
223
  return () => {
224
+ debug('$effect event wiring cleanup: unsubscribing %d events', currentUnsubscribers.length);
204
225
  for (const unsub of currentUnsubscribers) {
205
226
  unsub();
206
227
  }
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.8";
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.8';
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.8",
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.8",
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
+ }