@streamplace/components 0.6.37 → 0.7.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.
Files changed (138) hide show
  1. package/dist/components/chat/chat-box.js +109 -0
  2. package/dist/components/chat/chat-message.js +76 -0
  3. package/dist/components/chat/chat.js +56 -0
  4. package/dist/components/chat/mention-suggestions.js +39 -0
  5. package/dist/components/chat/mod-view.js +33 -0
  6. package/dist/components/mobile-player/fullscreen.js +69 -0
  7. package/dist/components/mobile-player/fullscreen.native.js +151 -0
  8. package/dist/components/mobile-player/player.js +103 -0
  9. package/dist/components/mobile-player/props.js +1 -0
  10. package/dist/components/mobile-player/shared.js +51 -0
  11. package/dist/components/mobile-player/ui/countdown.js +79 -0
  12. package/dist/components/mobile-player/ui/index.js +5 -0
  13. package/dist/components/mobile-player/ui/input.js +38 -0
  14. package/dist/components/mobile-player/ui/metrics.js +40 -0
  15. package/dist/components/mobile-player/ui/streamer-context-menu.js +4 -0
  16. package/dist/components/mobile-player/ui/viewer-context-menu.js +20 -0
  17. package/dist/components/mobile-player/use-webrtc.js +232 -0
  18. package/dist/components/mobile-player/video.js +375 -0
  19. package/dist/components/mobile-player/video.native.js +238 -0
  20. package/dist/components/mobile-player/webrtc-diagnostics.js +106 -0
  21. package/dist/components/mobile-player/webrtc-primitives.js +25 -0
  22. package/dist/components/mobile-player/webrtc-primitives.native.js +1 -0
  23. package/dist/components/ui/button.js +220 -0
  24. package/dist/components/ui/dialog.js +203 -0
  25. package/dist/components/ui/dropdown.js +148 -0
  26. package/dist/components/ui/icons.js +22 -0
  27. package/dist/components/ui/index.js +22 -0
  28. package/dist/components/ui/input.js +202 -0
  29. package/dist/components/ui/loader.js +7 -0
  30. package/dist/components/ui/primitives/button.js +121 -0
  31. package/dist/components/ui/primitives/input.js +202 -0
  32. package/dist/components/ui/primitives/modal.js +203 -0
  33. package/dist/components/ui/primitives/text.js +286 -0
  34. package/dist/components/ui/resizeable.js +101 -0
  35. package/dist/components/ui/text.js +175 -0
  36. package/dist/components/ui/textarea.js +17 -0
  37. package/dist/components/ui/toast.js +129 -0
  38. package/dist/components/ui/view.js +250 -0
  39. package/dist/hooks/index.js +9 -0
  40. package/dist/hooks/useAvatars.js +32 -0
  41. package/dist/hooks/useCameraToggle.js +9 -0
  42. package/dist/hooks/useKeyboard.js +33 -0
  43. package/dist/hooks/useKeyboardSlide.js +11 -0
  44. package/dist/hooks/useLivestreamInfo.js +62 -0
  45. package/dist/hooks/useOuterAndInnerDimensions.js +27 -0
  46. package/dist/hooks/usePlayerDimensions.js +19 -0
  47. package/dist/hooks/useSegmentTiming.js +62 -0
  48. package/dist/index.js +10 -0
  49. package/dist/lib/facet.js +88 -0
  50. package/dist/lib/theme/atoms.js +620 -0
  51. package/dist/lib/theme/atoms.types.js +5 -0
  52. package/dist/lib/theme/index.js +9 -0
  53. package/dist/lib/theme/theme.js +248 -0
  54. package/dist/lib/theme/tokens.js +383 -0
  55. package/dist/lib/utils.js +94 -0
  56. package/dist/livestream-provider/index.js +8 -3
  57. package/dist/livestream-store/chat.js +89 -65
  58. package/dist/livestream-store/index.js +1 -0
  59. package/dist/livestream-store/livestream-store.js +3 -0
  60. package/dist/livestream-store/stream-key.js +115 -0
  61. package/dist/player-store/player-provider.js +0 -1
  62. package/dist/player-store/player-store.js +13 -0
  63. package/dist/streamplace-store/block.js +23 -0
  64. package/dist/streamplace-store/index.js +1 -0
  65. package/dist/streamplace-store/stream.js +193 -0
  66. package/node-compile-cache/v22.15.0-x64-efe9a9df-0/37be0eec +0 -0
  67. package/node-compile-cache/v22.15.0-x64-efe9a9df-0/56540125 +0 -0
  68. package/node-compile-cache/v22.15.0-x64-efe9a9df-0/67b1eb60 +0 -0
  69. package/node-compile-cache/v22.15.0-x64-efe9a9df-0/7c275f90 +0 -0
  70. package/package.json +20 -4
  71. package/src/components/chat/chat-box.tsx +195 -0
  72. package/src/components/chat/chat-message.tsx +192 -0
  73. package/src/components/chat/chat.tsx +128 -0
  74. package/src/components/chat/mention-suggestions.tsx +71 -0
  75. package/src/components/chat/mod-view.tsx +118 -0
  76. package/src/components/mobile-player/fullscreen.native.tsx +193 -0
  77. package/src/components/mobile-player/fullscreen.tsx +79 -0
  78. package/src/components/mobile-player/player.tsx +134 -0
  79. package/src/components/mobile-player/props.tsx +11 -0
  80. package/src/components/mobile-player/shared.tsx +56 -0
  81. package/src/components/mobile-player/ui/countdown.tsx +119 -0
  82. package/src/components/mobile-player/ui/index.ts +5 -0
  83. package/src/components/mobile-player/ui/input.tsx +85 -0
  84. package/src/components/mobile-player/ui/metrics.tsx +69 -0
  85. package/src/components/mobile-player/ui/streamer-context-menu.tsx +3 -0
  86. package/src/components/mobile-player/ui/viewer-context-menu.tsx +70 -0
  87. package/src/components/mobile-player/use-webrtc.tsx +282 -0
  88. package/src/components/mobile-player/video.native.tsx +360 -0
  89. package/src/components/mobile-player/video.tsx +557 -0
  90. package/src/components/mobile-player/webrtc-diagnostics.tsx +149 -0
  91. package/src/components/mobile-player/webrtc-primitives.native.tsx +6 -0
  92. package/src/components/mobile-player/webrtc-primitives.tsx +33 -0
  93. package/src/components/ui/button.tsx +309 -0
  94. package/src/components/ui/dialog.tsx +376 -0
  95. package/src/components/ui/dropdown.tsx +399 -0
  96. package/src/components/ui/icons.tsx +50 -0
  97. package/src/components/ui/index.ts +33 -0
  98. package/src/components/ui/input.tsx +350 -0
  99. package/src/components/ui/loader.tsx +9 -0
  100. package/src/components/ui/primitives/button.tsx +292 -0
  101. package/src/components/ui/primitives/input.tsx +422 -0
  102. package/src/components/ui/primitives/modal.tsx +421 -0
  103. package/src/components/ui/primitives/text.tsx +499 -0
  104. package/src/components/ui/resizeable.tsx +169 -0
  105. package/src/components/ui/text.tsx +330 -0
  106. package/src/components/ui/textarea.tsx +34 -0
  107. package/src/components/ui/toast.tsx +203 -0
  108. package/src/components/ui/view.tsx +344 -0
  109. package/src/hooks/index.ts +9 -0
  110. package/src/hooks/useAvatars.tsx +44 -0
  111. package/src/hooks/useCameraToggle.ts +12 -0
  112. package/src/hooks/useKeyboard.tsx +41 -0
  113. package/src/hooks/useKeyboardSlide.ts +12 -0
  114. package/src/hooks/useLivestreamInfo.ts +67 -0
  115. package/src/hooks/useOuterAndInnerDimensions.tsx +32 -0
  116. package/src/hooks/usePlayerDimensions.ts +23 -0
  117. package/src/hooks/useSegmentTiming.tsx +88 -0
  118. package/src/index.tsx +21 -0
  119. package/src/lib/facet.ts +131 -0
  120. package/src/lib/theme/atoms.ts +760 -0
  121. package/src/lib/theme/atoms.types.ts +258 -0
  122. package/src/lib/theme/index.ts +48 -0
  123. package/src/lib/theme/theme.tsx +436 -0
  124. package/src/lib/theme/tokens.ts +409 -0
  125. package/src/lib/utils.ts +132 -0
  126. package/src/livestream-provider/index.tsx +13 -2
  127. package/src/livestream-store/chat.tsx +115 -78
  128. package/src/livestream-store/index.tsx +1 -0
  129. package/src/livestream-store/livestream-state.tsx +3 -0
  130. package/src/livestream-store/livestream-store.tsx +3 -0
  131. package/src/livestream-store/stream-key.tsx +124 -0
  132. package/src/player-store/player-provider.tsx +0 -1
  133. package/src/player-store/player-state.tsx +28 -0
  134. package/src/player-store/player-store.tsx +22 -0
  135. package/src/streamplace-store/block.tsx +29 -0
  136. package/src/streamplace-store/index.tsx +1 -0
  137. package/src/streamplace-store/stream.tsx +262 -0
  138. package/tsconfig.tsbuildinfo +1 -1
@@ -0,0 +1,360 @@
1
+ import { useVideoPlayer, VideoPlayerEvents, VideoView } from "expo-video";
2
+ import { useCallback, useEffect, useRef, useState } from "react";
3
+ import { LayoutChangeEvent } from "react-native";
4
+ import {
5
+ MediaStream,
6
+ RTCView,
7
+ RTCView as RTCViewIngest,
8
+ } from "react-native-webrtc";
9
+ import {
10
+ IngestMediaSource,
11
+ PlayerStatus as IngestPlayerStatus,
12
+ PlayerProtocol,
13
+ PlayerStatus,
14
+ Text,
15
+ usePlayerStore as useIngestPlayerStore,
16
+ usePlayerStore,
17
+ useStreamplaceStore,
18
+ View,
19
+ } from "../..";
20
+ import { borderRadius, colors, p } from "../../lib/theme/atoms";
21
+ import { srcToUrl } from "./shared";
22
+ import useWebRTC, { useWebRTCIngest } from "./use-webrtc";
23
+ import { mediaDevices, WebRTCMediaStream } from "./webrtc-primitives.native";
24
+
25
+ // Add NativeIngestPlayer to the switch below!
26
+ export default function VideoNative() {
27
+ const protocol = usePlayerStore((x) => x.protocol);
28
+ const ingest = usePlayerStore((x) => x.ingestConnectionState) != null;
29
+
30
+ return (
31
+ <View>
32
+ {ingest ? (
33
+ <NativeIngestPlayer />
34
+ ) : protocol === PlayerProtocol.WEBRTC ? (
35
+ <NativeWHEP />
36
+ ) : (
37
+ <NativeVideo />
38
+ )}
39
+ </View>
40
+ );
41
+ }
42
+
43
+ export function NativeVideo() {
44
+ const videoRef = useRef<VideoView | null>(null);
45
+ const protocol = usePlayerStore((x) => x.protocol);
46
+
47
+ const selectedRendition = usePlayerStore((x) => x.selectedRendition);
48
+ const src = usePlayerStore((x) => x.src);
49
+ const { url } = srcToUrl({ src: src, selectedRendition }, protocol);
50
+ const setStatus = usePlayerStore((x) => x.setStatus);
51
+ const muted = usePlayerStore((x) => x.muted);
52
+ const volume = usePlayerStore((x) => x.volume);
53
+ const setFullscreen = usePlayerStore((x) => x.setFullscreen);
54
+ const fullscreen = usePlayerStore((x) => x.fullscreen);
55
+ const playerEvent = usePlayerStore((x) => x.playerEvent);
56
+ const spurl = useStreamplaceStore((x) => x.url);
57
+
58
+ const setPlayerWidth = usePlayerStore((x) => x.setPlayerWidth);
59
+ const setPlayerHeight = usePlayerStore((x) => x.setPlayerHeight);
60
+
61
+ // State for live dimensions
62
+ const [dimensions, setDimensions] = useState<{
63
+ width: number;
64
+ height: number;
65
+ }>({ width: 0, height: 0 });
66
+
67
+ const handleLayout = useCallback((event: LayoutChangeEvent) => {
68
+ const { width, height } = event.nativeEvent.layout;
69
+ setDimensions({ width, height });
70
+ setPlayerWidth(width);
71
+ setPlayerHeight(height);
72
+ }, []);
73
+
74
+ useEffect(() => {
75
+ return () => {
76
+ setStatus(PlayerStatus.START);
77
+ };
78
+ }, [setStatus]);
79
+
80
+ const player = useVideoPlayer(url, (player) => {
81
+ player.loop = true;
82
+ player.muted = muted;
83
+ player.play();
84
+ });
85
+
86
+ useEffect(() => {
87
+ player.muted = muted;
88
+ }, [muted, player]);
89
+
90
+ useEffect(() => {
91
+ player.volume = volume;
92
+ }, [volume, player]);
93
+
94
+ useEffect(() => {
95
+ const subs = (
96
+ [
97
+ "playToEnd",
98
+ "playbackRateChange",
99
+ "playingChange",
100
+ "sourceChange",
101
+ "statusChange",
102
+ "volumeChange",
103
+ ] as (keyof VideoPlayerEvents)[]
104
+ ).map((evType) => {
105
+ return player.addListener(evType, (...args) => {
106
+ const now = new Date();
107
+ playerEvent(spurl, now.toISOString(), evType, { args: args });
108
+ });
109
+ });
110
+
111
+ subs.push(
112
+ player.addListener("playingChange", (newIsPlaying) => {
113
+ if (newIsPlaying) {
114
+ setStatus(PlayerStatus.PLAYING);
115
+ } else {
116
+ setStatus(PlayerStatus.WAITING);
117
+ }
118
+ }),
119
+ );
120
+
121
+ return () => {
122
+ for (const sub of subs) {
123
+ sub.remove();
124
+ }
125
+ };
126
+ }, [player, playerEvent, setStatus, spurl]);
127
+
128
+ return (
129
+ <>
130
+ <VideoView
131
+ ref={videoRef}
132
+ player={player}
133
+ allowsFullscreen
134
+ nativeControls={fullscreen}
135
+ onFullscreenEnter={() => {
136
+ setFullscreen(true);
137
+ }}
138
+ onFullscreenExit={() => {
139
+ setFullscreen(false);
140
+ }}
141
+ allowsPictureInPicture
142
+ onLayout={handleLayout}
143
+ />
144
+ </>
145
+ );
146
+ }
147
+
148
+ export function NativeWHEP() {
149
+ const selectedRendition = usePlayerStore((x) => x.selectedRendition);
150
+ const src = usePlayerStore((x) => x.src);
151
+ const { url } = srcToUrl(
152
+ { src: src, selectedRendition },
153
+ PlayerProtocol.WEBRTC,
154
+ );
155
+ const [stream, stuck] = useWebRTC(url);
156
+
157
+ const setPlayerWidth = usePlayerStore((x) => x.setPlayerWidth);
158
+ const setPlayerHeight = usePlayerStore((x) => x.setPlayerHeight);
159
+
160
+ // PiP support: wire up videoRef (no direct ref for RTCView)
161
+ const setVideoRef = usePlayerStore((x) => x.setVideoRef);
162
+
163
+ // State for live dimensions
164
+ const [dimensions, setDimensions] = useState<{
165
+ width: number;
166
+ height: number;
167
+ }>({ width: 0, height: 0 });
168
+
169
+ const handleLayout = useCallback((event: LayoutChangeEvent) => {
170
+ const { width, height } = event.nativeEvent.layout;
171
+ setDimensions({ width, height });
172
+ setPlayerWidth(width);
173
+ setPlayerHeight(height);
174
+ }, []);
175
+
176
+ const setStatus = usePlayerStore((x) => x.setStatus);
177
+ const muted = usePlayerStore((x) => x.muted);
178
+ const volume = usePlayerStore((x) => x.volume);
179
+
180
+ useEffect(() => {
181
+ if (stuck) {
182
+ setStatus(PlayerStatus.STALLED);
183
+ } else {
184
+ setStatus(PlayerStatus.PLAYING);
185
+ }
186
+ }, [stuck, setStatus]);
187
+
188
+ const mediaStream = stream as unknown as MediaStream;
189
+
190
+ useEffect(() => {
191
+ if (!mediaStream) {
192
+ setStatus(PlayerStatus.WAITING);
193
+ return;
194
+ }
195
+ setStatus(PlayerStatus.PLAYING);
196
+ }, [mediaStream, setStatus]);
197
+
198
+ useEffect(() => {
199
+ if (!mediaStream) {
200
+ return;
201
+ }
202
+ mediaStream.getTracks().forEach((track) => {
203
+ if (track.kind === "audio") {
204
+ track._setVolume(muted ? 0 : volume);
205
+ }
206
+ });
207
+ }, [mediaStream, muted, volume]);
208
+
209
+ // Keep the playerStore videoRef in sync for PiP (if possible)
210
+ useEffect(() => {
211
+ if (typeof setVideoRef === "function") {
212
+ setVideoRef(null); // No direct ref for RTCView, but keep API consistent
213
+ }
214
+ }, [setVideoRef]);
215
+
216
+ if (!mediaStream) {
217
+ return <View></View>;
218
+ }
219
+
220
+ return (
221
+ <>
222
+ <RTCView
223
+ mirror={false}
224
+ objectFit={"contain"}
225
+ streamURL={mediaStream.toURL()}
226
+ onLayout={handleLayout}
227
+ pictureInPictureEnabled={true}
228
+ autoStartPictureInPicture={true}
229
+ pictureInPicturePreferredSize={{
230
+ width: 160,
231
+ height: 90,
232
+ }}
233
+ style={{
234
+ minWidth: "100%",
235
+ minHeight: "100%",
236
+ flex: 1,
237
+ }}
238
+ />
239
+ </>
240
+ );
241
+ }
242
+
243
+ export function NativeIngestPlayer() {
244
+ const ingestStarting = useIngestPlayerStore((x) => x.ingestStarting);
245
+ const ingestMediaSource = useIngestPlayerStore((x) => x.ingestMediaSource);
246
+ const ingestAutoStart = useIngestPlayerStore((x) => x.ingestAutoStart);
247
+ const setStatus = useIngestPlayerStore((x) => x.setStatus);
248
+ const setVideoRef = usePlayerStore((x) => x.setVideoRef);
249
+
250
+ const [error, setError] = useState<Error | null>(null);
251
+
252
+ const ingestCamera = useIngestPlayerStore((x) => x.ingestCamera);
253
+
254
+ useEffect(() => {
255
+ setStatus(IngestPlayerStatus.PLAYING);
256
+ }, [setStatus]);
257
+
258
+ useEffect(() => {
259
+ if (typeof setVideoRef === "function") {
260
+ setVideoRef(null);
261
+ }
262
+ }, [setVideoRef]);
263
+
264
+ const url = useStreamplaceStore((x) => x.url);
265
+ const [lms, setLocalMediaStream] = useState<WebRTCMediaStream | null>(null);
266
+ const [, setRemoteMediaStream] = useWebRTCIngest({
267
+ endpoint: `${url}/api/ingest/webrtc`,
268
+ });
269
+
270
+ // Use lms directly as localMediaStream
271
+ const localMediaStream = lms;
272
+
273
+ useEffect(() => {
274
+ if (ingestMediaSource === IngestMediaSource.DISPLAY) {
275
+ mediaDevices
276
+ .getDisplayMedia()
277
+ .then((stream: WebRTCMediaStream) => {
278
+ console.log("display media", stream);
279
+ setLocalMediaStream(stream);
280
+ })
281
+ .catch((e: any) => {
282
+ console.log("error getting display media", e);
283
+ console.error("error getting display media", e);
284
+ });
285
+ } else {
286
+ mediaDevices
287
+ .getUserMedia({
288
+ audio: {
289
+ // deviceId: "audio-1",
290
+ // echoCancellation: true,
291
+ // autoGainControl: true,
292
+ // noiseSuppression: true,
293
+ // latency: false,
294
+ // channelCount: false,
295
+ },
296
+ video: {
297
+ facingMode: ingestCamera,
298
+ width: { min: 200, ideal: 1080, max: 2160 },
299
+ height: { min: 200, ideal: 1920, max: 3840 },
300
+ },
301
+ })
302
+ .then((stream: WebRTCMediaStream) => {
303
+ setLocalMediaStream(stream);
304
+ })
305
+ .catch((e: any) => {
306
+ console.error("error getting user media", e);
307
+ setError(
308
+ new Error(
309
+ "We could not access your camera or microphone. Please check your permissions.",
310
+ ),
311
+ );
312
+ });
313
+ }
314
+ }, [ingestMediaSource, ingestCamera]);
315
+
316
+ useEffect(() => {
317
+ if (!ingestStarting && !ingestAutoStart) {
318
+ setRemoteMediaStream(null);
319
+ return;
320
+ }
321
+ if (!localMediaStream) {
322
+ return;
323
+ }
324
+ console.log("setting remote media stream", localMediaStream);
325
+ // @ts-expect-error: WebRTCMediaStream may not have all MediaStream properties, but is compatible for our use
326
+ setRemoteMediaStream(localMediaStream);
327
+ }, [localMediaStream, ingestStarting, ingestAutoStart, setRemoteMediaStream]);
328
+
329
+ if (!localMediaStream) {
330
+ return null;
331
+ }
332
+
333
+ if (error) {
334
+ return (
335
+ <View
336
+ backgroundColor={colors.destructive[900]}
337
+ style={[p[4], { borderRadius: borderRadius.md }]}
338
+ >
339
+ <View>
340
+ <Text>Error encountered!</Text>
341
+ </View>
342
+ <Text>{error.message}</Text>
343
+ </View>
344
+ );
345
+ }
346
+
347
+ return (
348
+ <RTCViewIngest
349
+ mirror={ingestCamera !== "environment"}
350
+ objectFit={"contain"}
351
+ streamURL={localMediaStream.toURL()}
352
+ zOrder={0}
353
+ style={{
354
+ minWidth: "100%",
355
+ minHeight: "100%",
356
+ flex: 1,
357
+ }}
358
+ />
359
+ );
360
+ }