Live video on the AT Protocol
1import { ComAtprotoModerationCreateReport } from "@atproto/api";
2import { ChatMessageViewHydrated } from "streamplace";
3
4export enum PlayerProtocol {
5 WEBRTC = "webrtc",
6 HLS = "hls",
7 PROGRESSIVE_MP4 = "progressive-mp4",
8 PROGRESSIVE_WEBM = "progressive-webm",
9}
10
11export enum PlayerStatus {
12 START = "start",
13 PLAYING = "playing",
14 STALLED = "stalled",
15 SUSPEND = "suspend",
16 WAITING = "waiting",
17 PAUSE = "pause",
18 MUTE = "mute",
19}
20
21export type PlayerStatusTracker = Partial<Record<PlayerStatus, number>>;
22
23export enum IngestMediaSource {
24 USER = "user",
25 DISPLAY = "display",
26}
27
28export interface PlayerState {
29 id: string;
30 selectedRendition: string;
31 setSelectedRendition: (rendition: string) => void;
32 protocol: PlayerProtocol;
33 setProtocol: (protocol: PlayerProtocol) => void;
34
35 /** Source */
36 src: string;
37
38 /** Function to set the source URL */
39 setSrc: (src: string) => void;
40
41 /** Flag indicating if ingest (stream input) is currently starting */
42 ingestStarting: boolean;
43
44 /** Function to set the ingestStarting flag */
45 setIngestStarting: (ingestStarting: boolean) => void;
46
47 /** Flag indicating if ingest is live */
48 ingestLive: boolean;
49 setIngestLive: (ingestLive: boolean) => void;
50
51 /** Current connection state of ingest RTP/RTC peer connection */
52 ingestConnectionState: RTCPeerConnectionState | null;
53
54 /** Function to update the ingest connection state */
55 setIngestConnectionState: (state: RTCPeerConnectionState | null) => void;
56
57 ingestMediaSource?: IngestMediaSource;
58 setIngestMediaSource?: (source: IngestMediaSource) => void;
59
60 ingestCamera: "user" | "environment";
61 setIngestCamera: (camera: "user" | "environment") => void;
62
63 ingestAutoStart?: boolean;
64 setIngestAutoStart?: (autoStart: boolean) => void;
65
66 /** Timestamp (number) when ingest started, or null if not started */
67 ingestStarted: number | null;
68
69 /** Function to set the ingestStarted timestamp */
70 setIngestStarted: (timestamp: number | null) => void;
71
72 /** Player muted state */
73 muted: boolean;
74
75 /** Function to set the muted state */
76 setMuted: (isMuted: boolean) => void;
77
78 /** Player volume level (0.0 to 1.0) */
79 volume: number;
80
81 /** Function to set the volume level */
82 setVolume: (volume: number) => void;
83
84 /** Player fullscreen state */
85 fullscreen: boolean;
86
87 /** Function to set the fullscreen state */
88 setFullscreen: (isFullscreen: boolean) => void;
89
90 /** Current player status */
91 status: PlayerStatus;
92
93 /** Function to update the player status */
94 setStatus: (status: PlayerStatus) => void;
95
96 /** Current playback time in seconds */
97 playTime: number;
98
99 /** Function to set the current playback time */
100 setPlayTime: (playTime: number) => void;
101
102 /** Flag indicating if player is in offline state */
103 /** Reference to the video element for direct manipulation (used for PiP) */
104 videoRef:
105 | React.MutableRefObject<HTMLVideoElement | null>
106 | ((instance: HTMLVideoElement | null) => void)
107 | null
108 | undefined;
109
110 /** Function to set the video reference */
111 setVideoRef: (
112 videoRef:
113 | React.MutableRefObject<HTMLVideoElement | null>
114 | ((instance: HTMLVideoElement | null) => void)
115 | null
116 | undefined,
117 ) => void;
118
119 pipAction: (() => void) | undefined;
120 /** Function to set the Picture-in-Picture action */
121 setPipAction: (action: (() => void) | undefined) => void;
122
123 /** Player element width (CSS value or number) */
124 playerWidth?: string | number;
125 /** Function to set the player width */
126 setPlayerWidth: (width: number) => void;
127
128 /** Player element height (CSS value or number) */
129 playerHeight?: string | number;
130 /** Function to set the player height */
131 setPlayerHeight: (height: number) => void;
132
133 /** Flag indicating if player is in Picture-in-Picture mode */
134 pipMode: boolean;
135
136 /** Function to set the Picture-in-Picture mode */
137 setPipMode: (pipMode: boolean) => void;
138
139 /** Flag indicating if mute was forced by system (e.g., autoplay policy) */
140 muteWasForced: boolean;
141
142 /** Function to set the muteWasForced flag */
143 setMuteWasForced: (muteWasForced: boolean) => void;
144
145 /** Flag indicating if autoplay failed and needs user interaction */
146 autoplayFailed: boolean;
147
148 /** Function to set the autoplayFailed flag */
149 setAutoplayFailed: (autoplayFailed: boolean) => void;
150
151 /** Flag indicating if the player is embedded in another context */
152 embedded: boolean;
153
154 /** Function to set the embedded flag */
155 setEmbedded: (embedded: boolean) => void;
156
157 /** Flag indicating if player controls should be shown */
158 showControls: boolean;
159 controlsTimeout?: NodeJS.Timeout | undefined;
160
161 /** Function to set the showControls flag */
162 setShowControls: (showControls: boolean) => void;
163
164 telemetry: boolean;
165 setTelemetry: (telemetry: boolean) => void;
166
167 playerEvent: (
168 url: string,
169 time: string,
170 eventType: string,
171 meta: { [key: string]: any },
172 ) => void;
173
174 clearControlsTimeout: () => void;
175
176 setUserInteraction: () => void;
177
178 showDebugInfo: boolean;
179 setShowDebugInfo: (showDebugInfo: boolean) => void;
180
181 /** Message to be moderated */
182 modMessage: ChatMessageViewHydrated | null;
183
184 /** Function to set the mod message */
185 setModMessage: (message: ChatMessageViewHydrated | null) => void;
186
187 /** URL to send player events to (if not default) */
188 reportingURL: string | null;
189
190 /** Function to set the reporting URL */
191 setReportingURL: (reportingURL: string | null) => void;
192
193 /** Is the report modal open? */
194 reportModalOpen: boolean;
195
196 /** Function to set the report modal open state */
197 setReportModalOpen: (reportModalOpen: boolean) => void;
198
199 /** Subject to report */
200 reportSubject: ComAtprotoModerationCreateReport.InputSchema["subject"] | null;
201
202 /** Function to set the report subject */
203 setReportSubject: (
204 subject: ComAtprotoModerationCreateReport.InputSchema["subject"] | null,
205 ) => void;
206}
207
208export type PlayerEvent = {
209 id?: string;
210 time: string;
211 playerId: string;
212 eventType: string;
213 meta: { [key: string]: any };
214};