@streamplace/components 0.7.35 → 0.8.3
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/components/content-metadata/content-metadata-form.js +467 -0
- package/dist/components/content-metadata/content-rights.js +78 -0
- package/dist/components/content-metadata/content-warnings.js +68 -0
- package/dist/components/content-metadata/index.js +11 -0
- package/dist/components/mobile-player/player.js +4 -0
- package/dist/components/mobile-player/ui/report-modal.js +3 -2
- package/dist/components/ui/checkbox.js +87 -0
- package/dist/components/ui/dialog.js +188 -83
- package/dist/components/ui/primitives/input.js +13 -1
- package/dist/components/ui/primitives/modal.js +2 -2
- package/dist/components/ui/select.js +89 -0
- package/dist/components/ui/textarea.js +23 -4
- package/dist/components/ui/toast.js +464 -114
- package/dist/components/ui/tooltip.js +103 -0
- package/dist/index.js +2 -0
- package/dist/lib/metadata-constants.js +157 -0
- package/dist/lib/theme/theme.js +5 -3
- package/dist/streamplace-provider/index.js +14 -4
- package/dist/streamplace-store/content-metadata-actions.js +124 -0
- package/dist/streamplace-store/streamplace-store.js +22 -5
- package/dist/streamplace-store/user.js +67 -7
- package/node-compile-cache/v22.15.0-x64-efe9a9df-0/37be0eec +0 -0
- package/package.json +3 -3
- package/src/components/content-metadata/content-metadata-form.tsx +893 -0
- package/src/components/content-metadata/content-rights.tsx +104 -0
- package/src/components/content-metadata/content-warnings.tsx +100 -0
- package/src/components/content-metadata/index.tsx +10 -0
- package/src/components/mobile-player/player.tsx +5 -0
- package/src/components/mobile-player/ui/report-modal.tsx +13 -7
- package/src/components/ui/checkbox.tsx +147 -0
- package/src/components/ui/dialog.tsx +319 -99
- package/src/components/ui/primitives/input.tsx +19 -2
- package/src/components/ui/primitives/modal.tsx +4 -2
- package/src/components/ui/select.tsx +175 -0
- package/src/components/ui/textarea.tsx +47 -29
- package/src/components/ui/toast.tsx +785 -179
- package/src/components/ui/tooltip.tsx +131 -0
- package/src/index.tsx +3 -0
- package/src/lib/metadata-constants.ts +180 -0
- package/src/lib/theme/theme.tsx +10 -6
- package/src/streamplace-provider/index.tsx +20 -2
- package/src/streamplace-store/content-metadata-actions.tsx +145 -0
- package/src/streamplace-store/streamplace-store.tsx +41 -4
- package/src/streamplace-store/user.tsx +71 -7
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { forwardRef, useState } from "react";
|
|
2
|
+
import { StyleSheet, View } from "react-native";
|
|
3
|
+
import { useTheme } from "../../lib/theme/theme";
|
|
4
|
+
import { Text } from "../ui/text";
|
|
5
|
+
|
|
6
|
+
export interface TooltipProps {
|
|
7
|
+
content: string;
|
|
8
|
+
children: React.ReactNode;
|
|
9
|
+
position?: "top" | "bottom" | "left" | "right";
|
|
10
|
+
style?: any;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const Tooltip = forwardRef<any, TooltipProps>(
|
|
14
|
+
({ content, children, position = "top", style }, ref) => {
|
|
15
|
+
const { theme } = useTheme();
|
|
16
|
+
const [isVisible, setIsVisible] = useState(false);
|
|
17
|
+
const styles = createStyles(theme, position);
|
|
18
|
+
|
|
19
|
+
const handleHoverIn = () => {
|
|
20
|
+
setIsVisible(true);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const handleHoverOut = () => {
|
|
24
|
+
setIsVisible(false);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
return (
|
|
28
|
+
<View
|
|
29
|
+
ref={ref}
|
|
30
|
+
style={[styles.container, style]}
|
|
31
|
+
onPointerEnter={handleHoverIn}
|
|
32
|
+
onPointerLeave={handleHoverOut}
|
|
33
|
+
>
|
|
34
|
+
{children}
|
|
35
|
+
{isVisible && (
|
|
36
|
+
<View style={styles.tooltip}>
|
|
37
|
+
<Text style={styles.tooltipText}>{content}</Text>
|
|
38
|
+
</View>
|
|
39
|
+
)}
|
|
40
|
+
</View>
|
|
41
|
+
);
|
|
42
|
+
},
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
Tooltip.displayName = "Tooltip";
|
|
46
|
+
|
|
47
|
+
function createStyles(theme: any, position: string) {
|
|
48
|
+
const positionStyles = {
|
|
49
|
+
top: {
|
|
50
|
+
tooltip: {
|
|
51
|
+
bottom: "100%",
|
|
52
|
+
left: "50%",
|
|
53
|
+
transform: [{ translateX: -50 }],
|
|
54
|
+
marginBottom: theme.spacing[1],
|
|
55
|
+
},
|
|
56
|
+
arrow: {
|
|
57
|
+
top: "100%",
|
|
58
|
+
left: "50%",
|
|
59
|
+
transform: [{ translateX: -50 }],
|
|
60
|
+
borderTopColor: theme.colors.card,
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
bottom: {
|
|
64
|
+
tooltip: {
|
|
65
|
+
top: "100%",
|
|
66
|
+
left: "50%",
|
|
67
|
+
transform: [{ translateX: -50 }],
|
|
68
|
+
marginTop: theme.spacing[1],
|
|
69
|
+
},
|
|
70
|
+
arrow: {
|
|
71
|
+
bottom: "100%",
|
|
72
|
+
left: "50%",
|
|
73
|
+
transform: [{ translateX: -50 }],
|
|
74
|
+
borderBottomColor: theme.colors.card,
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
left: {
|
|
78
|
+
tooltip: {
|
|
79
|
+
right: "100%",
|
|
80
|
+
top: "50%",
|
|
81
|
+
transform: [{ translateY: -50 }],
|
|
82
|
+
marginRight: theme.spacing[1],
|
|
83
|
+
},
|
|
84
|
+
arrow: {
|
|
85
|
+
left: "100%",
|
|
86
|
+
top: "50%",
|
|
87
|
+
transform: [{ translateY: -50 }],
|
|
88
|
+
borderLeftColor: theme.colors.card,
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
right: {
|
|
92
|
+
tooltip: {
|
|
93
|
+
left: "100%",
|
|
94
|
+
top: "50%",
|
|
95
|
+
transform: [{ translateY: -50 }],
|
|
96
|
+
marginLeft: theme.spacing[1],
|
|
97
|
+
},
|
|
98
|
+
arrow: {
|
|
99
|
+
right: "100%",
|
|
100
|
+
top: "50%",
|
|
101
|
+
transform: [{ translateY: -50 }],
|
|
102
|
+
borderRightColor: theme.colors.card,
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const currentPosition =
|
|
108
|
+
positionStyles[position as keyof typeof positionStyles];
|
|
109
|
+
|
|
110
|
+
return StyleSheet.create({
|
|
111
|
+
container: {
|
|
112
|
+
position: "relative",
|
|
113
|
+
},
|
|
114
|
+
tooltip: {
|
|
115
|
+
position: "absolute",
|
|
116
|
+
backgroundColor: theme.colors.card,
|
|
117
|
+
borderRadius: theme.borderRadius.md,
|
|
118
|
+
padding: theme.spacing[2],
|
|
119
|
+
maxWidth: 200,
|
|
120
|
+
...theme.shadows.lg,
|
|
121
|
+
...currentPosition.tooltip,
|
|
122
|
+
zIndex: 1000,
|
|
123
|
+
},
|
|
124
|
+
tooltipText: {
|
|
125
|
+
color: theme.colors.text,
|
|
126
|
+
fontSize: 12,
|
|
127
|
+
lineHeight: 16,
|
|
128
|
+
textAlign: "left",
|
|
129
|
+
},
|
|
130
|
+
});
|
|
131
|
+
}
|
package/src/index.tsx
CHANGED
|
@@ -43,3 +43,6 @@ export * as Dashboard from "./components/dashboard";
|
|
|
43
43
|
// Storage exports
|
|
44
44
|
export { default as storage } from "./storage";
|
|
45
45
|
export type { AQStorage } from "./storage/storage.shared";
|
|
46
|
+
|
|
47
|
+
// Content metadata components
|
|
48
|
+
export * from "./components/content-metadata";
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { schemas } from "streamplace";
|
|
2
|
+
|
|
3
|
+
// Content warnings derived from lexicon schema
|
|
4
|
+
export const CONTENT_WARNINGS = (() => {
|
|
5
|
+
// Find the content warnings schema
|
|
6
|
+
const contentWarningsSchema = schemas.find(
|
|
7
|
+
(schema) => schema.id === "place.stream.metadata.contentWarnings",
|
|
8
|
+
);
|
|
9
|
+
if (!contentWarningsSchema?.defs) {
|
|
10
|
+
throw new Error(
|
|
11
|
+
"Could not find place.stream.metadata.contentWarnings schema",
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const contentWarningConstants = [
|
|
16
|
+
{ constant: "place.stream.metadata.contentWarnings#death", label: "Death" },
|
|
17
|
+
{
|
|
18
|
+
constant: "place.stream.metadata.contentWarnings#drugUse",
|
|
19
|
+
label: "Drug Use",
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
constant: "place.stream.metadata.contentWarnings#fantasyViolence",
|
|
23
|
+
label: "Fantasy Violence",
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
constant: "place.stream.metadata.contentWarnings#flashingLights",
|
|
27
|
+
label: "Flashing Lights",
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
constant: "place.stream.metadata.contentWarnings#language",
|
|
31
|
+
label: "Language",
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
constant: "place.stream.metadata.contentWarnings#nudity",
|
|
35
|
+
label: "Nudity",
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
constant: "place.stream.metadata.contentWarnings#PII",
|
|
39
|
+
label: "Personally Identifiable Information",
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
constant: "place.stream.metadata.contentWarnings#sexuality",
|
|
43
|
+
label: "Sexuality",
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
constant: "place.stream.metadata.contentWarnings#suffering",
|
|
47
|
+
label: "Upsetting or Disturbing",
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
constant: "place.stream.metadata.contentWarnings#violence",
|
|
51
|
+
label: "Violence",
|
|
52
|
+
},
|
|
53
|
+
];
|
|
54
|
+
|
|
55
|
+
return contentWarningConstants.map(({ constant, label }) => {
|
|
56
|
+
// Extract the key from the constant by splitting on '#'
|
|
57
|
+
const key = constant.split("#")[1];
|
|
58
|
+
const def = contentWarningsSchema.defs[key];
|
|
59
|
+
const description = def?.description || `Description for ${label}`;
|
|
60
|
+
return {
|
|
61
|
+
value: constant,
|
|
62
|
+
label: label,
|
|
63
|
+
description: description,
|
|
64
|
+
};
|
|
65
|
+
});
|
|
66
|
+
})();
|
|
67
|
+
|
|
68
|
+
// License options derived from lexicon schema
|
|
69
|
+
export const LICENSE_OPTIONS = (() => {
|
|
70
|
+
// Find the content rights schema
|
|
71
|
+
const contentRightsSchema = schemas.find(
|
|
72
|
+
(schema) => schema.id === "place.stream.metadata.contentRights",
|
|
73
|
+
);
|
|
74
|
+
if (!contentRightsSchema?.defs) {
|
|
75
|
+
throw new Error(
|
|
76
|
+
"Could not find place.stream.metadata.contentRights schema",
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const licenseConstants = [
|
|
81
|
+
{
|
|
82
|
+
constant: "place.stream.metadata.contentRights#all-rights-reserved",
|
|
83
|
+
label: "All Rights Reserved",
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
constant: "place.stream.metadata.contentRights#cc0_1__0",
|
|
87
|
+
label: "CC0 (Public Domain) 1.0",
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
constant: "place.stream.metadata.contentRights#cc-by_4__0",
|
|
91
|
+
label: "CC BY 4.0",
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
constant: "place.stream.metadata.contentRights#cc-by-sa_4__0",
|
|
95
|
+
label: "CC BY-SA 4.0",
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
constant: "place.stream.metadata.contentRights#cc-by-nc_4__0",
|
|
99
|
+
label: "CC BY-NC 4.0",
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
constant: "place.stream.metadata.contentRights#cc-by-nc-sa_4__0",
|
|
103
|
+
label: "CC BY-NC-SA 4.0",
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
constant: "place.stream.metadata.contentRights#cc-by-nd_4__0",
|
|
107
|
+
label: "CC BY-ND 4.0",
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
constant: "place.stream.metadata.contentRights#cc-by-nc-nd_4__0",
|
|
111
|
+
label: "CC BY-NC-ND 4.0",
|
|
112
|
+
},
|
|
113
|
+
];
|
|
114
|
+
|
|
115
|
+
const options = licenseConstants.map(({ constant, label }) => {
|
|
116
|
+
// Extract the key from the constant by splitting on '#'
|
|
117
|
+
const key = constant.split("#")[1];
|
|
118
|
+
const def = contentRightsSchema.defs[key];
|
|
119
|
+
const description = def?.description || `Description for ${label}`;
|
|
120
|
+
return {
|
|
121
|
+
value: constant,
|
|
122
|
+
label: label,
|
|
123
|
+
description: description,
|
|
124
|
+
};
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
// Add custom license option
|
|
128
|
+
options.push({
|
|
129
|
+
value: "custom",
|
|
130
|
+
label: "Custom License",
|
|
131
|
+
description:
|
|
132
|
+
"Custom license. Define your own terms for how others can use, adapt, or share your content.",
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
return options;
|
|
136
|
+
})();
|
|
137
|
+
|
|
138
|
+
// License URL labels for C2PA manifests
|
|
139
|
+
export const LICENSE_URL_LABELS: Record<string, string> = {
|
|
140
|
+
"http://creativecommons.org/publicdomain/zero/1.0/":
|
|
141
|
+
"CC0 - Public Domain 1.0",
|
|
142
|
+
"http://creativecommons.org/licenses/by/4.0/": "CC BY - Attribution 4.0",
|
|
143
|
+
"http://creativecommons.org/licenses/by-sa/4.0/":
|
|
144
|
+
"CC BY-SA - Attribution ShareAlike 4.0",
|
|
145
|
+
"http://creativecommons.org/licenses/by-nc/4.0/":
|
|
146
|
+
"CC BY-NC - Attribution NonCommercial 4.0",
|
|
147
|
+
"http://creativecommons.org/licenses/by-nc-sa/4.0/":
|
|
148
|
+
"CC BY-NC-SA - Attribution NonCommercial ShareAlike 4.0",
|
|
149
|
+
"http://creativecommons.org/licenses/by-nd/4.0/":
|
|
150
|
+
"CC BY-ND - Attribution NoDerivatives 4.0",
|
|
151
|
+
"http://creativecommons.org/licenses/by-nc-nd/4.0/":
|
|
152
|
+
"CC BY-NC-ND - Attribution NonCommercial NoDerivatives 4.0",
|
|
153
|
+
"All rights reserved": "All Rights Reserved",
|
|
154
|
+
} as const;
|
|
155
|
+
|
|
156
|
+
// C2PA warning labels for content warnings
|
|
157
|
+
export const C2PA_WARNING_LABELS: Record<string, string> = {
|
|
158
|
+
"cwarn:death": "Death",
|
|
159
|
+
"cwarn:drugUse": "Drug Use",
|
|
160
|
+
"cwarn:fantasyViolence": "Fantasy Violence",
|
|
161
|
+
"cwarn:flashingLights": "Flashing Lights",
|
|
162
|
+
"cwarn:language": "Language",
|
|
163
|
+
"cwarn:nudity": "Nudity",
|
|
164
|
+
"cwarn:PII": "Personally Identifiable Information",
|
|
165
|
+
"cwarn:sexuality": "Sexuality",
|
|
166
|
+
"cwarn:suffering": "Upsetting or Disturbing",
|
|
167
|
+
"cwarn:violence": "Violence",
|
|
168
|
+
// Also support lexicon constants for backward compatibility
|
|
169
|
+
"place.stream.metadata.contentWarnings#death": "Death",
|
|
170
|
+
"place.stream.metadata.contentWarnings#drugUse": "Drug Use",
|
|
171
|
+
"place.stream.metadata.contentWarnings#fantasyViolence": "Fantasy Violence",
|
|
172
|
+
"place.stream.metadata.contentWarnings#flashingLights": "Flashing Lights",
|
|
173
|
+
"place.stream.metadata.contentWarnings#language": "Language",
|
|
174
|
+
"place.stream.metadata.contentWarnings#nudity": "Nudity",
|
|
175
|
+
"place.stream.metadata.contentWarnings#PII":
|
|
176
|
+
"Personally Identifiable Information",
|
|
177
|
+
"place.stream.metadata.contentWarnings#sexuality": "Sexuality",
|
|
178
|
+
"place.stream.metadata.contentWarnings#suffering": "Upsetting or Disturbing",
|
|
179
|
+
"place.stream.metadata.contentWarnings#violence": "Violence",
|
|
180
|
+
} as const;
|
package/src/lib/theme/theme.tsx
CHANGED
|
@@ -84,6 +84,10 @@ export interface Theme {
|
|
|
84
84
|
warning: string;
|
|
85
85
|
warningForeground: string;
|
|
86
86
|
|
|
87
|
+
// Info colors
|
|
88
|
+
info: string;
|
|
89
|
+
infoForeground: string;
|
|
90
|
+
|
|
87
91
|
// Border and input colors
|
|
88
92
|
border: string;
|
|
89
93
|
input: string;
|
|
@@ -344,18 +348,18 @@ function generateThemeColorsFromPalette(
|
|
|
344
348
|
accent: isDark ? palette[800] : palette[100],
|
|
345
349
|
accentForeground: isDark ? palette[50] : palette[900],
|
|
346
350
|
|
|
347
|
-
destructive:
|
|
348
|
-
Platform.OS === "ios" ? colors.ios.systemRed : colors.destructive[500],
|
|
351
|
+
destructive: colors.destructive[700],
|
|
349
352
|
destructiveForeground: colors.white,
|
|
350
353
|
|
|
351
|
-
success:
|
|
352
|
-
Platform.OS === "ios" ? colors.ios.systemGreen : colors.success[500],
|
|
354
|
+
success: colors.success[700],
|
|
353
355
|
successForeground: colors.white,
|
|
354
356
|
|
|
355
|
-
warning:
|
|
356
|
-
Platform.OS === "ios" ? colors.ios.systemOrange : colors.warning[500],
|
|
357
|
+
warning: colors.warning[700],
|
|
357
358
|
warningForeground: colors.white,
|
|
358
359
|
|
|
360
|
+
info: colors.blue[700],
|
|
361
|
+
infoForeground: isDark ? palette[50] : palette[900],
|
|
362
|
+
|
|
359
363
|
border: isDark ? palette[500] + "30" : palette[200] + "30",
|
|
360
364
|
input: isDark ? palette[800] : palette[200],
|
|
361
365
|
ring: Platform.OS === "ios" ? colors.ios.systemBlue : colors.primary[500],
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { SessionManager } from "@atproto/api/dist/session-manager";
|
|
2
2
|
import { useEffect, useRef } from "react";
|
|
3
|
+
import { useGetChatProfile } from "../streamplace-store";
|
|
3
4
|
import { makeStreamplaceStore } from "../streamplace-store/streamplace-store";
|
|
4
5
|
import { StreamplaceContext } from "./context";
|
|
5
6
|
import Poller from "./poller";
|
|
@@ -13,7 +14,6 @@ export function StreamplaceProvider({
|
|
|
13
14
|
url: string;
|
|
14
15
|
oauthSession?: SessionManager | null;
|
|
15
16
|
}) {
|
|
16
|
-
console.log("session in provider is", oauthSession);
|
|
17
17
|
// todo: handle url changes?
|
|
18
18
|
const store = useRef(makeStreamplaceStore({ url })).current;
|
|
19
19
|
|
|
@@ -27,7 +27,25 @@ export function StreamplaceProvider({
|
|
|
27
27
|
|
|
28
28
|
return (
|
|
29
29
|
<StreamplaceContext.Provider value={{ store: store }}>
|
|
30
|
-
<
|
|
30
|
+
<ChatProfileCreator oauthSession={oauthSession}>
|
|
31
|
+
<Poller>{children}</Poller>
|
|
32
|
+
</ChatProfileCreator>
|
|
31
33
|
</StreamplaceContext.Provider>
|
|
32
34
|
);
|
|
33
35
|
}
|
|
36
|
+
|
|
37
|
+
export function ChatProfileCreator({
|
|
38
|
+
oauthSession,
|
|
39
|
+
children,
|
|
40
|
+
}: {
|
|
41
|
+
oauthSession?: SessionManager | null;
|
|
42
|
+
children: React.ReactNode;
|
|
43
|
+
}) {
|
|
44
|
+
const getChatProfile = useGetChatProfile();
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
if (oauthSession) {
|
|
47
|
+
getChatProfile();
|
|
48
|
+
}
|
|
49
|
+
}, [oauthSession]);
|
|
50
|
+
return <>{children}</>;
|
|
51
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { PlaceStreamMetadataConfiguration } from "streamplace";
|
|
2
|
+
import {
|
|
3
|
+
ContentMetadataResult,
|
|
4
|
+
useDID,
|
|
5
|
+
useSetContentMetadata,
|
|
6
|
+
useStreamplaceStore,
|
|
7
|
+
} from "./streamplace-store";
|
|
8
|
+
import { usePDSAgent } from "./xrpc";
|
|
9
|
+
|
|
10
|
+
export const useGetBroadcasterDID = () => {
|
|
11
|
+
const pdsAgent = usePDSAgent();
|
|
12
|
+
const did = useDID();
|
|
13
|
+
const setBroadcasterDID = useStreamplaceStore(
|
|
14
|
+
(state) => state.setBroadcasterDID,
|
|
15
|
+
);
|
|
16
|
+
const setServerDID = useStreamplaceStore((state) => state.setServerDID);
|
|
17
|
+
return async () => {
|
|
18
|
+
if (!pdsAgent || !did) {
|
|
19
|
+
throw new Error("No PDS agent or DID available");
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const result = await pdsAgent.place.stream.broadcast.getBroadcaster();
|
|
23
|
+
if (!result.success) {
|
|
24
|
+
throw new Error("Failed to get broadcaster DID");
|
|
25
|
+
}
|
|
26
|
+
setBroadcasterDID(result.data.broadcaster);
|
|
27
|
+
if (result.data.server) {
|
|
28
|
+
setServerDID(result.data.server);
|
|
29
|
+
} else {
|
|
30
|
+
setServerDID(null);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export const useSaveContentMetadata = () => {
|
|
36
|
+
const pdsAgent = usePDSAgent();
|
|
37
|
+
const did = useDID();
|
|
38
|
+
const setContentMetadata = useSetContentMetadata();
|
|
39
|
+
|
|
40
|
+
return async (metadataRecord: PlaceStreamMetadataConfiguration.Record) => {
|
|
41
|
+
if (!pdsAgent || !did) {
|
|
42
|
+
throw new Error("No PDS agent or DID available");
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
try {
|
|
46
|
+
// Try to update existing record first
|
|
47
|
+
const result = await (pdsAgent as any).com.atproto.repo.putRecord({
|
|
48
|
+
repo: did,
|
|
49
|
+
collection: "place.stream.metadata.configuration",
|
|
50
|
+
rkey: "self",
|
|
51
|
+
record: metadataRecord,
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
const contentMetadata: ContentMetadataResult = {
|
|
55
|
+
record: metadataRecord as any,
|
|
56
|
+
uri: result.data.uri,
|
|
57
|
+
cid: result.data.cid || "",
|
|
58
|
+
rkey: "self",
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
setContentMetadata(contentMetadata);
|
|
62
|
+
return contentMetadata;
|
|
63
|
+
} catch (error) {
|
|
64
|
+
// If record doesn't exist, create it
|
|
65
|
+
if (
|
|
66
|
+
error instanceof Error &&
|
|
67
|
+
(error.message?.includes("not found") ||
|
|
68
|
+
error.message?.includes("RecordNotFound") ||
|
|
69
|
+
error.message?.includes("mst: not found") ||
|
|
70
|
+
(error as any)?.status === 404)
|
|
71
|
+
) {
|
|
72
|
+
const createResult = await (
|
|
73
|
+
pdsAgent as any
|
|
74
|
+
).com.atproto.repo.createRecord({
|
|
75
|
+
repo: did,
|
|
76
|
+
collection: "place.stream.metadata.configuration",
|
|
77
|
+
rkey: "self",
|
|
78
|
+
record: metadataRecord,
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
const contentMetadata: ContentMetadataResult = {
|
|
82
|
+
record: metadataRecord as any,
|
|
83
|
+
uri: createResult.data.uri,
|
|
84
|
+
cid: createResult.data.cid || "",
|
|
85
|
+
rkey: "self",
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
setContentMetadata(contentMetadata);
|
|
89
|
+
return contentMetadata;
|
|
90
|
+
}
|
|
91
|
+
throw error;
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
// Simple get function
|
|
97
|
+
export const useGetContentMetadata = () => {
|
|
98
|
+
const pdsAgent = usePDSAgent();
|
|
99
|
+
const did = useDID();
|
|
100
|
+
const setContentMetadata = useSetContentMetadata();
|
|
101
|
+
|
|
102
|
+
return async (params?: { userDid?: string; rkey?: string }) => {
|
|
103
|
+
if (!pdsAgent) {
|
|
104
|
+
throw new Error("No PDS agent available");
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const targetDid = params?.userDid || did;
|
|
108
|
+
if (!targetDid) {
|
|
109
|
+
throw new Error("No DID provided or user not authenticated");
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
try {
|
|
113
|
+
const result = await (pdsAgent as any).com.atproto.repo.getRecord({
|
|
114
|
+
repo: targetDid,
|
|
115
|
+
collection: "place.stream.metadata.configuration",
|
|
116
|
+
rkey: params?.rkey || "self",
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
if (!result.success) {
|
|
120
|
+
throw new Error("Failed to get content metadata record");
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const contentMetadata: ContentMetadataResult = {
|
|
124
|
+
record: result.data.value,
|
|
125
|
+
uri: result.data.uri,
|
|
126
|
+
cid: result.data.cid || "",
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
setContentMetadata(contentMetadata);
|
|
130
|
+
return contentMetadata;
|
|
131
|
+
} catch (error) {
|
|
132
|
+
// Handle record not found - this is normal for new users
|
|
133
|
+
if (
|
|
134
|
+
error instanceof Error &&
|
|
135
|
+
(error.message?.includes("not found") ||
|
|
136
|
+
error.message?.includes("RecordNotFound") ||
|
|
137
|
+
error.message?.includes("mst: not found") ||
|
|
138
|
+
(error as any)?.status === 404)
|
|
139
|
+
) {
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
throw error;
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
};
|
|
@@ -5,6 +5,13 @@ import { createStore, StoreApi, useStore } from "zustand";
|
|
|
5
5
|
import storage from "../storage";
|
|
6
6
|
import { StreamplaceContext } from "../streamplace-provider/context";
|
|
7
7
|
|
|
8
|
+
export interface ContentMetadataResult {
|
|
9
|
+
record: any;
|
|
10
|
+
uri: string;
|
|
11
|
+
cid: string;
|
|
12
|
+
rkey?: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
8
15
|
// there are three categories of XRPC that we need to handle:
|
|
9
16
|
// 1. Public (probably) OAuth XRPC to the users' PDS for apps that use this API.
|
|
10
17
|
// 2. Confidental OAuth to the Streamplace server for doing things that require
|
|
@@ -33,6 +40,15 @@ export interface StreamplaceState {
|
|
|
33
40
|
handle: string | null;
|
|
34
41
|
chatProfile: PlaceStreamChatProfile.Record | null;
|
|
35
42
|
|
|
43
|
+
// Content metadata state
|
|
44
|
+
contentMetadata: ContentMetadataResult | null;
|
|
45
|
+
setContentMetadata: (metadata: ContentMetadataResult | null) => void;
|
|
46
|
+
|
|
47
|
+
broadcasterDID: string | null;
|
|
48
|
+
setBroadcasterDID: (broadcasterDID: string | null) => void;
|
|
49
|
+
serverDID: string | null;
|
|
50
|
+
setServerDID: (serverDID: string | null) => void;
|
|
51
|
+
|
|
36
52
|
// Volume state
|
|
37
53
|
volume: number;
|
|
38
54
|
muted: boolean;
|
|
@@ -70,6 +86,16 @@ export const makeStreamplaceStore = ({
|
|
|
70
86
|
handle: null,
|
|
71
87
|
chatProfile: null,
|
|
72
88
|
|
|
89
|
+
broadcasterDID: null,
|
|
90
|
+
setBroadcasterDID: (broadcasterDID: string | null) =>
|
|
91
|
+
set({ broadcasterDID }),
|
|
92
|
+
serverDID: null,
|
|
93
|
+
setServerDID: (serverDID: string | null) => set({ serverDID }),
|
|
94
|
+
|
|
95
|
+
// Content metadata
|
|
96
|
+
contentMetadata: null,
|
|
97
|
+
setContentMetadata: (metadata) => set({ contentMetadata: metadata }),
|
|
98
|
+
|
|
73
99
|
// Volume state - start with defaults
|
|
74
100
|
volume: 1.0,
|
|
75
101
|
muted: false,
|
|
@@ -125,13 +151,12 @@ export const makeStreamplaceStore = ({
|
|
|
125
151
|
initialMuted = storedMuted === "true";
|
|
126
152
|
}
|
|
127
153
|
|
|
128
|
-
// Update the store with loaded values
|
|
129
154
|
store.setState({
|
|
130
155
|
volume: initialVolume,
|
|
131
156
|
muted: initialMuted,
|
|
132
157
|
});
|
|
133
|
-
} catch (
|
|
134
|
-
console.
|
|
158
|
+
} catch (error) {
|
|
159
|
+
console.error("Failed to load volume state from storage:", error);
|
|
135
160
|
}
|
|
136
161
|
})();
|
|
137
162
|
|
|
@@ -164,7 +189,17 @@ export const useSetHandle = (): ((handle: string) => void) => {
|
|
|
164
189
|
return (handle: string) => store.setState({ handle });
|
|
165
190
|
};
|
|
166
191
|
|
|
167
|
-
//
|
|
192
|
+
// Content metadata hooks
|
|
193
|
+
export const useContentMetadata = () =>
|
|
194
|
+
useStreamplaceStore((x) => x.contentMetadata);
|
|
195
|
+
|
|
196
|
+
export const useSetContentMetadata = () => {
|
|
197
|
+
const store = getStreamplaceStoreFromContext();
|
|
198
|
+
return (metadata: ContentMetadataResult | null) =>
|
|
199
|
+
store.setState({ contentMetadata: metadata });
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
// Volume/muted hooks
|
|
168
203
|
export const useVolume = () => useStreamplaceStore((x) => x.volume);
|
|
169
204
|
export const useMuted = () => useStreamplaceStore((x) => x.muted);
|
|
170
205
|
export const useSetVolume = () => useStreamplaceStore((x) => x.setVolume);
|
|
@@ -177,3 +212,5 @@ export const useEffectiveVolume = () =>
|
|
|
177
212
|
// Ensure we always return a finite number for HTMLMediaElement.volume
|
|
178
213
|
return Number.isFinite(effectiveVolume) ? effectiveVolume : 1.0;
|
|
179
214
|
});
|
|
215
|
+
|
|
216
|
+
export { useCreateStreamRecord, useUpdateStreamRecord } from "./stream";
|