This repository was archived by the owner on Jun 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfishjamSetup.tsx
92 lines (74 loc) · 2.27 KB
/
fishjamSetup.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import { z } from "zod";
import type { ClientEvents } from "@fishjam-dev/react-client";
import { create } from "@fishjam-dev/react-client";
import { useEffect, useState } from "react";
const peerMetadataSchema = z.object({
name: z.string(),
});
const trackMetadataSchema = z.object({
type: z.union([z.literal("camera"), z.literal("microphone"), z.literal("screenshare")]),
mode: z.union([z.literal("auto"), z.literal("manual")]),
});
export type PeerMetadata = z.infer<typeof peerMetadataSchema>;
export type TrackMetadata = z.infer<typeof trackMetadataSchema>;
export const DEFAULT_VIDEO_TRACK_METADATA: TrackMetadata = {
type: "camera",
mode: "auto",
};
export const MANUAL_VIDEO_TRACK_METADATA: TrackMetadata = {
type: "camera",
mode: "manual",
};
export const DEFAULT_AUDIO_TRACK_METADATA: TrackMetadata = {
type: "microphone",
mode: "auto",
};
export const MANUAL_AUDIO_TRACK_METADATA: TrackMetadata = {
type: "microphone",
mode: "manual",
};
export const DEFAULT_SCREEN_SHARE_TRACK_METADATA: TrackMetadata = {
type: "screenshare",
mode: "auto",
};
export const MANUAL_SCREEN_SHARE_TRACK_METADATA: TrackMetadata = {
type: "screenshare",
mode: "manual",
};
export const EXAMPLE_PEER_METADATA: PeerMetadata = {
name: "John Doe",
};
export const {
useStatus,
useConnect,
useDisconnect,
FishjamContextProvider,
useSetupMedia,
useCamera,
useMicrophone,
useScreenShare,
useSelector,
useClient,
} = create<PeerMetadata, TrackMetadata>({
peerMetadataParser: (obj) => peerMetadataSchema.parse(obj),
trackMetadataParser: (obj) => trackMetadataSchema.passthrough().parse(obj),
});
export const useAuthErrorReason = () => {
const client = useClient();
const [authError, setAuthError] = useState<string | null>(null);
useEffect(() => {
const authError: ClientEvents<PeerMetadata, TrackMetadata>["authError"] = (reason) => {
setAuthError(reason);
};
const authSuccess: ClientEvents<PeerMetadata, TrackMetadata>["authSuccess"] = () => {
setAuthError(null);
};
client.on("authError", authError);
client.on("authSuccess", authSuccess);
return () => {
client.removeListener("authError", authError);
client.removeListener("authSuccess", authSuccess);
};
}, [setAuthError, client]);
return authError;
};