@dialtribe/react-sdk 0.1.0-alpha.10
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/LICENSE +21 -0
- package/README.md +535 -0
- package/dist/broadcast-player-CEAnuf6t.d.mts +559 -0
- package/dist/broadcast-player-CEAnuf6t.d.ts +559 -0
- package/dist/broadcast-player.d.mts +3 -0
- package/dist/broadcast-player.d.ts +3 -0
- package/dist/broadcast-player.js +2184 -0
- package/dist/broadcast-player.js.map +1 -0
- package/dist/broadcast-player.mjs +2164 -0
- package/dist/broadcast-player.mjs.map +1 -0
- package/dist/broadcast-streamer.d.mts +330 -0
- package/dist/broadcast-streamer.d.ts +330 -0
- package/dist/broadcast-streamer.js +3758 -0
- package/dist/broadcast-streamer.js.map +1 -0
- package/dist/broadcast-streamer.mjs +3724 -0
- package/dist/broadcast-streamer.mjs.map +1 -0
- package/dist/hello-world.d.mts +12 -0
- package/dist/hello-world.d.ts +12 -0
- package/dist/hello-world.js +27 -0
- package/dist/hello-world.js.map +1 -0
- package/dist/hello-world.mjs +25 -0
- package/dist/hello-world.mjs.map +1 -0
- package/dist/index.d.mts +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +3776 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +3742 -0
- package/dist/index.mjs.map +1 -0
- package/dist/styles.css +3 -0
- package/package.json +91 -0
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
export { A as ApiClientConfig, i as AudioWaveform, j as Broadcast, B as BroadcastPlayer, h as BroadcastPlayerErrorBoundary, f as BroadcastPlayerModal, g as BroadcastPlayerModalProps, e as BroadcastPlayerProps, C as CDN_DOMAIN, d as DIALTRIBE_API_BASE, c as DialTribeClient, a as DialTribeContextValue, D as DialTribeProvider, b as DialTribeProviderProps, E as ENDPOINTS, H as HTTP_STATUS, p as HttpStatusCode, L as LoadingSpinner, l as TranscriptData, k as TranscriptSegment, T as TranscriptWord, n as buildBroadcastCdnUrl, o as buildBroadcastS3KeyPrefix, m as formatTime, u as useDialTribe, q as useDialTribeOptional } from './broadcast-player-CEAnuf6t.mjs';
|
|
2
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
3
|
+
import { RefObject } from 'react';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Props for the BroadcastStreamer component.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```tsx
|
|
10
|
+
* // Inside DialTribeProvider (recommended)
|
|
11
|
+
* <DialTribeProvider sessionToken={token}>
|
|
12
|
+
* <BroadcastStreamer
|
|
13
|
+
* streamKey={keyFromBackend}
|
|
14
|
+
* onDone={() => window.close()}
|
|
15
|
+
* />
|
|
16
|
+
* </DialTribeProvider>
|
|
17
|
+
*
|
|
18
|
+
* // Standalone (e.g., popup window)
|
|
19
|
+
* <BroadcastStreamer
|
|
20
|
+
* sessionToken={token}
|
|
21
|
+
* streamKey={keyFromBackend}
|
|
22
|
+
* onDone={() => window.close()}
|
|
23
|
+
* />
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
interface BroadcastStreamerProps {
|
|
27
|
+
/**
|
|
28
|
+
* Session token for API authentication.
|
|
29
|
+
*
|
|
30
|
+
* Required for permission checks. Can be provided via:
|
|
31
|
+
* 1. DialTribeProvider context (recommended for main app)
|
|
32
|
+
* 2. This prop (required for popup windows)
|
|
33
|
+
*
|
|
34
|
+
* Must include `broadcasts:stream` permission.
|
|
35
|
+
*/
|
|
36
|
+
sessionToken?: string;
|
|
37
|
+
/**
|
|
38
|
+
* Stream key for broadcasting.
|
|
39
|
+
*
|
|
40
|
+
* **Production apps should always provide this from their backend.**
|
|
41
|
+
* The stream key authenticates the broadcaster with the encoder server.
|
|
42
|
+
*
|
|
43
|
+
* If omitted, a manual input form is shown. This is intended for
|
|
44
|
+
* development/testing only - end users should never see or handle stream keys.
|
|
45
|
+
*
|
|
46
|
+
* @example "w1_abc123def456..."
|
|
47
|
+
*/
|
|
48
|
+
streamKey?: string;
|
|
49
|
+
/**
|
|
50
|
+
* Called when streaming ends (user stops, terminates, or clicks Done).
|
|
51
|
+
* Use this to close the popup or navigate away.
|
|
52
|
+
*
|
|
53
|
+
* @example () => window.close()
|
|
54
|
+
*/
|
|
55
|
+
onDone?: () => void;
|
|
56
|
+
/**
|
|
57
|
+
* Called when the stream key changes (e.g., user edits it in preview mode).
|
|
58
|
+
* Useful for persisting the key or updating parent state.
|
|
59
|
+
*/
|
|
60
|
+
onStreamKeyChange?: (key: string) => void;
|
|
61
|
+
/**
|
|
62
|
+
* Custom encoder server URL. Defaults to DialTribe's production encoder.
|
|
63
|
+
* Only change this for self-hosted encoder deployments.
|
|
64
|
+
*
|
|
65
|
+
* @default "https://broadcastapi.dialtribe.com"
|
|
66
|
+
*/
|
|
67
|
+
encoderServerUrl?: string;
|
|
68
|
+
/**
|
|
69
|
+
* Custom API base URL for broadcast availability checks.
|
|
70
|
+
* Only change this for self-hosted API deployments.
|
|
71
|
+
*
|
|
72
|
+
* @default "https://dialtribe.com/api/public/v1"
|
|
73
|
+
*/
|
|
74
|
+
apiBaseUrl?: string;
|
|
75
|
+
/**
|
|
76
|
+
* When true, the streamer fills its parent container instead of the viewport.
|
|
77
|
+
* Use this when embedding the streamer inline within a page.
|
|
78
|
+
*
|
|
79
|
+
* @default false
|
|
80
|
+
*/
|
|
81
|
+
inline?: boolean;
|
|
82
|
+
}
|
|
83
|
+
declare function BroadcastStreamer({ sessionToken: propSessionToken, streamKey: initialStreamKey, onDone, onStreamKeyChange, encoderServerUrl, apiBaseUrl, inline, }: BroadcastStreamerProps): react_jsx_runtime.JSX.Element;
|
|
84
|
+
|
|
85
|
+
interface StreamingPreviewProps {
|
|
86
|
+
videoRef: RefObject<HTMLVideoElement>;
|
|
87
|
+
isVideoKey: boolean;
|
|
88
|
+
isVideoEnabled: boolean;
|
|
89
|
+
mediaStream: MediaStream | null;
|
|
90
|
+
facingMode: "user" | "environment";
|
|
91
|
+
}
|
|
92
|
+
declare function StreamingPreview({ videoRef, isVideoKey, isVideoEnabled, mediaStream, facingMode, }: StreamingPreviewProps): react_jsx_runtime.JSX.Element;
|
|
93
|
+
|
|
94
|
+
type StreamingControlState = "previewing" | "connecting" | "live" | "stopping";
|
|
95
|
+
interface MediaDeviceInfo {
|
|
96
|
+
deviceId: string;
|
|
97
|
+
label: string;
|
|
98
|
+
}
|
|
99
|
+
interface StreamingControlsProps {
|
|
100
|
+
state: StreamingControlState;
|
|
101
|
+
isVideoKey: boolean;
|
|
102
|
+
isMuted: boolean;
|
|
103
|
+
isVideoEnabled: boolean;
|
|
104
|
+
facingMode: "user" | "environment";
|
|
105
|
+
hasMultipleCameras: boolean;
|
|
106
|
+
startTime: Date | null;
|
|
107
|
+
bytesSent: number;
|
|
108
|
+
showStopConfirm: boolean;
|
|
109
|
+
streamKey: string;
|
|
110
|
+
onStreamKeyChange?: (newKey: string) => void;
|
|
111
|
+
onStart: () => void;
|
|
112
|
+
onStop: () => void;
|
|
113
|
+
onConfirmStop: () => void;
|
|
114
|
+
onCancelStop: () => void;
|
|
115
|
+
onToggleMute: () => void;
|
|
116
|
+
onToggleVideo: () => void;
|
|
117
|
+
onFlipCamera: () => void;
|
|
118
|
+
onClose?: () => void;
|
|
119
|
+
showCloseConfirm?: boolean;
|
|
120
|
+
onConfirmClose?: () => void;
|
|
121
|
+
onCancelClose?: () => void;
|
|
122
|
+
videoDevices?: MediaDeviceInfo[];
|
|
123
|
+
audioDevices?: MediaDeviceInfo[];
|
|
124
|
+
selectedVideoDeviceId?: string;
|
|
125
|
+
selectedAudioDeviceId?: string;
|
|
126
|
+
onVideoDeviceChange?: (deviceId: string) => void;
|
|
127
|
+
onAudioDeviceChange?: (deviceId: string) => void;
|
|
128
|
+
mediaStream?: MediaStream | null;
|
|
129
|
+
}
|
|
130
|
+
declare function StreamingControls({ state, isVideoKey, isMuted, isVideoEnabled, facingMode: _facingMode, // Reserved for future use (e.g., showing camera direction)
|
|
131
|
+
hasMultipleCameras, startTime, bytesSent, showStopConfirm, streamKey, onStreamKeyChange, onStart, onStop, onConfirmStop, onCancelStop, onToggleMute, onToggleVideo, onFlipCamera, onClose, showCloseConfirm, onConfirmClose, onCancelClose, videoDevices, audioDevices, selectedVideoDeviceId, selectedAudioDeviceId, onVideoDeviceChange, onAudioDeviceChange, mediaStream, }: StreamingControlsProps): react_jsx_runtime.JSX.Element;
|
|
132
|
+
|
|
133
|
+
interface StreamKeyDisplayProps {
|
|
134
|
+
streamKey: string;
|
|
135
|
+
className?: string;
|
|
136
|
+
showLabel?: boolean;
|
|
137
|
+
showCopy?: boolean;
|
|
138
|
+
editable?: boolean;
|
|
139
|
+
onChange?: (newKey: string) => void;
|
|
140
|
+
size?: 'sm' | 'md' | 'lg';
|
|
141
|
+
layout?: 'vertical' | 'horizontal';
|
|
142
|
+
darkMode?: boolean;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Shared component for displaying stream keys with reveal/copy functionality
|
|
146
|
+
* Obscures the stream key by default, showing only first 6 and last 6 characters
|
|
147
|
+
* When revealed and editable, becomes an input field for editing
|
|
148
|
+
*/
|
|
149
|
+
declare function StreamKeyDisplay({ streamKey, className, showLabel, showCopy, editable, onChange, size, layout, darkMode, }: StreamKeyDisplayProps): react_jsx_runtime.JSX.Element;
|
|
150
|
+
|
|
151
|
+
interface StreamKeyInputProps {
|
|
152
|
+
onSubmit: (key: string) => void;
|
|
153
|
+
/**
|
|
154
|
+
* When true, the input fills its parent container instead of the viewport.
|
|
155
|
+
* Use this when embedding inline within a page.
|
|
156
|
+
*/
|
|
157
|
+
inline?: boolean;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Stream key input form for manual entry
|
|
161
|
+
* Validates stream key format before submission
|
|
162
|
+
*/
|
|
163
|
+
declare function StreamKeyInput({ onSubmit, inline }: StreamKeyInputProps): react_jsx_runtime.JSX.Element;
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* WebSocket streaming client for sending media chunks to encoder server
|
|
167
|
+
* Based on prankcast reference implementation
|
|
168
|
+
*/
|
|
169
|
+
/** Default encoder server URL */
|
|
170
|
+
declare const DEFAULT_ENCODER_SERVER_URL = "https://broadcastapi.dialtribe.com";
|
|
171
|
+
interface WebSocketStreamerOptions {
|
|
172
|
+
streamKey: string;
|
|
173
|
+
mediaStream: MediaStream;
|
|
174
|
+
isVideo: boolean;
|
|
175
|
+
/** Optional custom encoder server URL (defaults to DEFAULT_ENCODER_SERVER_URL) */
|
|
176
|
+
encoderServerUrl?: string;
|
|
177
|
+
onBytesUpdate?: (bytes: number) => void;
|
|
178
|
+
onStateChange?: (state: "connecting" | "live" | "stopped" | "terminated" | "error") => void;
|
|
179
|
+
onError?: (error: string) => void;
|
|
180
|
+
}
|
|
181
|
+
declare class WebSocketStreamer {
|
|
182
|
+
private streamKey;
|
|
183
|
+
private mediaStream;
|
|
184
|
+
private isVideo;
|
|
185
|
+
private encoderServerUrl;
|
|
186
|
+
private websocket;
|
|
187
|
+
private mediaRecorder;
|
|
188
|
+
private bytesSent;
|
|
189
|
+
private userStopped;
|
|
190
|
+
private onBytesUpdate?;
|
|
191
|
+
private onStateChange?;
|
|
192
|
+
private onError?;
|
|
193
|
+
constructor(options: WebSocketStreamerOptions);
|
|
194
|
+
/**
|
|
195
|
+
* Validate stream key format
|
|
196
|
+
* Stream keys must follow format: {tierCode}{foreignId}_{randomKey}
|
|
197
|
+
* Tier codes: a (audio shared), b (audio VIP), v (video shared), w (video VIP)
|
|
198
|
+
*/
|
|
199
|
+
private validateStreamKeyFormat;
|
|
200
|
+
/**
|
|
201
|
+
* Build WebSocket URL from stream key
|
|
202
|
+
*/
|
|
203
|
+
private buildWebSocketUrl;
|
|
204
|
+
/**
|
|
205
|
+
* Start streaming
|
|
206
|
+
*/
|
|
207
|
+
start(): Promise<void>;
|
|
208
|
+
/**
|
|
209
|
+
* Stop streaming
|
|
210
|
+
*/
|
|
211
|
+
stop(): void;
|
|
212
|
+
/**
|
|
213
|
+
* Get total bytes sent
|
|
214
|
+
*/
|
|
215
|
+
getBytesSent(): number;
|
|
216
|
+
/**
|
|
217
|
+
* Update the media stream (e.g., when flipping camera)
|
|
218
|
+
* This keeps the WebSocket connection alive while swapping the media source
|
|
219
|
+
*
|
|
220
|
+
* Note: Errors are thrown to the caller, not sent to onError callback
|
|
221
|
+
* This allows the caller to handle camera flip failures gracefully
|
|
222
|
+
*/
|
|
223
|
+
updateMediaStream(newMediaStream: MediaStream): Promise<void>;
|
|
224
|
+
/**
|
|
225
|
+
* Set up WebSocket event handlers
|
|
226
|
+
*/
|
|
227
|
+
private setupWebSocketHandlers;
|
|
228
|
+
/**
|
|
229
|
+
* Set up MediaRecorder event handlers
|
|
230
|
+
*/
|
|
231
|
+
private setupMediaRecorderHandlers;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Media constraints for browser streaming
|
|
236
|
+
* Based on prankcast reference implementation
|
|
237
|
+
*/
|
|
238
|
+
interface MediaConstraintsOptions {
|
|
239
|
+
isVideo: boolean;
|
|
240
|
+
facingMode?: "user" | "environment";
|
|
241
|
+
}
|
|
242
|
+
declare function getMediaConstraints(options: MediaConstraintsOptions): MediaStreamConstraints;
|
|
243
|
+
/**
|
|
244
|
+
* MediaRecorder options for encoding
|
|
245
|
+
*/
|
|
246
|
+
declare function getMediaRecorderOptions(isVideo: boolean): MediaRecorderOptions;
|
|
247
|
+
/**
|
|
248
|
+
* Check browser compatibility
|
|
249
|
+
*/
|
|
250
|
+
declare function checkBrowserCompatibility(): {
|
|
251
|
+
compatible: boolean;
|
|
252
|
+
error?: string;
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Utility functions for opening broadcast streamer popup windows
|
|
257
|
+
*/
|
|
258
|
+
interface PopupDimensions {
|
|
259
|
+
width: number;
|
|
260
|
+
height: number;
|
|
261
|
+
left: number;
|
|
262
|
+
top: number;
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Calculate optimal popup dimensions based on screen size
|
|
266
|
+
* - Desktop/wider screens: 16:9 landscape ratio (e.g., 1280x720) to match modern webcams
|
|
267
|
+
* - Mobile/narrower screens: 9:16 portrait ratio (e.g., 720x1280) for vertical video
|
|
268
|
+
*/
|
|
269
|
+
declare function calculatePopupDimensions(): PopupDimensions;
|
|
270
|
+
type BroadcastMode = 'live' | 'schedule' | null;
|
|
271
|
+
/**
|
|
272
|
+
* Options for opening a broadcast streamer popup window.
|
|
273
|
+
*/
|
|
274
|
+
interface OpenBroadcastStreamerPopupOptions {
|
|
275
|
+
/**
|
|
276
|
+
* Session token for API authentication. **Required.**
|
|
277
|
+
* The token must include `broadcasts:stream` permission.
|
|
278
|
+
* Sent securely via postMessage (not in the URL).
|
|
279
|
+
*/
|
|
280
|
+
sessionToken: string;
|
|
281
|
+
/**
|
|
282
|
+
* Stream key for broadcasting. **Required for production use.**
|
|
283
|
+
* Fetch this from your backend and pass it here.
|
|
284
|
+
* The key is sent securely via postMessage (not in the URL).
|
|
285
|
+
*
|
|
286
|
+
* @example "w1_abc123def456..."
|
|
287
|
+
*/
|
|
288
|
+
streamKey: string;
|
|
289
|
+
/** Optional app ID to include in the postMessage payload */
|
|
290
|
+
appId?: number;
|
|
291
|
+
/**
|
|
292
|
+
* Launch mode. Use 'live' for immediate streaming.
|
|
293
|
+
* @default 'live'
|
|
294
|
+
*/
|
|
295
|
+
mode?: BroadcastMode;
|
|
296
|
+
/** Additional URL parameters to pass to the popup page */
|
|
297
|
+
additionalParams?: Record<string, string>;
|
|
298
|
+
/**
|
|
299
|
+
* Base URL for the streamer page.
|
|
300
|
+
* Only change this for custom hosting setups.
|
|
301
|
+
* @default "/broadcasts/new"
|
|
302
|
+
*/
|
|
303
|
+
baseUrl?: string;
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Open broadcast streamer popup window with credentials sent via postMessage
|
|
307
|
+
* This is more secure than passing sensitive data in the URL
|
|
308
|
+
*
|
|
309
|
+
* @example
|
|
310
|
+
* ```tsx
|
|
311
|
+
* import { openBroadcastStreamerPopup } from '@dialtribe/react-sdk/broadcast-streamer';
|
|
312
|
+
*
|
|
313
|
+
* // Open popup for live streaming
|
|
314
|
+
* openBroadcastStreamerPopup({
|
|
315
|
+
* sessionToken: 'sess_xxx...',
|
|
316
|
+
* streamKey: 'w1_abc123...',
|
|
317
|
+
* mode: 'live',
|
|
318
|
+
* });
|
|
319
|
+
* ```
|
|
320
|
+
*
|
|
321
|
+
* @returns The popup window reference, or null if popup was blocked
|
|
322
|
+
*/
|
|
323
|
+
declare function openBroadcastStreamerPopup(options: OpenBroadcastStreamerPopupOptions): Window | null;
|
|
324
|
+
/**
|
|
325
|
+
* Legacy function name for backwards compatibility
|
|
326
|
+
* @deprecated Use openBroadcastStreamerPopup instead
|
|
327
|
+
*/
|
|
328
|
+
declare const openBroadcastPopup: typeof openBroadcastStreamerPopup;
|
|
329
|
+
|
|
330
|
+
export { type BroadcastMode, BroadcastStreamer, type BroadcastStreamerProps, DEFAULT_ENCODER_SERVER_URL, type MediaConstraintsOptions, type OpenBroadcastStreamerPopupOptions, type PopupDimensions, StreamKeyDisplay, type StreamKeyDisplayProps, StreamKeyInput, type StreamKeyInputProps, type StreamingControlState, StreamingControls, type StreamingControlsProps, StreamingPreview, type StreamingPreviewProps, WebSocketStreamer, type WebSocketStreamerOptions, calculatePopupDimensions, checkBrowserCompatibility, getMediaConstraints, getMediaRecorderOptions, openBroadcastPopup, openBroadcastStreamerPopup };
|
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
export { A as ApiClientConfig, i as AudioWaveform, j as Broadcast, B as BroadcastPlayer, h as BroadcastPlayerErrorBoundary, f as BroadcastPlayerModal, g as BroadcastPlayerModalProps, e as BroadcastPlayerProps, C as CDN_DOMAIN, d as DIALTRIBE_API_BASE, c as DialTribeClient, a as DialTribeContextValue, D as DialTribeProvider, b as DialTribeProviderProps, E as ENDPOINTS, H as HTTP_STATUS, p as HttpStatusCode, L as LoadingSpinner, l as TranscriptData, k as TranscriptSegment, T as TranscriptWord, n as buildBroadcastCdnUrl, o as buildBroadcastS3KeyPrefix, m as formatTime, u as useDialTribe, q as useDialTribeOptional } from './broadcast-player-CEAnuf6t.js';
|
|
2
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
3
|
+
import { RefObject } from 'react';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Props for the BroadcastStreamer component.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```tsx
|
|
10
|
+
* // Inside DialTribeProvider (recommended)
|
|
11
|
+
* <DialTribeProvider sessionToken={token}>
|
|
12
|
+
* <BroadcastStreamer
|
|
13
|
+
* streamKey={keyFromBackend}
|
|
14
|
+
* onDone={() => window.close()}
|
|
15
|
+
* />
|
|
16
|
+
* </DialTribeProvider>
|
|
17
|
+
*
|
|
18
|
+
* // Standalone (e.g., popup window)
|
|
19
|
+
* <BroadcastStreamer
|
|
20
|
+
* sessionToken={token}
|
|
21
|
+
* streamKey={keyFromBackend}
|
|
22
|
+
* onDone={() => window.close()}
|
|
23
|
+
* />
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
interface BroadcastStreamerProps {
|
|
27
|
+
/**
|
|
28
|
+
* Session token for API authentication.
|
|
29
|
+
*
|
|
30
|
+
* Required for permission checks. Can be provided via:
|
|
31
|
+
* 1. DialTribeProvider context (recommended for main app)
|
|
32
|
+
* 2. This prop (required for popup windows)
|
|
33
|
+
*
|
|
34
|
+
* Must include `broadcasts:stream` permission.
|
|
35
|
+
*/
|
|
36
|
+
sessionToken?: string;
|
|
37
|
+
/**
|
|
38
|
+
* Stream key for broadcasting.
|
|
39
|
+
*
|
|
40
|
+
* **Production apps should always provide this from their backend.**
|
|
41
|
+
* The stream key authenticates the broadcaster with the encoder server.
|
|
42
|
+
*
|
|
43
|
+
* If omitted, a manual input form is shown. This is intended for
|
|
44
|
+
* development/testing only - end users should never see or handle stream keys.
|
|
45
|
+
*
|
|
46
|
+
* @example "w1_abc123def456..."
|
|
47
|
+
*/
|
|
48
|
+
streamKey?: string;
|
|
49
|
+
/**
|
|
50
|
+
* Called when streaming ends (user stops, terminates, or clicks Done).
|
|
51
|
+
* Use this to close the popup or navigate away.
|
|
52
|
+
*
|
|
53
|
+
* @example () => window.close()
|
|
54
|
+
*/
|
|
55
|
+
onDone?: () => void;
|
|
56
|
+
/**
|
|
57
|
+
* Called when the stream key changes (e.g., user edits it in preview mode).
|
|
58
|
+
* Useful for persisting the key or updating parent state.
|
|
59
|
+
*/
|
|
60
|
+
onStreamKeyChange?: (key: string) => void;
|
|
61
|
+
/**
|
|
62
|
+
* Custom encoder server URL. Defaults to DialTribe's production encoder.
|
|
63
|
+
* Only change this for self-hosted encoder deployments.
|
|
64
|
+
*
|
|
65
|
+
* @default "https://broadcastapi.dialtribe.com"
|
|
66
|
+
*/
|
|
67
|
+
encoderServerUrl?: string;
|
|
68
|
+
/**
|
|
69
|
+
* Custom API base URL for broadcast availability checks.
|
|
70
|
+
* Only change this for self-hosted API deployments.
|
|
71
|
+
*
|
|
72
|
+
* @default "https://dialtribe.com/api/public/v1"
|
|
73
|
+
*/
|
|
74
|
+
apiBaseUrl?: string;
|
|
75
|
+
/**
|
|
76
|
+
* When true, the streamer fills its parent container instead of the viewport.
|
|
77
|
+
* Use this when embedding the streamer inline within a page.
|
|
78
|
+
*
|
|
79
|
+
* @default false
|
|
80
|
+
*/
|
|
81
|
+
inline?: boolean;
|
|
82
|
+
}
|
|
83
|
+
declare function BroadcastStreamer({ sessionToken: propSessionToken, streamKey: initialStreamKey, onDone, onStreamKeyChange, encoderServerUrl, apiBaseUrl, inline, }: BroadcastStreamerProps): react_jsx_runtime.JSX.Element;
|
|
84
|
+
|
|
85
|
+
interface StreamingPreviewProps {
|
|
86
|
+
videoRef: RefObject<HTMLVideoElement>;
|
|
87
|
+
isVideoKey: boolean;
|
|
88
|
+
isVideoEnabled: boolean;
|
|
89
|
+
mediaStream: MediaStream | null;
|
|
90
|
+
facingMode: "user" | "environment";
|
|
91
|
+
}
|
|
92
|
+
declare function StreamingPreview({ videoRef, isVideoKey, isVideoEnabled, mediaStream, facingMode, }: StreamingPreviewProps): react_jsx_runtime.JSX.Element;
|
|
93
|
+
|
|
94
|
+
type StreamingControlState = "previewing" | "connecting" | "live" | "stopping";
|
|
95
|
+
interface MediaDeviceInfo {
|
|
96
|
+
deviceId: string;
|
|
97
|
+
label: string;
|
|
98
|
+
}
|
|
99
|
+
interface StreamingControlsProps {
|
|
100
|
+
state: StreamingControlState;
|
|
101
|
+
isVideoKey: boolean;
|
|
102
|
+
isMuted: boolean;
|
|
103
|
+
isVideoEnabled: boolean;
|
|
104
|
+
facingMode: "user" | "environment";
|
|
105
|
+
hasMultipleCameras: boolean;
|
|
106
|
+
startTime: Date | null;
|
|
107
|
+
bytesSent: number;
|
|
108
|
+
showStopConfirm: boolean;
|
|
109
|
+
streamKey: string;
|
|
110
|
+
onStreamKeyChange?: (newKey: string) => void;
|
|
111
|
+
onStart: () => void;
|
|
112
|
+
onStop: () => void;
|
|
113
|
+
onConfirmStop: () => void;
|
|
114
|
+
onCancelStop: () => void;
|
|
115
|
+
onToggleMute: () => void;
|
|
116
|
+
onToggleVideo: () => void;
|
|
117
|
+
onFlipCamera: () => void;
|
|
118
|
+
onClose?: () => void;
|
|
119
|
+
showCloseConfirm?: boolean;
|
|
120
|
+
onConfirmClose?: () => void;
|
|
121
|
+
onCancelClose?: () => void;
|
|
122
|
+
videoDevices?: MediaDeviceInfo[];
|
|
123
|
+
audioDevices?: MediaDeviceInfo[];
|
|
124
|
+
selectedVideoDeviceId?: string;
|
|
125
|
+
selectedAudioDeviceId?: string;
|
|
126
|
+
onVideoDeviceChange?: (deviceId: string) => void;
|
|
127
|
+
onAudioDeviceChange?: (deviceId: string) => void;
|
|
128
|
+
mediaStream?: MediaStream | null;
|
|
129
|
+
}
|
|
130
|
+
declare function StreamingControls({ state, isVideoKey, isMuted, isVideoEnabled, facingMode: _facingMode, // Reserved for future use (e.g., showing camera direction)
|
|
131
|
+
hasMultipleCameras, startTime, bytesSent, showStopConfirm, streamKey, onStreamKeyChange, onStart, onStop, onConfirmStop, onCancelStop, onToggleMute, onToggleVideo, onFlipCamera, onClose, showCloseConfirm, onConfirmClose, onCancelClose, videoDevices, audioDevices, selectedVideoDeviceId, selectedAudioDeviceId, onVideoDeviceChange, onAudioDeviceChange, mediaStream, }: StreamingControlsProps): react_jsx_runtime.JSX.Element;
|
|
132
|
+
|
|
133
|
+
interface StreamKeyDisplayProps {
|
|
134
|
+
streamKey: string;
|
|
135
|
+
className?: string;
|
|
136
|
+
showLabel?: boolean;
|
|
137
|
+
showCopy?: boolean;
|
|
138
|
+
editable?: boolean;
|
|
139
|
+
onChange?: (newKey: string) => void;
|
|
140
|
+
size?: 'sm' | 'md' | 'lg';
|
|
141
|
+
layout?: 'vertical' | 'horizontal';
|
|
142
|
+
darkMode?: boolean;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Shared component for displaying stream keys with reveal/copy functionality
|
|
146
|
+
* Obscures the stream key by default, showing only first 6 and last 6 characters
|
|
147
|
+
* When revealed and editable, becomes an input field for editing
|
|
148
|
+
*/
|
|
149
|
+
declare function StreamKeyDisplay({ streamKey, className, showLabel, showCopy, editable, onChange, size, layout, darkMode, }: StreamKeyDisplayProps): react_jsx_runtime.JSX.Element;
|
|
150
|
+
|
|
151
|
+
interface StreamKeyInputProps {
|
|
152
|
+
onSubmit: (key: string) => void;
|
|
153
|
+
/**
|
|
154
|
+
* When true, the input fills its parent container instead of the viewport.
|
|
155
|
+
* Use this when embedding inline within a page.
|
|
156
|
+
*/
|
|
157
|
+
inline?: boolean;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Stream key input form for manual entry
|
|
161
|
+
* Validates stream key format before submission
|
|
162
|
+
*/
|
|
163
|
+
declare function StreamKeyInput({ onSubmit, inline }: StreamKeyInputProps): react_jsx_runtime.JSX.Element;
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* WebSocket streaming client for sending media chunks to encoder server
|
|
167
|
+
* Based on prankcast reference implementation
|
|
168
|
+
*/
|
|
169
|
+
/** Default encoder server URL */
|
|
170
|
+
declare const DEFAULT_ENCODER_SERVER_URL = "https://broadcastapi.dialtribe.com";
|
|
171
|
+
interface WebSocketStreamerOptions {
|
|
172
|
+
streamKey: string;
|
|
173
|
+
mediaStream: MediaStream;
|
|
174
|
+
isVideo: boolean;
|
|
175
|
+
/** Optional custom encoder server URL (defaults to DEFAULT_ENCODER_SERVER_URL) */
|
|
176
|
+
encoderServerUrl?: string;
|
|
177
|
+
onBytesUpdate?: (bytes: number) => void;
|
|
178
|
+
onStateChange?: (state: "connecting" | "live" | "stopped" | "terminated" | "error") => void;
|
|
179
|
+
onError?: (error: string) => void;
|
|
180
|
+
}
|
|
181
|
+
declare class WebSocketStreamer {
|
|
182
|
+
private streamKey;
|
|
183
|
+
private mediaStream;
|
|
184
|
+
private isVideo;
|
|
185
|
+
private encoderServerUrl;
|
|
186
|
+
private websocket;
|
|
187
|
+
private mediaRecorder;
|
|
188
|
+
private bytesSent;
|
|
189
|
+
private userStopped;
|
|
190
|
+
private onBytesUpdate?;
|
|
191
|
+
private onStateChange?;
|
|
192
|
+
private onError?;
|
|
193
|
+
constructor(options: WebSocketStreamerOptions);
|
|
194
|
+
/**
|
|
195
|
+
* Validate stream key format
|
|
196
|
+
* Stream keys must follow format: {tierCode}{foreignId}_{randomKey}
|
|
197
|
+
* Tier codes: a (audio shared), b (audio VIP), v (video shared), w (video VIP)
|
|
198
|
+
*/
|
|
199
|
+
private validateStreamKeyFormat;
|
|
200
|
+
/**
|
|
201
|
+
* Build WebSocket URL from stream key
|
|
202
|
+
*/
|
|
203
|
+
private buildWebSocketUrl;
|
|
204
|
+
/**
|
|
205
|
+
* Start streaming
|
|
206
|
+
*/
|
|
207
|
+
start(): Promise<void>;
|
|
208
|
+
/**
|
|
209
|
+
* Stop streaming
|
|
210
|
+
*/
|
|
211
|
+
stop(): void;
|
|
212
|
+
/**
|
|
213
|
+
* Get total bytes sent
|
|
214
|
+
*/
|
|
215
|
+
getBytesSent(): number;
|
|
216
|
+
/**
|
|
217
|
+
* Update the media stream (e.g., when flipping camera)
|
|
218
|
+
* This keeps the WebSocket connection alive while swapping the media source
|
|
219
|
+
*
|
|
220
|
+
* Note: Errors are thrown to the caller, not sent to onError callback
|
|
221
|
+
* This allows the caller to handle camera flip failures gracefully
|
|
222
|
+
*/
|
|
223
|
+
updateMediaStream(newMediaStream: MediaStream): Promise<void>;
|
|
224
|
+
/**
|
|
225
|
+
* Set up WebSocket event handlers
|
|
226
|
+
*/
|
|
227
|
+
private setupWebSocketHandlers;
|
|
228
|
+
/**
|
|
229
|
+
* Set up MediaRecorder event handlers
|
|
230
|
+
*/
|
|
231
|
+
private setupMediaRecorderHandlers;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Media constraints for browser streaming
|
|
236
|
+
* Based on prankcast reference implementation
|
|
237
|
+
*/
|
|
238
|
+
interface MediaConstraintsOptions {
|
|
239
|
+
isVideo: boolean;
|
|
240
|
+
facingMode?: "user" | "environment";
|
|
241
|
+
}
|
|
242
|
+
declare function getMediaConstraints(options: MediaConstraintsOptions): MediaStreamConstraints;
|
|
243
|
+
/**
|
|
244
|
+
* MediaRecorder options for encoding
|
|
245
|
+
*/
|
|
246
|
+
declare function getMediaRecorderOptions(isVideo: boolean): MediaRecorderOptions;
|
|
247
|
+
/**
|
|
248
|
+
* Check browser compatibility
|
|
249
|
+
*/
|
|
250
|
+
declare function checkBrowserCompatibility(): {
|
|
251
|
+
compatible: boolean;
|
|
252
|
+
error?: string;
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Utility functions for opening broadcast streamer popup windows
|
|
257
|
+
*/
|
|
258
|
+
interface PopupDimensions {
|
|
259
|
+
width: number;
|
|
260
|
+
height: number;
|
|
261
|
+
left: number;
|
|
262
|
+
top: number;
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Calculate optimal popup dimensions based on screen size
|
|
266
|
+
* - Desktop/wider screens: 16:9 landscape ratio (e.g., 1280x720) to match modern webcams
|
|
267
|
+
* - Mobile/narrower screens: 9:16 portrait ratio (e.g., 720x1280) for vertical video
|
|
268
|
+
*/
|
|
269
|
+
declare function calculatePopupDimensions(): PopupDimensions;
|
|
270
|
+
type BroadcastMode = 'live' | 'schedule' | null;
|
|
271
|
+
/**
|
|
272
|
+
* Options for opening a broadcast streamer popup window.
|
|
273
|
+
*/
|
|
274
|
+
interface OpenBroadcastStreamerPopupOptions {
|
|
275
|
+
/**
|
|
276
|
+
* Session token for API authentication. **Required.**
|
|
277
|
+
* The token must include `broadcasts:stream` permission.
|
|
278
|
+
* Sent securely via postMessage (not in the URL).
|
|
279
|
+
*/
|
|
280
|
+
sessionToken: string;
|
|
281
|
+
/**
|
|
282
|
+
* Stream key for broadcasting. **Required for production use.**
|
|
283
|
+
* Fetch this from your backend and pass it here.
|
|
284
|
+
* The key is sent securely via postMessage (not in the URL).
|
|
285
|
+
*
|
|
286
|
+
* @example "w1_abc123def456..."
|
|
287
|
+
*/
|
|
288
|
+
streamKey: string;
|
|
289
|
+
/** Optional app ID to include in the postMessage payload */
|
|
290
|
+
appId?: number;
|
|
291
|
+
/**
|
|
292
|
+
* Launch mode. Use 'live' for immediate streaming.
|
|
293
|
+
* @default 'live'
|
|
294
|
+
*/
|
|
295
|
+
mode?: BroadcastMode;
|
|
296
|
+
/** Additional URL parameters to pass to the popup page */
|
|
297
|
+
additionalParams?: Record<string, string>;
|
|
298
|
+
/**
|
|
299
|
+
* Base URL for the streamer page.
|
|
300
|
+
* Only change this for custom hosting setups.
|
|
301
|
+
* @default "/broadcasts/new"
|
|
302
|
+
*/
|
|
303
|
+
baseUrl?: string;
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Open broadcast streamer popup window with credentials sent via postMessage
|
|
307
|
+
* This is more secure than passing sensitive data in the URL
|
|
308
|
+
*
|
|
309
|
+
* @example
|
|
310
|
+
* ```tsx
|
|
311
|
+
* import { openBroadcastStreamerPopup } from '@dialtribe/react-sdk/broadcast-streamer';
|
|
312
|
+
*
|
|
313
|
+
* // Open popup for live streaming
|
|
314
|
+
* openBroadcastStreamerPopup({
|
|
315
|
+
* sessionToken: 'sess_xxx...',
|
|
316
|
+
* streamKey: 'w1_abc123...',
|
|
317
|
+
* mode: 'live',
|
|
318
|
+
* });
|
|
319
|
+
* ```
|
|
320
|
+
*
|
|
321
|
+
* @returns The popup window reference, or null if popup was blocked
|
|
322
|
+
*/
|
|
323
|
+
declare function openBroadcastStreamerPopup(options: OpenBroadcastStreamerPopupOptions): Window | null;
|
|
324
|
+
/**
|
|
325
|
+
* Legacy function name for backwards compatibility
|
|
326
|
+
* @deprecated Use openBroadcastStreamerPopup instead
|
|
327
|
+
*/
|
|
328
|
+
declare const openBroadcastPopup: typeof openBroadcastStreamerPopup;
|
|
329
|
+
|
|
330
|
+
export { type BroadcastMode, BroadcastStreamer, type BroadcastStreamerProps, DEFAULT_ENCODER_SERVER_URL, type MediaConstraintsOptions, type OpenBroadcastStreamerPopupOptions, type PopupDimensions, StreamKeyDisplay, type StreamKeyDisplayProps, StreamKeyInput, type StreamKeyInputProps, type StreamingControlState, StreamingControls, type StreamingControlsProps, StreamingPreview, type StreamingPreviewProps, WebSocketStreamer, type WebSocketStreamerOptions, calculatePopupDimensions, checkBrowserCompatibility, getMediaConstraints, getMediaRecorderOptions, openBroadcastPopup, openBroadcastStreamerPopup };
|