@atmo-dev/kit 0.20.0 → 0.22.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.
- package/README.md +1 -1
- package/dist/components/RichText.svelte +17 -9
- package/dist/components/RichTextEditor.svelte +67 -11
- package/dist/components/RichTextEditor.svelte.d.ts +0 -2
- package/dist/components/StreamplacePicker.svelte +2 -2
- package/dist/components/StreamplacePicker.svelte.d.ts +1 -1
- package/dist/components/composer/EmojiPanel.svelte +55 -0
- package/dist/components/composer/EmojiPanel.svelte.d.ts +6 -0
- package/dist/components/composer/EmojiPicker.svelte +2 -38
- package/dist/components/data/DataLabel.svelte +120 -0
- package/dist/components/data/DataLabel.svelte.d.ts +10 -0
- package/dist/components/data/issues.d.ts +5 -0
- package/dist/components/data/issues.js +52 -0
- package/dist/components/data/types.d.ts +28 -0
- package/dist/components/data/types.js +1 -0
- package/dist/components/data/visibility.d.ts +7 -0
- package/dist/components/data/visibility.js +15 -0
- package/dist/components/legal/links.js +1 -0
- package/dist/components/legal/types.d.ts +1 -1
- package/dist/components/notifications/NotificationList.svelte +137 -0
- package/dist/components/notifications/NotificationList.svelte.d.ts +19 -0
- package/dist/components/notifications/NotificationPushToggle.svelte +76 -0
- package/dist/components/notifications/NotificationPushToggle.svelte.d.ts +19 -0
- package/dist/components/notifications/NotificationSettings.svelte +125 -0
- package/dist/components/notifications/NotificationSettings.svelte.d.ts +16 -0
- package/dist/components/notifications/types.d.ts +37 -0
- package/dist/components/notifications/types.js +1 -0
- package/dist/editor/ImageDialog.svelte +87 -0
- package/dist/editor/ImageDialog.svelte.d.ts +16 -0
- package/dist/editor/image-node.d.ts +6 -2
- package/dist/editor/image-node.js +36 -37
- package/dist/events/EventCard.svelte +6 -1
- package/dist/events/VodPlayer.svelte +1 -1
- package/dist/events/atmo-rsvp.d.ts +6 -0
- package/dist/events/atmo-rsvp.js +34 -0
- package/dist/events/atproto-helpers.d.ts +1 -0
- package/dist/events/atproto-helpers.js +3 -0
- package/dist/events/event-link-embed.d.ts +7 -3
- package/dist/events/event-link-embed.js +11 -5
- package/dist/events/event-view/StreamPlacePlayer.svelte +14 -108
- package/dist/events/linked-records.d.ts +1 -1
- package/dist/events/linked-records.js +2 -2
- package/dist/events-card.d.ts +9 -0
- package/dist/events-card.js +7 -0
- package/dist/events-data.d.ts +1 -0
- package/dist/events-data.js +1 -0
- package/dist/gestures.d.ts +5 -1
- package/dist/gestures.js +6 -3
- package/dist/grain/xrpc.js +11 -4
- package/dist/index.d.ts +13 -1
- package/dist/index.js +7 -1
- package/dist/legal.d.ts +3 -0
- package/dist/legal.js +2 -0
- package/dist/richtext/serialize.js +13 -8
- package/dist/streamplace/StreamCard.svelte +184 -0
- package/dist/streamplace/StreamCard.svelte.d.ts +24 -0
- package/dist/streamplace/StreamLinkEmbed.svelte +59 -0
- package/dist/streamplace/StreamLinkEmbed.svelte.d.ts +5 -0
- package/dist/streamplace/StreamPlayer.svelte +539 -0
- package/dist/streamplace/StreamPlayer.svelte.d.ts +42 -0
- package/dist/streamplace/VideoCard.svelte +159 -0
- package/dist/streamplace/VideoCard.svelte.d.ts +17 -0
- package/dist/streamplace/api.d.ts +74 -0
- package/dist/streamplace/api.js +182 -0
- package/dist/streamplace/broadcast.d.ts +3 -0
- package/dist/streamplace/broadcast.js +110 -0
- package/dist/streamplace/channel.svelte.d.ts +74 -0
- package/dist/streamplace/channel.svelte.js +515 -0
- package/dist/streamplace/chat/Composer.svelte +232 -0
- package/dist/streamplace/chat/Composer.svelte.d.ts +15 -0
- package/dist/streamplace/chat/Embeds.svelte +135 -0
- package/dist/streamplace/chat/Embeds.svelte.d.ts +13 -0
- package/dist/streamplace/chat/Message.svelte +303 -0
- package/dist/streamplace/chat/Message.svelte.d.ts +25 -0
- package/dist/streamplace/chat/StreamChat.svelte +463 -0
- package/dist/streamplace/chat/StreamChat.svelte.d.ts +33 -0
- package/dist/streamplace/chat/StreamChatPopups.svelte +151 -0
- package/dist/streamplace/chat/StreamChatPopups.svelte.d.ts +15 -0
- package/dist/streamplace/chat/UserCard.svelte +76 -0
- package/dist/streamplace/chat/UserCard.svelte.d.ts +12 -0
- package/dist/streamplace/chat/color.d.ts +7 -0
- package/dist/streamplace/chat/color.js +33 -0
- package/dist/streamplace/chat/links.d.ts +10 -0
- package/dist/streamplace/chat/links.js +29 -0
- package/dist/streamplace/facets.d.ts +15 -0
- package/dist/streamplace/facets.js +112 -0
- package/dist/streamplace/link-embed.d.ts +13 -0
- package/dist/streamplace/link-embed.js +16 -0
- package/dist/streamplace/links.d.ts +6 -0
- package/dist/streamplace/links.js +1 -0
- package/dist/streamplace/reactions.d.ts +21 -0
- package/dist/streamplace/reactions.js +46 -0
- package/dist/streamplace/types.d.ts +200 -0
- package/dist/streamplace/types.js +1 -0
- package/dist/streamplace-data.d.ts +11 -0
- package/dist/streamplace-data.js +10 -0
- package/dist/streamplace.d.ts +14 -6
- package/dist/streamplace.js +11 -1
- package/dist/{events/event-view → video}/Player.svelte +69 -21
- package/dist/video/Player.svelte.d.ts +38 -0
- package/dist/video/engines.d.ts +59 -0
- package/dist/video/engines.js +647 -0
- package/package.json +11 -1
- package/dist/events/event-view/Player.svelte.d.ts +0 -24
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
import type { VideoView } from './types.js';
|
|
3
|
+
|
|
4
|
+
// Playlists of cards in view load a few at a time while the page is idle; the node answers
|
|
5
|
+
// slowly, and a card that is pointed at goes ahead of the queue.
|
|
6
|
+
const waiting: (() => Promise<unknown>)[] = [];
|
|
7
|
+
let running = 0;
|
|
8
|
+
function enqueue(task: () => Promise<unknown>) {
|
|
9
|
+
waiting.push(task);
|
|
10
|
+
drain();
|
|
11
|
+
return () => {
|
|
12
|
+
const at = waiting.indexOf(task);
|
|
13
|
+
if (at >= 0) waiting.splice(at, 1);
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
function drain() {
|
|
17
|
+
while (running < 3 && waiting.length) {
|
|
18
|
+
const task = waiting.shift()!;
|
|
19
|
+
running += 1;
|
|
20
|
+
void task().finally(() => {
|
|
21
|
+
running -= 1;
|
|
22
|
+
drain();
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export type VideoCardProps = {
|
|
28
|
+
video: VideoView;
|
|
29
|
+
/** Where the card leads: a path in this app, or stream.place by default. */
|
|
30
|
+
href?: string;
|
|
31
|
+
/** Leave the author out, e.g. on their own page. */
|
|
32
|
+
showAuthor?: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Load the start of the recording as soon as the card is pointed at, focused or
|
|
35
|
+
* pressed, so the video page that opens next plays at once. On for links within the app.
|
|
36
|
+
*/
|
|
37
|
+
prefetch?: boolean;
|
|
38
|
+
class?: string;
|
|
39
|
+
};
|
|
40
|
+
</script>
|
|
41
|
+
|
|
42
|
+
<script lang="ts">
|
|
43
|
+
import { muted, recess } from '../styles.js';
|
|
44
|
+
import { cn } from '../utils.js';
|
|
45
|
+
import { prefetchHls } from '../video/engines.js';
|
|
46
|
+
import {
|
|
47
|
+
blobImage,
|
|
48
|
+
displayName,
|
|
49
|
+
formatCount,
|
|
50
|
+
formatDuration,
|
|
51
|
+
handleOf,
|
|
52
|
+
rkeyOf,
|
|
53
|
+
timeAgo,
|
|
54
|
+
videoPlaylist
|
|
55
|
+
} from './api.js';
|
|
56
|
+
|
|
57
|
+
let { video, href, showAuthor = true, prefetch, class: className }: VideoCardProps = $props();
|
|
58
|
+
|
|
59
|
+
const link = $derived(
|
|
60
|
+
href ??
|
|
61
|
+
`https://stream.place/${encodeURIComponent(handleOf(video.author))}/video/${encodeURIComponent(rkeyOf(video.uri))}`
|
|
62
|
+
);
|
|
63
|
+
const local = $derived(/^\/(?!\/)/.test(link));
|
|
64
|
+
const thumbnail = $derived(blobImage(video.author.did, video.record.thumb));
|
|
65
|
+
|
|
66
|
+
const enabled = $derived(prefetch ?? local);
|
|
67
|
+
let loadedPoster: string | undefined;
|
|
68
|
+
/** The start of the recording, for a card that is pointed at, focused or pressed. */
|
|
69
|
+
function warm() {
|
|
70
|
+
if (!enabled) return;
|
|
71
|
+
void prefetchHls(videoPlaylist(video.uri), 2);
|
|
72
|
+
// The video page's poster.
|
|
73
|
+
const poster = blobImage(video.author.did, video.record.thumb, 'feed_fullsize');
|
|
74
|
+
if (!poster || poster === loadedPoster) return;
|
|
75
|
+
loadedPoster = poster;
|
|
76
|
+
new Image().src = poster;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** The playlists alone, for a card that comes into view. */
|
|
80
|
+
function inView(node: HTMLElement) {
|
|
81
|
+
if (!enabled || typeof IntersectionObserver === 'undefined') return;
|
|
82
|
+
const uri = video.uri;
|
|
83
|
+
let idle: number | undefined;
|
|
84
|
+
let cancelQueued: (() => void) | undefined;
|
|
85
|
+
const observer = new IntersectionObserver(
|
|
86
|
+
([entry]) => {
|
|
87
|
+
if (!entry?.isIntersecting) return;
|
|
88
|
+
observer.disconnect();
|
|
89
|
+
const queue = () => {
|
|
90
|
+
idle = undefined;
|
|
91
|
+
cancelQueued = enqueue(() => prefetchHls(videoPlaylist(uri), 0));
|
|
92
|
+
};
|
|
93
|
+
idle =
|
|
94
|
+
typeof requestIdleCallback === 'function'
|
|
95
|
+
? requestIdleCallback(queue, { timeout: 1500 })
|
|
96
|
+
: window.setTimeout(queue, 200);
|
|
97
|
+
},
|
|
98
|
+
{ rootMargin: '200px' }
|
|
99
|
+
);
|
|
100
|
+
observer.observe(node);
|
|
101
|
+
return () => {
|
|
102
|
+
observer.disconnect();
|
|
103
|
+
cancelQueued?.();
|
|
104
|
+
if (idle === undefined) return;
|
|
105
|
+
if (typeof cancelIdleCallback === 'function') cancelIdleCallback(idle);
|
|
106
|
+
else clearTimeout(idle);
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
const views = $derived(video.viewCounts?.count ?? 0);
|
|
110
|
+
const byline = $derived(
|
|
111
|
+
[
|
|
112
|
+
showAuthor && displayName(video.author),
|
|
113
|
+
`${formatCount(views)} ${views === 1 ? 'view' : 'views'}`,
|
|
114
|
+
timeAgo(video.record.createdAt)
|
|
115
|
+
]
|
|
116
|
+
.filter(Boolean)
|
|
117
|
+
.join(' · ')
|
|
118
|
+
);
|
|
119
|
+
</script>
|
|
120
|
+
|
|
121
|
+
<a
|
|
122
|
+
href={link}
|
|
123
|
+
target={local ? undefined : '_blank'}
|
|
124
|
+
rel={local ? undefined : 'noopener noreferrer'}
|
|
125
|
+
class={cn(
|
|
126
|
+
'group block min-w-0 text-base-950 no-underline outline-none dark:text-base-50',
|
|
127
|
+
className
|
|
128
|
+
)}
|
|
129
|
+
onpointerenter={warm}
|
|
130
|
+
onpointerdown={warm}
|
|
131
|
+
onfocus={warm}
|
|
132
|
+
{@attach inView}
|
|
133
|
+
>
|
|
134
|
+
<div
|
|
135
|
+
class={cn(
|
|
136
|
+
'relative aspect-video overflow-hidden rounded-ui group-focus-visible:outline-2 group-focus-visible:outline-offset-3 group-focus-visible:outline-accent-700 dark:group-focus-visible:outline-accent-300',
|
|
137
|
+
recess
|
|
138
|
+
)}
|
|
139
|
+
>
|
|
140
|
+
{#if thumbnail}
|
|
141
|
+
<img
|
|
142
|
+
src={thumbnail}
|
|
143
|
+
alt=""
|
|
144
|
+
loading="lazy"
|
|
145
|
+
decoding="async"
|
|
146
|
+
class="size-full object-cover transition-transform duration-300 group-hover:scale-[1.02] motion-reduce:transition-none"
|
|
147
|
+
/>
|
|
148
|
+
{/if}
|
|
149
|
+
{#if video.record.durationMs}
|
|
150
|
+
<span
|
|
151
|
+
class="absolute right-2 bottom-2 rounded-md bg-black/70 px-1.5 py-0.5 text-[11px] font-medium text-white tabular-nums"
|
|
152
|
+
>
|
|
153
|
+
{formatDuration(video.record.durationMs)}
|
|
154
|
+
</span>
|
|
155
|
+
{/if}
|
|
156
|
+
</div>
|
|
157
|
+
<h3 class="mt-2.5 line-clamp-2 text-sm leading-snug font-medium">{video.record.title}</h3>
|
|
158
|
+
<p class={cn('mt-0.5 truncate text-[13px]', muted)}>{byline}</p>
|
|
159
|
+
</a>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { VideoView } from './types.js';
|
|
2
|
+
export type VideoCardProps = {
|
|
3
|
+
video: VideoView;
|
|
4
|
+
/** Where the card leads: a path in this app, or stream.place by default. */
|
|
5
|
+
href?: string;
|
|
6
|
+
/** Leave the author out, e.g. on their own page. */
|
|
7
|
+
showAuthor?: boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Load the start of the recording as soon as the card is pointed at, focused or
|
|
10
|
+
* pressed, so the video page that opens next plays at once. On for links within the app.
|
|
11
|
+
*/
|
|
12
|
+
prefetch?: boolean;
|
|
13
|
+
class?: string;
|
|
14
|
+
};
|
|
15
|
+
declare const VideoCard: import("svelte").Component<VideoCardProps, {}, "">;
|
|
16
|
+
type VideoCard = ReturnType<typeof VideoCard>;
|
|
17
|
+
export default VideoCard;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { Activity, BlobRef, LivestreamView, VideoView } from './types.js';
|
|
2
|
+
export declare const NODE = "https://stream.place";
|
|
3
|
+
export declare const NODE_WS = "wss://stream.place";
|
|
4
|
+
export declare class ApiError extends Error {
|
|
5
|
+
status: number;
|
|
6
|
+
constructor(status: number, message: string);
|
|
7
|
+
}
|
|
8
|
+
type Params = Record<string, string | number | undefined>;
|
|
9
|
+
type Options = {
|
|
10
|
+
fetch?: typeof fetch;
|
|
11
|
+
signal?: AbortSignal;
|
|
12
|
+
};
|
|
13
|
+
export declare function xrpc<T>(method: string, params?: Params, options?: Options): Promise<T>;
|
|
14
|
+
/**
|
|
15
|
+
* Everyone sending video right now, most watched first. `lastSeenAt` on the records is
|
|
16
|
+
* not a liveness signal: some live channels never have it refreshed.
|
|
17
|
+
*/
|
|
18
|
+
export declare function getLiveStreams(options?: Options): Promise<LivestreamView[]>;
|
|
19
|
+
/**
|
|
20
|
+
* The live list, shared for half a minute between browser callers that only need a hint.
|
|
21
|
+
* On the server this fetches fresh per call so in-flight I/O is never shared across requests.
|
|
22
|
+
*/
|
|
23
|
+
export declare function getLiveStreamsCached(): Promise<LivestreamView[]>;
|
|
24
|
+
type PublicProfile = {
|
|
25
|
+
did: string;
|
|
26
|
+
handle: string;
|
|
27
|
+
displayName?: string;
|
|
28
|
+
avatar?: string;
|
|
29
|
+
};
|
|
30
|
+
/** Names and avatars from the public profile index. Accounts it does not know are left out. */
|
|
31
|
+
export declare function fetchProfiles(dids: string[], options?: Options): Promise<Map<string, PublicProfile>>;
|
|
32
|
+
export declare function withProfiles<T extends {
|
|
33
|
+
author: {
|
|
34
|
+
did: string;
|
|
35
|
+
};
|
|
36
|
+
}>(items: T[], options?: Options): Promise<T[]>;
|
|
37
|
+
/** Which of these accounts the viewer follows. Failed lookups count as not followed. */
|
|
38
|
+
export declare function followedAmong(viewer: string, dids: string[], options?: Options): Promise<string[]>;
|
|
39
|
+
export declare function getLivestream(user: string, options?: Options): Promise<LivestreamView | null>;
|
|
40
|
+
export declare const getVideos: (params: {
|
|
41
|
+
repo?: string;
|
|
42
|
+
limit?: number;
|
|
43
|
+
cursor?: string;
|
|
44
|
+
}, o?: Options) => Promise<{
|
|
45
|
+
videos: VideoView[];
|
|
46
|
+
cursor?: string;
|
|
47
|
+
}>;
|
|
48
|
+
export declare const getVideo: (uri: string, o?: Options) => Promise<VideoView>;
|
|
49
|
+
export declare const liveThumbnail: (did: string, bust?: number) => string;
|
|
50
|
+
export declare const blobImage: (did: string, blob?: BlobRef, preset?: string) => string | undefined;
|
|
51
|
+
export declare const livePlaylist: (user: string, rendition?: string) => string;
|
|
52
|
+
export declare const whepUrl: (user: string, rendition?: string) => string;
|
|
53
|
+
export declare const videoPlaylist: (uri: string) => string;
|
|
54
|
+
export declare const activityOptions: {
|
|
55
|
+
value: string;
|
|
56
|
+
label: string;
|
|
57
|
+
}[];
|
|
58
|
+
export declare function activityName(activity?: Activity): string | undefined;
|
|
59
|
+
/** Tags like `lang:en` are metadata, not something to show. */
|
|
60
|
+
export declare const visibleTags: (tags?: string[]) => string[];
|
|
61
|
+
export declare const rkeyOf: (uri: string) => string;
|
|
62
|
+
export declare const displayName: (profile: {
|
|
63
|
+
displayName?: string;
|
|
64
|
+
handle: string;
|
|
65
|
+
did: string;
|
|
66
|
+
}) => string;
|
|
67
|
+
export declare const handleOf: (profile: {
|
|
68
|
+
handle?: string;
|
|
69
|
+
did: string;
|
|
70
|
+
}) => string;
|
|
71
|
+
export declare function formatCount(count: number): string;
|
|
72
|
+
export declare function formatDuration(ms: number): string;
|
|
73
|
+
export declare function timeAgo(date: string | number, now?: number): string;
|
|
74
|
+
export {};
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { appviewUrl, cdnUrl } from '../events/atproto-helpers.js';
|
|
2
|
+
import { isLinkedActor } from '../grain/urls.js';
|
|
3
|
+
// One fixed node; never a user-supplied host.
|
|
4
|
+
export const NODE = 'https://stream.place';
|
|
5
|
+
export const NODE_WS = 'wss://stream.place';
|
|
6
|
+
export class ApiError extends Error {
|
|
7
|
+
status;
|
|
8
|
+
constructor(status, message) {
|
|
9
|
+
super(message);
|
|
10
|
+
this.status = status;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export async function xrpc(method, params = {}, options = {}) {
|
|
14
|
+
const url = new URL(`${NODE}/xrpc/${method}`);
|
|
15
|
+
for (const [key, value] of Object.entries(params)) {
|
|
16
|
+
if (value !== undefined)
|
|
17
|
+
url.searchParams.set(key, String(value));
|
|
18
|
+
}
|
|
19
|
+
const response = await (options.fetch ?? fetch)(url, { signal: options.signal });
|
|
20
|
+
if (!response.ok) {
|
|
21
|
+
const body = (await response.json().catch(() => null));
|
|
22
|
+
throw new ApiError(response.status, body?.message ?? body?.error ?? response.statusText);
|
|
23
|
+
}
|
|
24
|
+
return (await response.json());
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Everyone sending video right now, most watched first. `lastSeenAt` on the records is
|
|
28
|
+
* not a liveness signal: some live channels never have it refreshed.
|
|
29
|
+
*/
|
|
30
|
+
export async function getLiveStreams(options) {
|
|
31
|
+
const { streams } = await xrpc('place.stream.live.getLiveUsers', { limit: 100 }, options);
|
|
32
|
+
return (streams ?? [])
|
|
33
|
+
.filter((stream) => !stream.record.endedAt)
|
|
34
|
+
.sort((a, b) => (b.viewerCount?.count ?? 0) - (a.viewerCount?.count ?? 0));
|
|
35
|
+
}
|
|
36
|
+
let recent;
|
|
37
|
+
/**
|
|
38
|
+
* The live list, shared for half a minute between browser callers that only need a hint.
|
|
39
|
+
* On the server this fetches fresh per call so in-flight I/O is never shared across requests.
|
|
40
|
+
*/
|
|
41
|
+
export function getLiveStreamsCached() {
|
|
42
|
+
if (typeof window === 'undefined')
|
|
43
|
+
return getLiveStreams();
|
|
44
|
+
if (!recent || Date.now() - recent.at > 30_000) {
|
|
45
|
+
const streams = getLiveStreams();
|
|
46
|
+
recent = { at: Date.now(), streams };
|
|
47
|
+
streams.catch(() => {
|
|
48
|
+
if (recent?.streams === streams)
|
|
49
|
+
recent = undefined;
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
return recent.streams;
|
|
53
|
+
}
|
|
54
|
+
/** Names and avatars from the public profile index. Accounts it does not know are left out. */
|
|
55
|
+
export async function fetchProfiles(dids, options = {}) {
|
|
56
|
+
const profiles = new Map();
|
|
57
|
+
const unique = [...new Set(dids)];
|
|
58
|
+
for (let i = 0; i < unique.length; i += 25) {
|
|
59
|
+
if (options.signal?.aborted)
|
|
60
|
+
break;
|
|
61
|
+
const query = unique
|
|
62
|
+
.slice(i, i + 25)
|
|
63
|
+
.map((did) => `actors=${encodeURIComponent(did)}`)
|
|
64
|
+
.join('&');
|
|
65
|
+
const response = await (options.fetch ?? fetch)(`${appviewUrl()}/xrpc/app.bsky.actor.getProfiles?${query}`, { signal: options.signal }).catch(() => null);
|
|
66
|
+
if (!response?.ok)
|
|
67
|
+
continue;
|
|
68
|
+
const body = (await response.json().catch(() => null));
|
|
69
|
+
for (const profile of body?.profiles ?? []) {
|
|
70
|
+
profiles.set(profile.did, {
|
|
71
|
+
did: profile.did,
|
|
72
|
+
handle: profile.handle,
|
|
73
|
+
...(profile.displayName ? { displayName: profile.displayName } : {}),
|
|
74
|
+
...(profile.avatar ? { avatar: profile.avatar } : {})
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return profiles;
|
|
79
|
+
}
|
|
80
|
+
export async function withProfiles(items, options) {
|
|
81
|
+
const profiles = await fetchProfiles(items.map((item) => item.author.did), options);
|
|
82
|
+
return items.map((item) => ({
|
|
83
|
+
...item,
|
|
84
|
+
author: { ...item.author, ...profiles.get(item.author.did) }
|
|
85
|
+
}));
|
|
86
|
+
}
|
|
87
|
+
/** Which of these accounts the viewer follows. Failed lookups count as not followed. */
|
|
88
|
+
export async function followedAmong(viewer, dids, options = {}) {
|
|
89
|
+
const found = new Set();
|
|
90
|
+
const queue = [...new Set(dids)];
|
|
91
|
+
// The node has no batch lookup: one request per account, a few at a time.
|
|
92
|
+
const worker = async () => {
|
|
93
|
+
for (let did = queue.shift(); did; did = queue.shift()) {
|
|
94
|
+
if (options.signal?.aborted)
|
|
95
|
+
break;
|
|
96
|
+
const subject = did;
|
|
97
|
+
await xrpc('place.stream.graph.getFollowingUser', { userDID: viewer, subjectDID: subject }, options)
|
|
98
|
+
.then((result) => result.follow && found.add(subject))
|
|
99
|
+
.catch(() => { });
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
await Promise.all(Array.from({ length: 6 }, worker));
|
|
103
|
+
return dids.filter((did) => found.has(did));
|
|
104
|
+
}
|
|
105
|
+
export async function getLivestream(user, options = {}) {
|
|
106
|
+
const response = await (options.fetch ?? fetch)(`${NODE}/api/livestream/${encodeURIComponent(user)}`, { signal: options.signal });
|
|
107
|
+
if (!response.ok)
|
|
108
|
+
return null;
|
|
109
|
+
const data = (await response.json().catch(() => null));
|
|
110
|
+
return data?.record ? data : null;
|
|
111
|
+
}
|
|
112
|
+
export const getVideos = (params, o) => xrpc('place.stream.media.getVideoList', params, o);
|
|
113
|
+
export const getVideo = (uri, o) => xrpc('place.stream.media.getVideo', { uri }, o);
|
|
114
|
+
export const liveThumbnail = (did, bust) => `${NODE}/api/playback/${encodeURIComponent(did)}/stream.jpg${bust ? `?t=${bust}` : ''}`;
|
|
115
|
+
export const blobImage = (did, blob, preset = 'feed_thumbnail') => {
|
|
116
|
+
const cid = blob?.ref?.$link;
|
|
117
|
+
if (!cid ||
|
|
118
|
+
!did.startsWith('did:') ||
|
|
119
|
+
!isLinkedActor(did) ||
|
|
120
|
+
!/^[A-Za-z0-9_-]+$/.test(cid) ||
|
|
121
|
+
!/^[a-z0-9_]+$/i.test(preset))
|
|
122
|
+
return undefined;
|
|
123
|
+
return `${cdnUrl()}/img/${preset}/plain/${did}/${cid}@jpeg`;
|
|
124
|
+
};
|
|
125
|
+
export const livePlaylist = (user, rendition) => `${NODE}/xrpc/place.stream.playback.getLivePlaylist?streamer=${encodeURIComponent(user)}${rendition ? `&rendition=${encodeURIComponent(rendition)}` : ''}`;
|
|
126
|
+
export const whepUrl = (user, rendition = 'source') => `${NODE}/api/playback/${encodeURIComponent(user)}/webrtc?rendition=${encodeURIComponent(rendition)}`;
|
|
127
|
+
export const videoPlaylist = (uri) => `${NODE}/xrpc/place.stream.playback.getVideoPlaylist?uri=${encodeURIComponent(uri)}&ext=hls.m3u8`;
|
|
128
|
+
const activityLabels = {
|
|
129
|
+
events: 'Events',
|
|
130
|
+
just_chatting: 'Just chatting',
|
|
131
|
+
podcasting: 'Podcasting',
|
|
132
|
+
music: 'Music',
|
|
133
|
+
art: 'Art',
|
|
134
|
+
software_dev: 'Software development',
|
|
135
|
+
cooking: 'Cooking',
|
|
136
|
+
miniatures: 'Miniatures',
|
|
137
|
+
makers_crafting: 'Makers & crafting',
|
|
138
|
+
fitness: 'Fitness',
|
|
139
|
+
sports: 'Sports'
|
|
140
|
+
};
|
|
141
|
+
export const activityOptions = Object.entries(activityLabels).map(([value, label]) => ({
|
|
142
|
+
value,
|
|
143
|
+
label
|
|
144
|
+
}));
|
|
145
|
+
export function activityName(activity) {
|
|
146
|
+
if (!activity)
|
|
147
|
+
return undefined;
|
|
148
|
+
if ('label' in activity)
|
|
149
|
+
return activityLabels[activity.label] ?? activity.label;
|
|
150
|
+
return activity.name;
|
|
151
|
+
}
|
|
152
|
+
/** Tags like `lang:en` are metadata, not something to show. */
|
|
153
|
+
export const visibleTags = (tags) => (tags ?? []).filter((tag) => !tag.includes(':'));
|
|
154
|
+
export const rkeyOf = (uri) => uri.split('/').pop() ?? '';
|
|
155
|
+
export const displayName = (profile) => profile.displayName?.trim() || handleOf(profile);
|
|
156
|
+
export const handleOf = (profile) => profile.handle && profile.handle !== 'handle.invalid' ? profile.handle : profile.did;
|
|
157
|
+
export function formatCount(count) {
|
|
158
|
+
return new Intl.NumberFormat('en', { notation: 'compact', maximumFractionDigits: 1 }).format(count);
|
|
159
|
+
}
|
|
160
|
+
export function formatDuration(ms) {
|
|
161
|
+
const total = Math.max(0, Math.floor(ms / 1000));
|
|
162
|
+
const h = Math.floor(total / 3600);
|
|
163
|
+
const m = Math.floor((total % 3600) / 60);
|
|
164
|
+
const s = total % 60;
|
|
165
|
+
const pad = (n) => String(n).padStart(2, '0');
|
|
166
|
+
return h ? `${h}:${pad(m)}:${pad(s)}` : `${m}:${pad(s)}`;
|
|
167
|
+
}
|
|
168
|
+
export function timeAgo(date, now = Date.now()) {
|
|
169
|
+
const seconds = Math.max(0, (now - new Date(date).getTime()) / 1000);
|
|
170
|
+
const units = [
|
|
171
|
+
[31536000, 'y'],
|
|
172
|
+
[2592000, 'mo'],
|
|
173
|
+
[86400, 'd'],
|
|
174
|
+
[3600, 'h'],
|
|
175
|
+
[60, 'm']
|
|
176
|
+
];
|
|
177
|
+
for (const [size, unit] of units) {
|
|
178
|
+
if (seconds >= size)
|
|
179
|
+
return `${Math.floor(seconds / size)}${unit} ago`;
|
|
180
|
+
}
|
|
181
|
+
return 'just now';
|
|
182
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export type BroadcastState = 'connecting' | 'live' | 'reconnecting' | 'stopped' | 'failed';
|
|
2
|
+
/** Sends a camera or screen capture to the node over WHIP until stopped. */
|
|
3
|
+
export declare function startBroadcast(media: MediaStream, streamKey: string, onstate: (state: BroadcastState) => void): () => void;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { NODE } from './api.js';
|
|
2
|
+
/** How long the node gets to answer one connection attempt. */
|
|
3
|
+
const ANSWER_DEADLINE = 10_000;
|
|
4
|
+
/** Sends a camera or screen capture to the node over WHIP until stopped. */
|
|
5
|
+
export function startBroadcast(media, streamKey, onstate) {
|
|
6
|
+
let stopped = false;
|
|
7
|
+
let pc;
|
|
8
|
+
let retry;
|
|
9
|
+
let attempts = 0;
|
|
10
|
+
let request;
|
|
11
|
+
async function connect() {
|
|
12
|
+
if (stopped)
|
|
13
|
+
return;
|
|
14
|
+
pc?.close();
|
|
15
|
+
const connection = new RTCPeerConnection({ bundlePolicy: 'max-bundle' });
|
|
16
|
+
pc = connection;
|
|
17
|
+
for (const track of media.getTracks()) {
|
|
18
|
+
const transceiver = connection.addTransceiver(track, { direction: 'sendonly' });
|
|
19
|
+
if (track.kind !== 'video')
|
|
20
|
+
continue;
|
|
21
|
+
// The node records H.264; offer it first where the browser can encode it.
|
|
22
|
+
const codecs = RTCRtpSender.getCapabilities?.('video')?.codecs ?? [];
|
|
23
|
+
const h264 = codecs.filter((codec) => codec.mimeType.toLowerCase() === 'video/h264');
|
|
24
|
+
if (h264.length) {
|
|
25
|
+
transceiver.setCodecPreferences?.([
|
|
26
|
+
...h264,
|
|
27
|
+
...codecs.filter((codec) => !h264.includes(codec))
|
|
28
|
+
]);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
connection.onconnectionstatechange = () => {
|
|
32
|
+
if (connection !== pc || stopped)
|
|
33
|
+
return;
|
|
34
|
+
if (connection.connectionState === 'connected') {
|
|
35
|
+
attempts = 0;
|
|
36
|
+
onstate('live');
|
|
37
|
+
}
|
|
38
|
+
else if (connection.connectionState === 'failed') {
|
|
39
|
+
again();
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
try {
|
|
43
|
+
await connection.setLocalDescription(await connection.createOffer());
|
|
44
|
+
await new Promise((resolve) => {
|
|
45
|
+
if (connection.iceGatheringState === 'complete')
|
|
46
|
+
return resolve();
|
|
47
|
+
const timer = setTimeout(resolve, 1000);
|
|
48
|
+
connection.addEventListener('icegatheringstatechange', () => {
|
|
49
|
+
if (connection.iceGatheringState !== 'complete')
|
|
50
|
+
return;
|
|
51
|
+
clearTimeout(timer);
|
|
52
|
+
resolve();
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
// Stopped or superseded while gathering: the stream key must not go out.
|
|
56
|
+
if (stopped || connection !== pc)
|
|
57
|
+
return;
|
|
58
|
+
const attempt = new AbortController();
|
|
59
|
+
request = attempt;
|
|
60
|
+
const deadline = setTimeout(() => attempt.abort(), ANSWER_DEADLINE);
|
|
61
|
+
let response;
|
|
62
|
+
let answer;
|
|
63
|
+
try {
|
|
64
|
+
response = await fetch(`${NODE}/api/ingest/webrtc`, {
|
|
65
|
+
method: 'POST',
|
|
66
|
+
headers: { 'content-type': 'application/sdp', authorization: `Bearer ${streamKey}` },
|
|
67
|
+
body: connection.localDescription?.sdp,
|
|
68
|
+
signal: attempt.signal
|
|
69
|
+
});
|
|
70
|
+
// The deadline covers the body too; a node that stalls mid-answer is retried.
|
|
71
|
+
answer = await response.text();
|
|
72
|
+
}
|
|
73
|
+
finally {
|
|
74
|
+
clearTimeout(deadline);
|
|
75
|
+
}
|
|
76
|
+
if (stopped || connection !== pc)
|
|
77
|
+
return;
|
|
78
|
+
if (response.status === 401 || response.status === 403) {
|
|
79
|
+
stopped = true;
|
|
80
|
+
connection.close();
|
|
81
|
+
return onstate('failed');
|
|
82
|
+
}
|
|
83
|
+
if (!response.ok)
|
|
84
|
+
return again();
|
|
85
|
+
await connection.setRemoteDescription({ type: 'answer', sdp: answer });
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
// A superseded attempt must not schedule a second retry.
|
|
89
|
+
if (connection === pc)
|
|
90
|
+
again();
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
function again() {
|
|
94
|
+
if (stopped)
|
|
95
|
+
return;
|
|
96
|
+
clearTimeout(retry);
|
|
97
|
+
attempts += 1;
|
|
98
|
+
onstate('reconnecting');
|
|
99
|
+
retry = setTimeout(connect, Math.min(8000, 1000 * attempts));
|
|
100
|
+
}
|
|
101
|
+
onstate('connecting');
|
|
102
|
+
void connect();
|
|
103
|
+
return () => {
|
|
104
|
+
stopped = true;
|
|
105
|
+
clearTimeout(retry);
|
|
106
|
+
request?.abort();
|
|
107
|
+
pc?.close();
|
|
108
|
+
onstate('stopped');
|
|
109
|
+
};
|
|
110
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { SvelteMap } from 'svelte/reactivity';
|
|
2
|
+
import { type Reaction } from './reactions.js';
|
|
3
|
+
import type { ChatMessage, ChatProfile, LivestreamView, PinnedRecordView, Problem, ProfileBasic, RecordWriter, Segment, Viewer } from './types.js';
|
|
4
|
+
export type Teleport = {
|
|
5
|
+
uri?: string;
|
|
6
|
+
cid?: string;
|
|
7
|
+
streamer: string;
|
|
8
|
+
startsAt: string;
|
|
9
|
+
};
|
|
10
|
+
/** One streamer's live channel: stream state, viewers and chat over a single socket. */
|
|
11
|
+
export declare class Channel {
|
|
12
|
+
#private;
|
|
13
|
+
readonly user: string;
|
|
14
|
+
connected: boolean;
|
|
15
|
+
/** Whether it is known yet if the stream is live. */
|
|
16
|
+
settled: boolean;
|
|
17
|
+
profile: ProfileBasic | null;
|
|
18
|
+
livestream: LivestreamView | null;
|
|
19
|
+
viewers: number | null;
|
|
20
|
+
viewTotal: number | null;
|
|
21
|
+
segment: Segment | null;
|
|
22
|
+
renditions: string[];
|
|
23
|
+
problems: Problem[];
|
|
24
|
+
messages: ChatMessage[];
|
|
25
|
+
/** Reactions by the message they are on. They are replies of one emoji, kept out of `messages`. */
|
|
26
|
+
reactions: Map<string, Reaction[]>;
|
|
27
|
+
pinned: PinnedRecordView | null;
|
|
28
|
+
teleport: Teleport | null;
|
|
29
|
+
/** Everyone seen in chat, for mentions and name colours. */
|
|
30
|
+
authors: SvelteMap<string, {
|
|
31
|
+
handle: string;
|
|
32
|
+
chatProfile?: ChatProfile;
|
|
33
|
+
}>;
|
|
34
|
+
readonly live: boolean;
|
|
35
|
+
readonly ended: boolean;
|
|
36
|
+
constructor(user: string, initial?: {
|
|
37
|
+
livestream?: LivestreamView | null;
|
|
38
|
+
/** Whether the stream is live, when already known (e.g. from the server). */
|
|
39
|
+
live?: boolean;
|
|
40
|
+
/** Without it the channel is read-only: sending and moderating throw. */
|
|
41
|
+
write?: RecordWriter;
|
|
42
|
+
});
|
|
43
|
+
/** Opens the socket. Does nothing while already connected, connecting or waiting to retry. */
|
|
44
|
+
connect(): void;
|
|
45
|
+
/** Closes the socket and drops anything not yet applied. `connect()` starts again. */
|
|
46
|
+
close(): void;
|
|
47
|
+
/**
|
|
48
|
+
* Applies events as if the node had sent them: history an app loaded itself, or fixtures
|
|
49
|
+
* in tests and examples. The socket is not needed for this.
|
|
50
|
+
*/
|
|
51
|
+
receive(events: object[]): void;
|
|
52
|
+
/** Resolves a mentioned handle from chat first, then from the network. */
|
|
53
|
+
resolveHandle(handle: string): Promise<string | undefined>;
|
|
54
|
+
/** Shows the message at once and writes it to the sender's repository. */
|
|
55
|
+
send(text: string, viewer: Viewer, replyTo?: ChatMessage | null): Promise<void>;
|
|
56
|
+
/** Adds the viewer's reaction to a message, or takes it back if it is already there. */
|
|
57
|
+
react(target: ChatMessage, emoji: string, viewer: Viewer): Promise<void>;
|
|
58
|
+
/** Deletes one of the viewer's own messages. It comes back if that fails. */
|
|
59
|
+
remove(uri: string): Promise<void>;
|
|
60
|
+
/** Streamer: hides someone's message from this chat. It comes back if that fails. */
|
|
61
|
+
hide(uri: string): Promise<void>;
|
|
62
|
+
/** Streamer: pins a message above the chat. */
|
|
63
|
+
pin(uri: string): Promise<void>;
|
|
64
|
+
/** Streamer: removes the pinned message. */
|
|
65
|
+
unpin(): Promise<void>;
|
|
66
|
+
/**
|
|
67
|
+
* Streamer: bans an account from this chat. This blocks the account. Their messages go
|
|
68
|
+
* once the block is written, so a failed ban changes nothing on screen.
|
|
69
|
+
*/
|
|
70
|
+
ban(did: string): Promise<void>;
|
|
71
|
+
/** Removes a message from this tab right away; the network confirms later. */
|
|
72
|
+
hideLocally(uri: string): void;
|
|
73
|
+
banLocally(did: string): void;
|
|
74
|
+
}
|