@streamplace/components 0.7.14 → 0.7.17

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 (123) hide show
  1. package/package.json +13 -15
  2. package/src/components/mobile-player/fullscreen.native.tsx +14 -3
  3. package/src/components/mobile-player/fullscreen.tsx +10 -2
  4. package/src/components/mobile-player/player.tsx +7 -1
  5. package/src/components/mobile-player/props.tsx +7 -0
  6. package/src/components/mobile-player/video-async.native.tsx +436 -0
  7. package/src/components/mobile-player/video.native.tsx +16 -406
  8. package/src/components/mobile-player/video.tsx +14 -3
  9. package/src/hooks/useLivestreamInfo.ts +6 -2
  10. package/src/lib/browser.ts +27 -0
  11. package/src/livestream-store/stream-key.tsx +1 -28
  12. package/src/streamplace-store/stream.tsx +52 -13
  13. package/dist/assets/emoji-data.json +0 -19371
  14. package/dist/components/chat/chat-box.js +0 -314
  15. package/dist/components/chat/chat-message.js +0 -87
  16. package/dist/components/chat/chat.js +0 -149
  17. package/dist/components/chat/emoji-suggestions.js +0 -35
  18. package/dist/components/chat/mention-suggestions.js +0 -42
  19. package/dist/components/chat/mod-view.js +0 -94
  20. package/dist/components/chat/system-message.js +0 -19
  21. package/dist/components/dashboard/chat-panel.js +0 -38
  22. package/dist/components/dashboard/header.js +0 -80
  23. package/dist/components/dashboard/index.js +0 -14
  24. package/dist/components/dashboard/information-widget.js +0 -234
  25. package/dist/components/dashboard/mod-actions.js +0 -71
  26. package/dist/components/dashboard/problems.js +0 -74
  27. package/dist/components/icons/bluesky-icon.js +0 -9
  28. package/dist/components/keep-awake.js +0 -7
  29. package/dist/components/keep-awake.native.js +0 -16
  30. package/dist/components/mobile-player/fullscreen.js +0 -74
  31. package/dist/components/mobile-player/fullscreen.native.js +0 -141
  32. package/dist/components/mobile-player/player.js +0 -94
  33. package/dist/components/mobile-player/props.js +0 -2
  34. package/dist/components/mobile-player/shared.js +0 -54
  35. package/dist/components/mobile-player/ui/countdown.js +0 -83
  36. package/dist/components/mobile-player/ui/index.js +0 -11
  37. package/dist/components/mobile-player/ui/input.js +0 -42
  38. package/dist/components/mobile-player/ui/metrics.js +0 -44
  39. package/dist/components/mobile-player/ui/report-modal.js +0 -90
  40. package/dist/components/mobile-player/ui/streamer-context-menu.js +0 -7
  41. package/dist/components/mobile-player/ui/streamer-loading-overlay.js +0 -104
  42. package/dist/components/mobile-player/ui/viewer-context-menu.js +0 -51
  43. package/dist/components/mobile-player/ui/viewer-loading-overlay.js +0 -49
  44. package/dist/components/mobile-player/ui/viewers.js +0 -23
  45. package/dist/components/mobile-player/use-webrtc.js +0 -243
  46. package/dist/components/mobile-player/video-retry.js +0 -29
  47. package/dist/components/mobile-player/video.js +0 -460
  48. package/dist/components/mobile-player/video.native.js +0 -276
  49. package/dist/components/mobile-player/webrtc-diagnostics.js +0 -110
  50. package/dist/components/mobile-player/webrtc-primitives.js +0 -27
  51. package/dist/components/mobile-player/webrtc-primitives.native.js +0 -8
  52. package/dist/components/share/sharesheet.js +0 -91
  53. package/dist/components/ui/button.js +0 -223
  54. package/dist/components/ui/dialog.js +0 -206
  55. package/dist/components/ui/dropdown.js +0 -172
  56. package/dist/components/ui/icons.js +0 -25
  57. package/dist/components/ui/index.js +0 -34
  58. package/dist/components/ui/info-box.js +0 -31
  59. package/dist/components/ui/info-row.js +0 -23
  60. package/dist/components/ui/input.js +0 -205
  61. package/dist/components/ui/loader.js +0 -10
  62. package/dist/components/ui/primitives/button.js +0 -125
  63. package/dist/components/ui/primitives/input.js +0 -206
  64. package/dist/components/ui/primitives/modal.js +0 -206
  65. package/dist/components/ui/primitives/text.js +0 -292
  66. package/dist/components/ui/resizeable.js +0 -121
  67. package/dist/components/ui/slider.js +0 -5
  68. package/dist/components/ui/text.js +0 -177
  69. package/dist/components/ui/textarea.js +0 -19
  70. package/dist/components/ui/toast.js +0 -175
  71. package/dist/components/ui/view.js +0 -252
  72. package/dist/hooks/index.js +0 -14
  73. package/dist/hooks/useAvatars.js +0 -35
  74. package/dist/hooks/useCameraToggle.js +0 -12
  75. package/dist/hooks/useKeyboard.js +0 -36
  76. package/dist/hooks/useKeyboardSlide.js +0 -14
  77. package/dist/hooks/useLivestreamInfo.js +0 -65
  78. package/dist/hooks/useOuterAndInnerDimensions.js +0 -30
  79. package/dist/hooks/usePlayerDimensions.js +0 -22
  80. package/dist/hooks/usePointerDevice.js +0 -71
  81. package/dist/hooks/useSegmentDimensions.js +0 -17
  82. package/dist/hooks/useSegmentTiming.js +0 -65
  83. package/dist/index.js +0 -34
  84. package/dist/lib/facet.js +0 -92
  85. package/dist/lib/system-messages.js +0 -101
  86. package/dist/lib/theme/atoms.js +0 -646
  87. package/dist/lib/theme/atoms.types.js +0 -6
  88. package/dist/lib/theme/index.js +0 -35
  89. package/dist/lib/theme/theme.js +0 -256
  90. package/dist/lib/theme/tokens.js +0 -659
  91. package/dist/lib/utils.js +0 -105
  92. package/dist/livestream-provider/index.js +0 -30
  93. package/dist/livestream-provider/websocket.js +0 -45
  94. package/dist/livestream-store/chat.js +0 -286
  95. package/dist/livestream-store/context.js +0 -5
  96. package/dist/livestream-store/index.js +0 -7
  97. package/dist/livestream-store/livestream-state.js +0 -2
  98. package/dist/livestream-store/livestream-store.js +0 -58
  99. package/dist/livestream-store/problems.js +0 -76
  100. package/dist/livestream-store/stream-key.js +0 -119
  101. package/dist/livestream-store/websocket-consumer.js +0 -94
  102. package/dist/player-store/context.js +0 -5
  103. package/dist/player-store/index.js +0 -9
  104. package/dist/player-store/player-provider.js +0 -57
  105. package/dist/player-store/player-state.js +0 -25
  106. package/dist/player-store/player-store.js +0 -199
  107. package/dist/player-store/single-player-provider.js +0 -121
  108. package/dist/streamplace-provider/context.js +0 -5
  109. package/dist/streamplace-provider/index.js +0 -20
  110. package/dist/streamplace-provider/poller.js +0 -49
  111. package/dist/streamplace-provider/xrpc.js +0 -0
  112. package/dist/streamplace-store/block.js +0 -65
  113. package/dist/streamplace-store/index.js +0 -6
  114. package/dist/streamplace-store/stream.js +0 -218
  115. package/dist/streamplace-store/streamplace-store.js +0 -47
  116. package/dist/streamplace-store/user.js +0 -52
  117. package/dist/streamplace-store/xrpc.js +0 -15
  118. package/dist/ui/index.js +0 -79
  119. package/node-compile-cache/v22.15.0-x64-efe9a9df-0/37be0eec +0 -0
  120. package/node-compile-cache/v22.15.0-x64-efe9a9df-0/56540125 +0 -0
  121. package/node-compile-cache/v22.15.0-x64-efe9a9df-0/67b1eb60 +0 -0
  122. package/node-compile-cache/v22.15.0-x64-efe9a9df-0/7c275f90 +0 -0
  123. package/tsconfig.tsbuildinfo +0 -1
@@ -1,460 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = WebVideo;
4
- exports.ProgressiveMP4Player = ProgressiveMP4Player;
5
- exports.ProgressiveWebMPlayer = ProgressiveWebMPlayer;
6
- exports.HLSPlayer = HLSPlayer;
7
- exports.WebRTCPlayer = WebRTCPlayer;
8
- exports.WebRTCPlayerInner = WebRTCPlayerInner;
9
- exports.WebcamIngestPlayer = WebcamIngestPlayer;
10
- const tslib_1 = require("tslib");
11
- const jsx_runtime_1 = require("react/jsx-runtime");
12
- const hls_js_1 = tslib_1.__importDefault(require("hls.js"));
13
- const react_1 = require("react");
14
- const __1 = require("../..");
15
- const atoms_1 = require("../../lib/theme/atoms");
16
- const index_1 = require("../ui/index");
17
- const loader_1 = require("../ui/loader");
18
- const shared_1 = require("./shared");
19
- const use_webrtc_1 = tslib_1.__importStar(require("./use-webrtc"));
20
- const webrtc_diagnostics_1 = require("./webrtc-diagnostics");
21
- const webrtc_primitives_1 = require("./webrtc-primitives");
22
- function assignVideoRef(ref, instance) {
23
- if (!ref)
24
- return;
25
- if (typeof ref === "function")
26
- ref(instance);
27
- else
28
- ref.current = instance;
29
- }
30
- function useVideoDimensions(videoRef) {
31
- const [dimensions, setDimensions] = (0, react_1.useState)({ width: 0, height: 0 });
32
- (0, react_1.useEffect)(() => {
33
- if (!videoRef.current)
34
- return;
35
- function updateSize() {
36
- setDimensions({
37
- width: videoRef.current?.videoWidth || 0,
38
- height: videoRef.current?.videoHeight || 0,
39
- });
40
- }
41
- updateSize();
42
- const observer = new window.ResizeObserver(updateSize);
43
- observer.observe(videoRef.current);
44
- videoRef.current.addEventListener("loadedmetadata", updateSize);
45
- videoRef.current.addEventListener("resize", updateSize);
46
- return () => {
47
- observer.disconnect();
48
- videoRef.current?.removeEventListener("loadedmetadata", updateSize);
49
- videoRef.current?.removeEventListener("resize", updateSize);
50
- };
51
- }, [videoRef, videoRef.current]);
52
- return dimensions;
53
- }
54
- function WebVideo() {
55
- const inProto = (0, __1.usePlayerStore)((x) => x.protocol);
56
- const isIngesting = (0, __1.usePlayerStore)((x) => x.ingestConnectionState !== null);
57
- const selectedRendition = (0, __1.usePlayerStore)((x) => x.selectedRendition);
58
- const src = (0, __1.usePlayerStore)((x) => x.src);
59
- const setPlayerWidth = (0, __1.usePlayerStore)((x) => x.setPlayerWidth);
60
- const setPlayerHeight = (0, __1.usePlayerStore)((x) => x.setPlayerHeight);
61
- const { url, protocol } = (0, shared_1.srcToUrl)({ src: src, selectedRendition }, inProto);
62
- const videoRef = (0, react_1.useRef)(null);
63
- const dimensions = useVideoDimensions(videoRef);
64
- (0, react_1.useEffect)(() => {
65
- if (videoRef.current) {
66
- setPlayerWidth(dimensions.width);
67
- setPlayerHeight(dimensions.height);
68
- }
69
- }, [dimensions, setPlayerWidth, setPlayerHeight]);
70
- const playerProps = { url, videoRef };
71
- return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: isIngesting ? ((0, jsx_runtime_1.jsx)(WebcamIngestPlayer, { ...playerProps })) : protocol === __1.PlayerProtocol.PROGRESSIVE_MP4 ? ((0, jsx_runtime_1.jsx)(ProgressiveMP4Player, { ...playerProps })) : protocol === __1.PlayerProtocol.PROGRESSIVE_WEBM ? ((0, jsx_runtime_1.jsx)(ProgressiveWebMPlayer, { ...playerProps })) : protocol === __1.PlayerProtocol.HLS ? ((0, jsx_runtime_1.jsx)(HLSPlayer, { ...playerProps })) : protocol === __1.PlayerProtocol.WEBRTC ? ((0, jsx_runtime_1.jsx)(WebRTCPlayer, { ...playerProps })) : ((() => {
72
- throw new Error(`unknown playback protocol ${inProto}`);
73
- })()) }));
74
- }
75
- const updateEvents = {
76
- playing: true,
77
- waiting: true,
78
- stalled: true,
79
- pause: true,
80
- suspend: true,
81
- mute: true,
82
- };
83
- const VideoElement = (0, react_1.forwardRef)((props, ref) => {
84
- const x = (0, __1.usePlayerStore)((x) => x);
85
- const url = (0, __1.useStreamplaceStore)((x) => x.url);
86
- const playerEvent = (0, __1.usePlayerStore)((x) => x.playerEvent);
87
- const setMuted = (0, __1.usePlayerStore)((x) => x.setMuted);
88
- const setMuteWasForced = (0, __1.usePlayerStore)((x) => x.setMuteWasForced);
89
- const muted = (0, __1.usePlayerStore)((x) => x.muted);
90
- const ingest = (0, __1.usePlayerStore)((x) => x.ingestConnectionState !== null);
91
- const volume = (0, __1.usePlayerStore)((x) => x.volume);
92
- const setStatus = (0, __1.usePlayerStore)((x) => x.setStatus);
93
- const setUserInteraction = (0, __1.usePlayerStore)((x) => x.setUserInteraction);
94
- const setVideoRef = (0, __1.usePlayerStore)((x) => x.setVideoRef);
95
- const event = (evType) => (e) => {
96
- console.log(evType);
97
- const now = new Date();
98
- if (updateEvents[evType]) {
99
- x.setStatus(evType);
100
- }
101
- console.log("Sending", evType, "status to", url);
102
- playerEvent(url, now.toISOString(), evType, {});
103
- };
104
- const [firstAttempt, setFirstAttempt] = (0, react_1.useState)(true);
105
- const localVideoRef = props.videoRef ?? (0, react_1.useRef)(null);
106
- // setPipAction comes from Zustand store
107
- (0, react_1.useEffect)(() => {
108
- if (typeof x.setPipAction === "function") {
109
- const fn = () => {
110
- if (localVideoRef.current) {
111
- try {
112
- localVideoRef.current.requestPictureInPicture?.();
113
- }
114
- catch (err) {
115
- console.error("Error requesting Picture-in-Picture:", err);
116
- }
117
- }
118
- else {
119
- console.log("No video ref available for PiP");
120
- }
121
- };
122
- x.setPipAction(fn);
123
- }
124
- // Cleanup on unmount
125
- return () => {
126
- if (typeof x.setPipAction === "function") {
127
- x.setPipAction(undefined);
128
- }
129
- };
130
- }, []);
131
- const canPlayThrough = (e) => {
132
- console.log("canPlayThrough called", {
133
- firstAttempt,
134
- videoRef: !!localVideoRef.current,
135
- });
136
- setStatus(__1.PlayerStatus.PLAYING);
137
- event("canplaythrough")(e);
138
- if (firstAttempt && localVideoRef.current) {
139
- setFirstAttempt(false);
140
- console.log("Attempting to play video");
141
- localVideoRef.current.play().catch((err) => {
142
- console.log("error playing video", err.name);
143
- if (err.name === "NotAllowedError") {
144
- if (localVideoRef.current) {
145
- console.log("Setting muted and retrying");
146
- setMuted(true);
147
- localVideoRef.current.muted = true;
148
- localVideoRef.current
149
- .play()
150
- .then(() => {
151
- console.log("Muted play succeeded");
152
- setMuteWasForced(true);
153
- })
154
- .catch((err) => {
155
- console.error("Muted play also failed", err);
156
- });
157
- }
158
- }
159
- });
160
- }
161
- };
162
- (0, react_1.useEffect)(() => {
163
- return () => {
164
- setStatus(__1.PlayerStatus.START);
165
- };
166
- }, []);
167
- (0, react_1.useEffect)(() => {
168
- if (localVideoRef.current) {
169
- localVideoRef.current.volume = volume;
170
- console.log("Setting volume to", volume);
171
- }
172
- }, [volume]);
173
- (0, react_1.useEffect)(() => {
174
- console.log(localVideoRef.current?.width, localVideoRef.current?.height);
175
- setVideoRef(localVideoRef);
176
- }, [setVideoRef, localVideoRef]);
177
- const handleVideoRef = (videoElement) => {
178
- if (typeof ref === "function") {
179
- ref(videoElement);
180
- }
181
- else if (ref) {
182
- ref.current =
183
- videoElement;
184
- }
185
- localVideoRef.current = videoElement;
186
- };
187
- const eventLogger = (evType) => (e) => {
188
- console.log("📺 Video event:", evType);
189
- const now = new Date();
190
- if (updateEvents[evType]) {
191
- x.setStatus(evType);
192
- }
193
- console.log("Sending", evType, "status to", url);
194
- playerEvent(url, now.toISOString(), evType, {});
195
- };
196
- return ((0, jsx_runtime_1.jsx)("video", { autoPlay: true, playsInline: true, ref: handleVideoRef, controls: false, src: ingest ? undefined : props.url, muted: muted, crossOrigin: "anonymous", onMouseMove: setUserInteraction, onClick: setUserInteraction, onAbort: event("abort"), onCanPlay: eventLogger, onCanPlayThroughCapture: eventLogger, onCanPlayThrough: canPlayThrough, onEmptied: event("emptied"), onEncrypted: event("encrypted"), onEnded: event("ended"), onError: event("error"), onLoadedData: event("loadeddata"), onLoadedMetadata: event("loadedmetadata"), onLoadStart: event("loadstart"), onPause: event("pause"), onPlay: event("play"), onPlaying: event("playing"), onRateChange: event("ratechange"), onSeeked: event("seeked"), onSeeking: event("seeking"), onStalled: event("stalled"), onSuspend: event("suspend"), onVolumeChange: event("volumechange"), onWaiting: event("waiting"), style: {
197
- objectFit: "contain",
198
- backgroundColor: "transparent",
199
- width: "100%",
200
- height: "100%",
201
- maxWidth: "100%",
202
- maxHeight: "100%",
203
- transform: ingest ? "scaleX(-1)" : undefined,
204
- } }));
205
- });
206
- function ProgressiveMP4Player(props) {
207
- return (0, jsx_runtime_1.jsx)(VideoElement, { ...props });
208
- }
209
- function ProgressiveWebMPlayer(props) {
210
- return (0, jsx_runtime_1.jsx)(VideoElement, { ...props });
211
- }
212
- function HLSPlayer(props) {
213
- const localRef = (0, react_1.useRef)(null);
214
- (0, react_1.useEffect)(() => {
215
- if (!localRef.current) {
216
- return;
217
- }
218
- if (hls_js_1.default.isSupported()) {
219
- var hls = new hls_js_1.default({ maxAudioFramesDrift: 20 });
220
- hls.loadSource(props.url);
221
- try {
222
- hls.attachMedia(localRef.current);
223
- }
224
- catch (e) {
225
- console.error("error on attachMedia");
226
- hls.stopLoad();
227
- return;
228
- }
229
- hls.on(hls_js_1.default.Events.MANIFEST_PARSED, () => {
230
- if (!localRef.current) {
231
- return;
232
- }
233
- localRef.current.play();
234
- });
235
- return () => {
236
- hls.stopLoad();
237
- };
238
- }
239
- else if (localRef.current.canPlayType("application/vnd.apple.mpegurl")) {
240
- localRef.current.src = props.url;
241
- localRef.current.addEventListener("canplay", () => {
242
- if (!localRef.current) {
243
- return;
244
- }
245
- localRef.current.play();
246
- });
247
- }
248
- }, [props.url]);
249
- return (0, jsx_runtime_1.jsx)(VideoElement, { ...props, ref: localRef });
250
- }
251
- function WebRTCPlayer(props) {
252
- const [webrtcError, setWebrtcError] = (0, react_1.useState)(null);
253
- const setStatus = (0, __1.usePlayerStore)((x) => x.setStatus);
254
- const setProtocol = (0, __1.usePlayerStore)((x) => x.setProtocol);
255
- const diagnostics = (0, webrtc_diagnostics_1.useWebRTCDiagnostics)();
256
- // Check WebRTC compatibility on component mount
257
- (0, react_1.useEffect)(() => {
258
- try {
259
- (0, webrtc_primitives_1.checkWebRTCSupport)();
260
- console.log("WebRTC Player - Browser compatibility check passed");
261
- (0, webrtc_diagnostics_1.logWebRTCDiagnostics)();
262
- }
263
- catch (error) {
264
- console.error("WebRTC Player - Compatibility error:", error.message);
265
- setWebrtcError(error.message);
266
- setStatus(__1.PlayerStatus.START);
267
- return;
268
- }
269
- }, []);
270
- // Monitor diagnostics for errors
271
- (0, react_1.useEffect)(() => {
272
- if (!diagnostics.browserSupport && diagnostics.errors.length > 0) {
273
- setWebrtcError(diagnostics.errors.join(", "));
274
- }
275
- }, [diagnostics]);
276
- if (!diagnostics.done)
277
- return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, {});
278
- if (webrtcError) {
279
- setProtocol(__1.PlayerProtocol.HLS);
280
- return ((0, jsx_runtime_1.jsx)(index_1.View, { backgroundColor: "#111", children: (0, jsx_runtime_1.jsxs)(index_1.View, { children: [(0, jsx_runtime_1.jsx)(index_1.View, { children: (0, jsx_runtime_1.jsx)(index_1.Text, { children: "WebRTC Not Supported" }) }), (0, jsx_runtime_1.jsx)(index_1.Text, { children: webrtcError }), diagnostics.errors.length > 0 && ((0, jsx_runtime_1.jsxs)(index_1.View, { children: [(0, jsx_runtime_1.jsx)(index_1.Text, { children: "Technical Details:" }), diagnostics.errors.map((error, index) => ((0, jsx_runtime_1.jsxs)(index_1.Text, { children: ["\u2022 ", error] }, index)))] })), (0, jsx_runtime_1.jsx)(index_1.Text, { children: "\u2022 To use WebRTC, you may need to disable any blocking extensions or update your browser." }), (0, jsx_runtime_1.jsx)(index_1.Text, { style: [atoms_1.mt[2]], children: "Switching to HLS..." })] }) }));
281
- }
282
- return (0, jsx_runtime_1.jsx)(WebRTCPlayerInner, { url: props.url, videoRef: props.videoRef });
283
- }
284
- const connectionStatusMessages = {
285
- initializing: "Starting up...",
286
- connecting: "Connecting...",
287
- "connection-failed": "Connecting...",
288
- connected: "Connected",
289
- reconnecting: "Reconnecting...",
290
- checking: "Checking connection...",
291
- };
292
- function WebRTCPlayerInner({ videoRef, url, width, height, }) {
293
- const [connectionStatus, setConnectionStatus] = (0, react_1.useState)("initializing");
294
- const status = (0, __1.usePlayerStore)((x) => x.status);
295
- const setStatus = (0, __1.usePlayerStore)((x) => x.setStatus);
296
- const playerEvent = (0, __1.usePlayerStore)((x) => x.playerEvent);
297
- const spurl = (0, __1.useStreamplaceStore)((x) => x.url);
298
- const [mediaStream, stuck] = (0, use_webrtc_1.default)(url);
299
- (0, react_1.useEffect)(() => {
300
- if (stuck) {
301
- setConnectionStatus("connection-failed");
302
- }
303
- else if (mediaStream) {
304
- setConnectionStatus("connected");
305
- }
306
- else {
307
- setConnectionStatus("connecting");
308
- }
309
- }, [url, mediaStream, stuck, status]);
310
- (0, react_1.useEffect)(() => {
311
- if (stuck && status === __1.PlayerStatus.PLAYING) {
312
- setStatus(__1.PlayerStatus.STALLED);
313
- }
314
- if (!stuck && status === __1.PlayerStatus.STALLED) {
315
- setStatus(__1.PlayerStatus.PLAYING);
316
- }
317
- }, [stuck, status, mediaStream]);
318
- (0, react_1.useEffect)(() => {
319
- if (!mediaStream) {
320
- return;
321
- }
322
- const evt = (evType) => (e) => {
323
- console.log("webrtc event", evType);
324
- playerEvent(spurl, new Date().toISOString(), evType, {});
325
- };
326
- const active = evt("active");
327
- const inactive = evt("inactive");
328
- const ended = evt("ended");
329
- const mute = evt("mute");
330
- const unmute = evt("playing");
331
- mediaStream.addEventListener("active", active);
332
- mediaStream.addEventListener("inactive", inactive);
333
- mediaStream.addEventListener("ended", ended);
334
- for (const track of mediaStream.getTracks()) {
335
- track.addEventListener("ended", ended);
336
- track.addEventListener("mute", mute);
337
- track.addEventListener("unmute", unmute);
338
- }
339
- return () => {
340
- for (const track of mediaStream.getTracks()) {
341
- track.removeEventListener("ended", ended);
342
- track.removeEventListener("mute", mute);
343
- track.removeEventListener("unmute", unmute);
344
- }
345
- mediaStream.removeEventListener("active", active);
346
- mediaStream.removeEventListener("inactive", inactive);
347
- mediaStream.removeEventListener("ended", ended);
348
- };
349
- }, [mediaStream]);
350
- (0, react_1.useEffect)(() => {
351
- if (!videoRef || !videoRef.current) {
352
- return;
353
- }
354
- videoRef.current.srcObject = mediaStream;
355
- }, [mediaStream]);
356
- if (!mediaStream) {
357
- const isError = connectionStatus === "connection-failed";
358
- return ((0, jsx_runtime_1.jsx)(index_1.View, { backgroundColor: "#111", style: {
359
- minWidth: "100%",
360
- minHeight: "100%",
361
- display: "flex",
362
- alignItems: "center",
363
- justifyContent: "center",
364
- }, children: (0, jsx_runtime_1.jsxs)(index_1.View, { style: {
365
- borderRadius: atoms_1.borderRadius.md,
366
- padding: 24,
367
- alignItems: "center",
368
- gap: 16,
369
- }, children: [!isError && (0, jsx_runtime_1.jsx)(loader_1.Loader, { size: "large" }), (0, jsx_runtime_1.jsx)(index_1.Text, { size: "lg", weight: "semibold", children: connectionStatusMessages[connectionStatus] || "Connecting..." })] }) }));
370
- }
371
- return (0, jsx_runtime_1.jsx)(VideoElement, { url: url, ref: videoRef });
372
- }
373
- function WebcamIngestPlayer(props) {
374
- const ingestStarting = (0, __1.usePlayerStore)((x) => x.ingestStarting);
375
- const ingestMediaSource = (0, __1.usePlayerStore)((x) => x.ingestMediaSource);
376
- const ingestAutoStart = (0, __1.usePlayerStore)((x) => x.ingestAutoStart);
377
- const [error, setError] = (0, react_1.useState)(null);
378
- let streamKey = null;
379
- const [videoElement, setVideoElement] = (0, react_1.useState)(null);
380
- const handleRef = (0, react_1.useCallback)((node) => {
381
- if (node) {
382
- setVideoElement(node);
383
- }
384
- }, []);
385
- const url = (0, __1.useStreamplaceStore)((x) => x.url);
386
- const [localMediaStream, setLocalMediaStream] = (0, react_1.useState)(null);
387
- // we assign a stream key in the webrtcingest hook
388
- const [remoteMediaStream, setRemoteMediaStream] = (0, use_webrtc_1.useWebRTCIngest)({
389
- endpoint: `${url}/api/ingest/webrtc`,
390
- });
391
- (0, react_1.useEffect)(() => {
392
- if (ingestMediaSource === __1.IngestMediaSource.DISPLAY) {
393
- navigator.mediaDevices
394
- .getDisplayMedia({
395
- audio: true,
396
- video: true,
397
- })
398
- .then((stream) => {
399
- setLocalMediaStream(stream);
400
- })
401
- .catch((e) => {
402
- console.error("error getting display media", e);
403
- });
404
- }
405
- else {
406
- navigator.mediaDevices
407
- .getUserMedia({
408
- audio: true,
409
- video: {
410
- width: { min: 200, ideal: 1080, max: 2160 },
411
- height: { min: 200, ideal: 1920, max: 3840 },
412
- },
413
- })
414
- .then((stream) => {
415
- setLocalMediaStream(stream);
416
- })
417
- .catch((e) => {
418
- console.error("error getting user media", e.name);
419
- if (e.name == "NotAllowedError") {
420
- setError(new Error("Unable to access video! Please allow it in your browser settings."));
421
- }
422
- });
423
- }
424
- }, [ingestMediaSource]);
425
- (0, react_1.useEffect)(() => {
426
- if (!ingestStarting && !ingestAutoStart) {
427
- setRemoteMediaStream(null);
428
- return;
429
- }
430
- if (!localMediaStream) {
431
- return;
432
- }
433
- setRemoteMediaStream(localMediaStream);
434
- }, [localMediaStream, ingestStarting, ingestAutoStart]);
435
- (0, react_1.useEffect)(() => {
436
- if (!videoElement) {
437
- return;
438
- }
439
- if (!localMediaStream) {
440
- return;
441
- }
442
- videoElement.srcObject = localMediaStream;
443
- }, [videoElement, localMediaStream]);
444
- if (error) {
445
- return ((0, jsx_runtime_1.jsx)(index_1.View, { backgroundColor: "#111", style: {
446
- minWidth: "100%",
447
- minHeight: "100%",
448
- display: "flex",
449
- alignItems: "center",
450
- justifyContent: "center",
451
- }, children: (0, jsx_runtime_1.jsx)(index_1.View, { backgroundColor: atoms_1.colors.destructive[900], style: {
452
- borderRadius: atoms_1.borderRadius.md,
453
- padding: 24,
454
- alignItems: "center",
455
- gap: 16,
456
- maxWidth: 400,
457
- }, children: (0, jsx_runtime_1.jsx)(index_1.Text, { size: "xl", weight: "extrabold", color: "default", children: error.message }) }) }));
458
- }
459
- return (0, jsx_runtime_1.jsx)(VideoElement, { ...props, ref: handleRef });
460
- }