@atmo-dev/kit 0.21.0 → 0.23.0

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.
Files changed (109) hide show
  1. package/README.md +1 -1
  2. package/dist/articles/ArticleView.svelte +21 -7
  3. package/dist/articles/ArticleView.svelte.d.ts +8 -4
  4. package/dist/articles/styles.js +3 -2
  5. package/dist/articles-data.d.ts +1 -0
  6. package/dist/components/RichText.svelte +34 -17
  7. package/dist/components/RichText.svelte.d.ts +4 -1
  8. package/dist/components/RichTextEditor.svelte +67 -11
  9. package/dist/components/RichTextEditor.svelte.d.ts +0 -2
  10. package/dist/components/StreamplacePicker.svelte +2 -2
  11. package/dist/components/StreamplacePicker.svelte.d.ts +1 -1
  12. package/dist/components/composer/EmojiPanel.svelte +55 -0
  13. package/dist/components/composer/EmojiPanel.svelte.d.ts +6 -0
  14. package/dist/components/composer/EmojiPicker.svelte +2 -38
  15. package/dist/components/data/DataLabel.svelte +120 -0
  16. package/dist/components/data/DataLabel.svelte.d.ts +10 -0
  17. package/dist/components/data/issues.d.ts +5 -0
  18. package/dist/components/data/issues.js +52 -0
  19. package/dist/components/data/types.d.ts +28 -0
  20. package/dist/components/data/types.js +1 -0
  21. package/dist/components/data/visibility.d.ts +7 -0
  22. package/dist/components/data/visibility.js +15 -0
  23. package/dist/components/legal/links.js +1 -0
  24. package/dist/components/legal/types.d.ts +1 -1
  25. package/dist/components/notifications/NotificationList.svelte +137 -0
  26. package/dist/components/notifications/NotificationList.svelte.d.ts +19 -0
  27. package/dist/components/notifications/NotificationPushToggle.svelte +76 -0
  28. package/dist/components/notifications/NotificationPushToggle.svelte.d.ts +19 -0
  29. package/dist/components/notifications/NotificationSettings.svelte +125 -0
  30. package/dist/components/notifications/NotificationSettings.svelte.d.ts +16 -0
  31. package/dist/components/notifications/types.d.ts +37 -0
  32. package/dist/components/notifications/types.js +1 -0
  33. package/dist/editor/ImageDialog.svelte +87 -0
  34. package/dist/editor/ImageDialog.svelte.d.ts +16 -0
  35. package/dist/editor/image-node.d.ts +6 -2
  36. package/dist/editor/image-node.js +36 -37
  37. package/dist/events/EventCard.svelte +6 -1
  38. package/dist/events/VodPlayer.svelte +1 -1
  39. package/dist/events/atmo-rsvp.d.ts +6 -0
  40. package/dist/events/atmo-rsvp.js +34 -0
  41. package/dist/events/atproto-helpers.d.ts +1 -0
  42. package/dist/events/atproto-helpers.js +3 -0
  43. package/dist/events/event-link-embed.d.ts +7 -3
  44. package/dist/events/event-link-embed.js +11 -5
  45. package/dist/events/event-view/StreamPlacePlayer.svelte +14 -108
  46. package/dist/events/linked-records.d.ts +1 -1
  47. package/dist/events/linked-records.js +2 -2
  48. package/dist/events-card.d.ts +9 -0
  49. package/dist/events-card.js +7 -0
  50. package/dist/events-data.d.ts +1 -0
  51. package/dist/events-data.js +1 -0
  52. package/dist/grain/xrpc.js +11 -4
  53. package/dist/index.d.ts +14 -2
  54. package/dist/index.js +7 -1
  55. package/dist/legal.d.ts +3 -0
  56. package/dist/legal.js +2 -0
  57. package/dist/media.d.ts +33 -0
  58. package/dist/media.js +74 -1
  59. package/dist/richtext/serialize.js +13 -8
  60. package/dist/streamplace/StreamCard.svelte +184 -0
  61. package/dist/streamplace/StreamCard.svelte.d.ts +24 -0
  62. package/dist/streamplace/StreamLinkEmbed.svelte +59 -0
  63. package/dist/streamplace/StreamLinkEmbed.svelte.d.ts +5 -0
  64. package/dist/streamplace/StreamPlayer.svelte +539 -0
  65. package/dist/streamplace/StreamPlayer.svelte.d.ts +42 -0
  66. package/dist/streamplace/VideoCard.svelte +159 -0
  67. package/dist/streamplace/VideoCard.svelte.d.ts +17 -0
  68. package/dist/streamplace/api.d.ts +74 -0
  69. package/dist/streamplace/api.js +182 -0
  70. package/dist/streamplace/broadcast.d.ts +3 -0
  71. package/dist/streamplace/broadcast.js +110 -0
  72. package/dist/streamplace/channel.svelte.d.ts +74 -0
  73. package/dist/streamplace/channel.svelte.js +515 -0
  74. package/dist/streamplace/chat/Composer.svelte +232 -0
  75. package/dist/streamplace/chat/Composer.svelte.d.ts +15 -0
  76. package/dist/streamplace/chat/Embeds.svelte +135 -0
  77. package/dist/streamplace/chat/Embeds.svelte.d.ts +13 -0
  78. package/dist/streamplace/chat/Message.svelte +303 -0
  79. package/dist/streamplace/chat/Message.svelte.d.ts +25 -0
  80. package/dist/streamplace/chat/StreamChat.svelte +463 -0
  81. package/dist/streamplace/chat/StreamChat.svelte.d.ts +33 -0
  82. package/dist/streamplace/chat/StreamChatPopups.svelte +151 -0
  83. package/dist/streamplace/chat/StreamChatPopups.svelte.d.ts +15 -0
  84. package/dist/streamplace/chat/UserCard.svelte +76 -0
  85. package/dist/streamplace/chat/UserCard.svelte.d.ts +12 -0
  86. package/dist/streamplace/chat/color.d.ts +7 -0
  87. package/dist/streamplace/chat/color.js +33 -0
  88. package/dist/streamplace/chat/links.d.ts +10 -0
  89. package/dist/streamplace/chat/links.js +29 -0
  90. package/dist/streamplace/facets.d.ts +15 -0
  91. package/dist/streamplace/facets.js +112 -0
  92. package/dist/streamplace/link-embed.d.ts +13 -0
  93. package/dist/streamplace/link-embed.js +16 -0
  94. package/dist/streamplace/links.d.ts +6 -0
  95. package/dist/streamplace/links.js +1 -0
  96. package/dist/streamplace/reactions.d.ts +21 -0
  97. package/dist/streamplace/reactions.js +46 -0
  98. package/dist/streamplace/types.d.ts +200 -0
  99. package/dist/streamplace/types.js +1 -0
  100. package/dist/streamplace-data.d.ts +11 -0
  101. package/dist/streamplace-data.js +10 -0
  102. package/dist/streamplace.d.ts +14 -6
  103. package/dist/streamplace.js +11 -1
  104. package/dist/{events/event-view → video}/Player.svelte +69 -21
  105. package/dist/video/Player.svelte.d.ts +38 -0
  106. package/dist/video/engines.d.ts +59 -0
  107. package/dist/video/engines.js +647 -0
  108. package/package.json +11 -1
  109. package/dist/events/event-view/Player.svelte.d.ts +0 -24
@@ -0,0 +1,539 @@
1
+ <script lang="ts" module>
2
+ import type { IconNode } from '@sketchyicons/svelte';
3
+
4
+ export type StreamPlayerProps = {
5
+ /** Live: the streamer's DID or handle. */
6
+ user?: string;
7
+ /** Whether the stream is live right now. Playback starts and stops with it. */
8
+ live?: boolean;
9
+ /** Transcoded renditions offered for low-delay playback, from `Channel.renditions`. */
10
+ renditions?: string[];
11
+ /** Recording: an HLS playlist, e.g. from `videoPlaylist(uri)`. */
12
+ src?: string;
13
+ /** Start playing as soon as there is something to play. On by default. */
14
+ autoplay?: boolean;
15
+ /** Recording: where to start, in seconds. */
16
+ startAt?: number;
17
+ poster?: string;
18
+ title?: string;
19
+ /** Remembered by the app; changed from the player's own controls. */
20
+ volume?: number;
21
+ muted?: boolean;
22
+ /** `low` plays over WebRTC, `smooth` buffers a few seconds over HLS. */
23
+ delay?: 'low' | 'smooth';
24
+ theater?: boolean;
25
+ /** Offer a theater-mode button (and the `t` key) on wide screens. The page does the layout. */
26
+ showTheater?: boolean;
27
+ /** Page-owned buttons in the top right corner, shown and hidden with the controls. */
28
+ cornerControls?: { label: string; icon: IconNode; onclick: () => void }[];
29
+ /** Whether the controls are on screen, for page elements that appear with them. */
30
+ controlsVisible?: boolean;
31
+ /** Where the keyboard shortcuts work: with focus in the player, or anywhere on the page. */
32
+ shortcuts?: 'focus' | 'page';
33
+ /** Shown instead of the video while a live stream is offline. */
34
+ offline?: Snippet;
35
+ ontime?: (seconds: number) => void;
36
+ };
37
+ </script>
38
+
39
+ <script lang="ts">
40
+ import { untrack, type Snippet } from 'svelte';
41
+ import {
42
+ Check,
43
+ PictureInPicture2,
44
+ RectangleHorizontal,
45
+ Settings,
46
+ VolumeX
47
+ } from '@sketchyicons/svelte';
48
+ import Icon from '../components/Icon.svelte';
49
+ import Player from '../video/Player.svelte';
50
+ import { startHls, startWebRTC, type Engine, type Level } from '../video/engines.js';
51
+ import { livePlaylist, whepUrl } from './api.js';
52
+
53
+ let {
54
+ user,
55
+ live = false,
56
+ renditions = [],
57
+ src,
58
+ autoplay = true,
59
+ startAt,
60
+ poster,
61
+ title = 'Video',
62
+ volume = $bindable(1),
63
+ muted = $bindable(false),
64
+ delay = $bindable('low'),
65
+ theater = $bindable(false),
66
+ showTheater = false,
67
+ cornerControls = [],
68
+ controlsVisible = $bindable(true),
69
+ shortcuts = 'focus',
70
+ offline,
71
+ ontime
72
+ }: StreamPlayerProps = $props();
73
+
74
+ const isLive = $derived(!src);
75
+ const isOffline = $derived(isLive && !live);
76
+
77
+ let video = $state<HTMLVideoElement>();
78
+ let engine: Engine | undefined;
79
+
80
+ let status = $state<'idle' | 'loading' | 'playing' | 'reconnecting' | 'blocked' | 'failed'>(
81
+ 'idle'
82
+ );
83
+ /** Bumped by "Try again" to start playback from scratch. */
84
+ let attempt = $state(0);
85
+ /** The browser refused sound without a click, so playback started silently. */
86
+ let needsGesture = $state(false);
87
+ let webrtcFailed = $state(false);
88
+ let levels = $state.raw<Level[]>([]);
89
+ let level = $state(-1);
90
+ let rendition = $state('source');
91
+ let latency = $state<number>();
92
+ let fullscreen = $state(false);
93
+ let menu = $state(false);
94
+ let showStats = $state(false);
95
+ let stats = $state.raw<{ bitrate?: number; resolution?: string; dropped?: number }>({});
96
+
97
+ const protocol = $derived(
98
+ !isLive
99
+ ? 'hls'
100
+ : delay === 'low' && !webrtcFailed && typeof RTCPeerConnection !== 'undefined'
101
+ ? 'webrtc'
102
+ : 'hls'
103
+ );
104
+ const qualityOptions = $derived(
105
+ protocol === 'webrtc'
106
+ ? [
107
+ 'source',
108
+ ...new Set(renditions.filter((name) => name !== 'source' && name !== 'audio'))
109
+ ].map((name) => ({ value: name, label: name === 'source' ? 'Source' : name }))
110
+ : levels.length
111
+ ? [
112
+ { value: '-1', label: 'Auto' },
113
+ ...levels.map((item) => ({ value: String(item.index), label: item.label }))
114
+ ]
115
+ : []
116
+ );
117
+ const quality = $derived(protocol === 'webrtc' ? rendition : String(level));
118
+ const behind = $derived(isLive && latency !== undefined && latency > 8);
119
+
120
+ // A different channel or recording starts fresh on WebRTC and source quality.
121
+ // Derived so unrelated prop updates never reset fallback state.
122
+ const streamKey = $derived(`${user ?? ''}\0${src ?? ''}`);
123
+ $effect(() => {
124
+ void streamKey;
125
+ webrtcFailed = false;
126
+ rendition = 'source';
127
+ stats = {};
128
+ });
129
+ $effect(() => {
130
+ if (isOffline) {
131
+ webrtcFailed = false;
132
+ menu = false;
133
+ }
134
+ });
135
+
136
+ async function play() {
137
+ const node = video;
138
+ if (!node) return;
139
+ try {
140
+ await node.play();
141
+ } catch (cause) {
142
+ // Only a refusal counts; a source swapped mid-start is retried by its own engine.
143
+ if (!(cause instanceof DOMException) || cause.name !== 'NotAllowedError') return;
144
+ if (node.muted) return void (status = 'blocked');
145
+ // Browsers refuse sound without a gesture; start silently instead.
146
+ needsGesture = true;
147
+ node.muted = true;
148
+ try {
149
+ await node.play();
150
+ } catch {
151
+ // Muted autoplay was also refused: restore the viewer's mute setting for when
152
+ // they press Play.
153
+ needsGesture = false;
154
+ node.muted = muted;
155
+ status = 'blocked';
156
+ }
157
+ }
158
+ }
159
+
160
+ // (Re)start playback whenever the source, protocol or rendition changes.
161
+ $effect(() => {
162
+ const element = video;
163
+ const source = src;
164
+ const name = user;
165
+ const mode = protocol;
166
+ const chosen = rendition;
167
+ void attempt;
168
+ if (!element || (!source && (!name || !live))) {
169
+ status = 'idle';
170
+ return;
171
+ }
172
+ status = 'loading';
173
+ levels = [];
174
+ const events = {
175
+ // Without autoplay the play button takes over once the media is attached.
176
+ onready: () => (untrack(() => autoplay) ? void play() : (status = 'idle')),
177
+ onwaiting: () => (status = 'reconnecting'),
178
+ onlevels: (list: Level[]) => (levels = list),
179
+ onfail: () => {
180
+ if (mode === 'webrtc') webrtcFailed = true;
181
+ // The engine has stopped trying; say so instead of spinning forever.
182
+ else status = 'failed';
183
+ }
184
+ };
185
+ const next = source
186
+ ? startHls(element, source, events, { live: false, startAt: untrack(() => startAt) })
187
+ : mode === 'webrtc'
188
+ ? startWebRTC(element, whepUrl(name!, chosen), events)
189
+ : startHls(element, livePlaylist(name!), events, { live: true });
190
+ engine = next;
191
+ untrack(() => (level = -1));
192
+ return () => {
193
+ next.destroy();
194
+ if (engine === next) engine = undefined;
195
+ latency = undefined;
196
+ };
197
+ });
198
+
199
+ // The app's remembered volume goes to the element; changes made with the controls come back.
200
+ $effect(() => {
201
+ if (!video) return;
202
+ video.volume = volume;
203
+ if (!needsGesture) video.muted = muted;
204
+ });
205
+ $effect(() => {
206
+ const node = video;
207
+ if (!node) return;
208
+ const changed = () => {
209
+ volume = node.volume;
210
+ if (!needsGesture) muted = node.muted;
211
+ else if (!node.muted) {
212
+ // Unmuted by hand: sound is allowed from here on.
213
+ needsGesture = false;
214
+ muted = false;
215
+ }
216
+ };
217
+ const playing = () => (status = 'playing');
218
+ const time = () => {
219
+ // Some browsers skip `playing` after a stall or a swapped source.
220
+ if (status !== 'playing' && !node.paused && node.readyState > 2) status = 'playing';
221
+ ontime?.(node.currentTime);
222
+ };
223
+ node.addEventListener('volumechange', changed);
224
+ node.addEventListener('playing', playing);
225
+ node.addEventListener('timeupdate', time);
226
+ return () => {
227
+ node.removeEventListener('volumechange', changed);
228
+ node.removeEventListener('playing', playing);
229
+ node.removeEventListener('timeupdate', time);
230
+ };
231
+ });
232
+
233
+ // Latency and stats are polled only while something shows them.
234
+ $effect(() => {
235
+ if (status !== 'playing' || (!isLive && !showStats)) return;
236
+ const wantStats = showStats;
237
+ const timer = setInterval(async () => {
238
+ latency = engine?.latency?.();
239
+ if (wantStats) stats = (await engine?.stats?.()) ?? {};
240
+ }, 1000);
241
+ return () => clearInterval(timer);
242
+ });
243
+
244
+ function retry() {
245
+ webrtcFailed = false;
246
+ attempt += 1;
247
+ }
248
+ function unmute() {
249
+ if (!video) return;
250
+ if (!video.volume) video.volume = 1;
251
+ video.muted = false;
252
+ }
253
+ function toLive() {
254
+ engine?.toLive?.();
255
+ void play();
256
+ }
257
+ async function togglePip() {
258
+ if (document.pictureInPictureElement) await document.exitPictureInPicture().catch(() => {});
259
+ else await video?.requestPictureInPicture?.().catch(() => {});
260
+ }
261
+ function pickQuality(value: string) {
262
+ if (protocol === 'webrtc') rendition = value;
263
+ else {
264
+ level = Number(value);
265
+ engine?.setLevel?.(level);
266
+ }
267
+ }
268
+ function pickDelay(value: string) {
269
+ delay = value as 'low' | 'smooth';
270
+ webrtcFailed = false;
271
+ }
272
+
273
+ let menuButton = $state<HTMLButtonElement>();
274
+ const menuItems = (node: HTMLElement) => [
275
+ ...node.querySelectorAll<HTMLElement>('[role^="menuitem"]')
276
+ ];
277
+ /** Focus starts on the first item, so the arrow keys work at once. */
278
+ function openMenu(node: HTMLElement) {
279
+ menuItems(node)[0]?.focus();
280
+ }
281
+ function menuKey(event: KeyboardEvent & { currentTarget: HTMLElement }) {
282
+ const items = menuItems(event.currentTarget);
283
+ const at = items.indexOf(document.activeElement as HTMLElement);
284
+ const to =
285
+ event.key === 'ArrowDown'
286
+ ? (at + 1) % items.length
287
+ : event.key === 'ArrowUp'
288
+ ? (at - 1 + items.length) % items.length
289
+ : event.key === 'Home'
290
+ ? 0
291
+ : event.key === 'End'
292
+ ? items.length - 1
293
+ : -1;
294
+ if (to < 0) return;
295
+ event.preventDefault();
296
+ // The player's own arrow keys seek; here they only move through the menu.
297
+ event.stopPropagation();
298
+ items[to]?.focus();
299
+ }
300
+
301
+ function onkeydown(event: KeyboardEvent) {
302
+ if (event.key === 'Escape' && menu) {
303
+ menu = false;
304
+ // Back to where the menu was opened from, not to the top of the page.
305
+ menuButton?.focus();
306
+ return event.preventDefault();
307
+ }
308
+ if (isOffline || status === 'failed') return;
309
+ const target = (event.composedPath?.()[0] ?? event.target) as HTMLElement | null;
310
+ if (!target) return;
311
+ if (event.key.toLowerCase() !== 't' || !showTheater || fullscreen) return;
312
+ if (event.metaKey || event.ctrlKey || event.altKey || event.defaultPrevented) return;
313
+ if (target.isContentEditable || /^(INPUT|TEXTAREA|SELECT)$/.test(target.tagName)) return;
314
+ if (shortcuts !== 'page' && !video?.parentElement?.contains(target)) return;
315
+ theater = !theater;
316
+ event.preventDefault();
317
+ }
318
+
319
+ const pipSupported = $derived(
320
+ typeof document !== 'undefined' && Boolean(document.pictureInPictureEnabled)
321
+ );
322
+ const item =
323
+ 'flex w-full cursor-pointer items-center justify-between gap-6 px-3 py-1.5 text-left text-[13px] text-white/90 outline-none hover:bg-white/10 focus-visible:bg-white/10';
324
+ </script>
325
+
326
+ <svelte:window {onkeydown} />
327
+
328
+ {#snippet options(
329
+ heading: string,
330
+ items: { value: string; label: string }[],
331
+ selected: string,
332
+ pick: (value: string) => void
333
+ )}
334
+ <div role="group" aria-label={heading} class="py-1">
335
+ <p class="px-3 py-1 text-[11px] font-medium text-white/60">{heading}</p>
336
+ {#each items as option (option.value)}
337
+ <button
338
+ type="button"
339
+ role="menuitemradio"
340
+ aria-checked={option.value === selected}
341
+ class={item}
342
+ onclick={() => pick(option.value)}
343
+ >
344
+ {option.label}
345
+ {#if option.value === selected}<Icon img={Check} size={15} />{/if}
346
+ </button>
347
+ {/each}
348
+ </div>
349
+ {/snippet}
350
+
351
+ <Player
352
+ bind:video
353
+ bind:controlsVisible
354
+ bind:fullscreen
355
+ {title}
356
+ {poster}
357
+ live={isLive}
358
+ loading={!isOffline && (status === 'loading' || status === 'reconnecting')}
359
+ inactive={isOffline || status === 'failed'}
360
+ keepControls={menu}
361
+ {shortcuts}
362
+ >
363
+ {#snippet liveStatus()}
364
+ <button
365
+ type="button"
366
+ class="ml-1 flex h-7 cursor-pointer items-center gap-1.5 rounded-md px-2 text-xs font-medium text-white hover:bg-white/15 focus-visible:outline-2 focus-visible:outline-white disabled:cursor-default disabled:hover:bg-transparent"
367
+ onclick={toLive}
368
+ disabled={!behind}
369
+ aria-label={behind ? 'Jump to live' : 'Live'}
370
+ >
371
+ <span class={['size-2 rounded-full', behind ? 'bg-white/50' : 'bg-accent-500']}></span>
372
+ {behind ? `${Math.round(latency ?? 0)}s behind` : 'Live'}
373
+ </button>
374
+ {/snippet}
375
+
376
+ {#snippet controls(button)}
377
+ <div class="relative">
378
+ <button
379
+ bind:this={menuButton}
380
+ type="button"
381
+ class={button}
382
+ aria-label="Settings"
383
+ aria-haspopup="menu"
384
+ aria-expanded={menu}
385
+ onclick={() => (menu = !menu)}
386
+ >
387
+ <Icon img={Settings} size={18} />
388
+ </button>
389
+ {#if menu}
390
+ <button
391
+ type="button"
392
+ class="fixed inset-0 cursor-default"
393
+ aria-label="Close settings"
394
+ tabindex="-1"
395
+ onclick={() => (menu = false)}
396
+ ></button>
397
+ <div
398
+ role="menu"
399
+ tabindex="-1"
400
+ {@attach openMenu}
401
+ onkeydown={menuKey}
402
+ aria-label="Settings"
403
+ class="absolute right-0 bottom-11 max-h-72 min-w-44 divide-y divide-white/10 overflow-y-auto rounded-xl bg-zinc-900/95 py-1 shadow-xl ring-1 ring-white/10 backdrop-blur"
404
+ >
405
+ {#if qualityOptions.length > 1}
406
+ {@render options('Quality', qualityOptions, quality, pickQuality)}
407
+ {/if}
408
+ {#if isLive}
409
+ {@render options(
410
+ 'Delay',
411
+ [
412
+ { value: 'low', label: 'Lowest' },
413
+ { value: 'smooth', label: 'Smoother' }
414
+ ],
415
+ protocol === 'webrtc' ? 'low' : 'smooth',
416
+ pickDelay
417
+ )}
418
+ {/if}
419
+ <div class="py-1">
420
+ <button
421
+ type="button"
422
+ role="menuitemcheckbox"
423
+ aria-checked={showStats}
424
+ class={item}
425
+ onclick={() => (showStats = !showStats)}
426
+ >
427
+ Stats
428
+ {#if showStats}<Icon img={Check} size={15} />{/if}
429
+ </button>
430
+ </div>
431
+ </div>
432
+ {/if}
433
+ </div>
434
+ {#if pipSupported}
435
+ <button type="button" class={button} aria-label="Picture in picture" onclick={togglePip}>
436
+ <Icon img={PictureInPicture2} size={18} />
437
+ </button>
438
+ {/if}
439
+ {#if showTheater && !fullscreen}
440
+ <button
441
+ type="button"
442
+ class="{button} max-lg:hidden"
443
+ aria-label={theater ? 'Exit theater mode' : 'Theater mode'}
444
+ aria-pressed={theater}
445
+ onclick={() => (theater = !theater)}
446
+ >
447
+ <Icon img={RectangleHorizontal} size={18} />
448
+ </button>
449
+ {/if}
450
+ {/snippet}
451
+
452
+ {#if isOffline}
453
+ <!-- Above the controls: there is nothing to control. -->
454
+ <div class="absolute inset-0 z-20 bg-black text-white">
455
+ {#if offline}{@render offline()}{:else}
456
+ <p class="grid h-full place-items-center text-sm text-white/80">Offline</p>
457
+ {/if}
458
+ </div>
459
+ {:else if status === 'failed'}
460
+ <div class="absolute inset-0 z-20 grid place-items-center bg-black/80 text-white" role="alert">
461
+ <div class="px-6 text-center">
462
+ <p class="text-sm">This video could not be played.</p>
463
+ <button
464
+ type="button"
465
+ class="mt-3 cursor-pointer rounded-full bg-white px-4 py-2 text-xs font-medium text-black focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-white"
466
+ onclick={retry}
467
+ >
468
+ Try again
469
+ </button>
470
+ </div>
471
+ </div>
472
+ {:else if status === 'reconnecting'}
473
+ <p
474
+ class="pointer-events-none absolute inset-x-0 top-[calc(50%+2rem)] z-10 text-center"
475
+ role="status"
476
+ >
477
+ <span class="rounded-full bg-black/60 px-3 py-1 text-xs text-white">Reconnecting…</span>
478
+ </p>
479
+ {/if}
480
+
481
+ {#if needsGesture && status === 'playing'}
482
+ <button
483
+ type="button"
484
+ class="absolute top-3 left-3 z-10 flex cursor-pointer items-center gap-2 rounded-full bg-white px-3.5 py-2 text-xs font-medium text-black shadow-lg focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-white"
485
+ onclick={unmute}
486
+ >
487
+ <Icon img={VolumeX} size={16} />Unmute
488
+ </button>
489
+ {/if}
490
+
491
+ {#if cornerControls.length && !fullscreen}
492
+ <div
493
+ class={[
494
+ 'absolute top-2 right-2 z-30 flex gap-1 transition-opacity duration-200 motion-reduce:transition-none',
495
+ controlsVisible ? 'opacity-100' : 'pointer-events-none opacity-0'
496
+ ]}
497
+ >
498
+ {#each cornerControls as corner (corner.label)}
499
+ <button
500
+ type="button"
501
+ class="grid size-9 cursor-pointer place-items-center rounded-lg bg-black/50 text-white backdrop-blur-sm hover:bg-black/70 focus-visible:outline-2 focus-visible:outline-white"
502
+ aria-label={corner.label}
503
+ title={corner.label}
504
+ onclick={corner.onclick}
505
+ >
506
+ <Icon img={corner.icon} size={20} />
507
+ </button>
508
+ {/each}
509
+ </div>
510
+ {/if}
511
+
512
+ {#if showStats && !isOffline}
513
+ <dl
514
+ class={[
515
+ cornerControls.length && !fullscreen ? 'top-14' : 'top-3',
516
+ 'absolute right-3 z-10 grid grid-cols-[auto_auto] gap-x-3 gap-y-0.5 rounded-lg bg-black/70 px-3 py-2 font-mono text-[11px] text-white/90'
517
+ ]}
518
+ >
519
+ <dt class="text-white/60">Playback</dt>
520
+ <dd>{protocol === 'webrtc' ? 'WebRTC' : 'HLS'}</dd>
521
+ {#if stats.resolution}
522
+ <dt class="text-white/60">Resolution</dt>
523
+ <dd>{stats.resolution}</dd>
524
+ {/if}
525
+ {#if stats.bitrate}
526
+ <dt class="text-white/60">Bitrate</dt>
527
+ <dd>{(stats.bitrate / 1e6).toFixed(2)} Mbps</dd>
528
+ {/if}
529
+ {#if latency !== undefined}
530
+ <dt class="text-white/60">Latency</dt>
531
+ <dd>{latency.toFixed(1)} s</dd>
532
+ {/if}
533
+ {#if stats.dropped !== undefined}
534
+ <dt class="text-white/60">Dropped</dt>
535
+ <dd>{stats.dropped}</dd>
536
+ {/if}
537
+ </dl>
538
+ {/if}
539
+ </Player>
@@ -0,0 +1,42 @@
1
+ import type { IconNode } from '@sketchyicons/svelte';
2
+ export type StreamPlayerProps = {
3
+ /** Live: the streamer's DID or handle. */
4
+ user?: string;
5
+ /** Whether the stream is live right now. Playback starts and stops with it. */
6
+ live?: boolean;
7
+ /** Transcoded renditions offered for low-delay playback, from `Channel.renditions`. */
8
+ renditions?: string[];
9
+ /** Recording: an HLS playlist, e.g. from `videoPlaylist(uri)`. */
10
+ src?: string;
11
+ /** Start playing as soon as there is something to play. On by default. */
12
+ autoplay?: boolean;
13
+ /** Recording: where to start, in seconds. */
14
+ startAt?: number;
15
+ poster?: string;
16
+ title?: string;
17
+ /** Remembered by the app; changed from the player's own controls. */
18
+ volume?: number;
19
+ muted?: boolean;
20
+ /** `low` plays over WebRTC, `smooth` buffers a few seconds over HLS. */
21
+ delay?: 'low' | 'smooth';
22
+ theater?: boolean;
23
+ /** Offer a theater-mode button (and the `t` key) on wide screens. The page does the layout. */
24
+ showTheater?: boolean;
25
+ /** Page-owned buttons in the top right corner, shown and hidden with the controls. */
26
+ cornerControls?: {
27
+ label: string;
28
+ icon: IconNode;
29
+ onclick: () => void;
30
+ }[];
31
+ /** Whether the controls are on screen, for page elements that appear with them. */
32
+ controlsVisible?: boolean;
33
+ /** Where the keyboard shortcuts work: with focus in the player, or anywhere on the page. */
34
+ shortcuts?: 'focus' | 'page';
35
+ /** Shown instead of the video while a live stream is offline. */
36
+ offline?: Snippet;
37
+ ontime?: (seconds: number) => void;
38
+ };
39
+ import { type Snippet } from 'svelte';
40
+ declare const StreamPlayer: import("svelte").Component<StreamPlayerProps, {}, "delay" | "controlsVisible" | "volume" | "muted" | "theater">;
41
+ type StreamPlayer = ReturnType<typeof StreamPlayer>;
42
+ export default StreamPlayer;