@streamplace/components 0.7.0 → 0.7.2

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 (97) hide show
  1. package/dist/components/chat/chat-box.js +46 -43
  2. package/dist/components/chat/chat-message.js +36 -33
  3. package/dist/components/chat/chat.js +31 -27
  4. package/dist/components/chat/mention-suggestions.js +16 -13
  5. package/dist/components/chat/mod-view.js +20 -17
  6. package/dist/components/mobile-player/fullscreen.js +21 -17
  7. package/dist/components/mobile-player/fullscreen.native.js +39 -35
  8. package/dist/components/mobile-player/player.js +38 -32
  9. package/dist/components/mobile-player/props.js +2 -1
  10. package/dist/components/mobile-player/shared.js +16 -13
  11. package/dist/components/mobile-player/ui/countdown.js +23 -19
  12. package/dist/components/mobile-player/ui/index.js +9 -5
  13. package/dist/components/mobile-player/ui/input.js +16 -12
  14. package/dist/components/mobile-player/ui/metrics.js +20 -16
  15. package/dist/components/mobile-player/ui/streamer-context-menu.js +6 -3
  16. package/dist/components/mobile-player/ui/viewer-context-menu.js +19 -16
  17. package/dist/components/mobile-player/ui/viewers.js +23 -0
  18. package/dist/components/mobile-player/use-webrtc.js +29 -24
  19. package/dist/components/mobile-player/video.js +109 -99
  20. package/dist/components/mobile-player/video.native.js +108 -84
  21. package/dist/components/mobile-player/webrtc-diagnostics.js +9 -5
  22. package/dist/components/mobile-player/webrtc-primitives.js +8 -6
  23. package/dist/components/mobile-player/webrtc-primitives.native.js +8 -1
  24. package/dist/components/ui/button.js +26 -23
  25. package/dist/components/ui/dialog.js +43 -40
  26. package/dist/components/ui/dropdown.js +121 -116
  27. package/dist/components/ui/icons.js +8 -5
  28. package/dist/components/ui/index.js +27 -19
  29. package/dist/components/ui/input.js +31 -28
  30. package/dist/components/ui/loader.js +9 -6
  31. package/dist/components/ui/primitives/button.js +33 -29
  32. package/dist/components/ui/primitives/input.js +44 -40
  33. package/dist/components/ui/primitives/modal.js +45 -41
  34. package/dist/components/ui/primitives/text.js +35 -29
  35. package/dist/components/ui/resizeable.js +54 -43
  36. package/dist/components/ui/text.js +50 -48
  37. package/dist/components/ui/textarea.js +13 -11
  38. package/dist/components/ui/toast.js +26 -23
  39. package/dist/components/ui/view.js +41 -39
  40. package/dist/hooks/index.js +12 -8
  41. package/dist/hooks/useAvatars.js +11 -8
  42. package/dist/hooks/useCameraToggle.js +7 -4
  43. package/dist/hooks/useKeyboard.js +13 -10
  44. package/dist/hooks/useKeyboardSlide.js +8 -5
  45. package/dist/hooks/useLivestreamInfo.js +17 -14
  46. package/dist/hooks/useOuterAndInnerDimensions.js +9 -6
  47. package/dist/hooks/usePlayerDimensions.js +9 -6
  48. package/dist/hooks/useSegmentDimensions.js +17 -0
  49. package/dist/hooks/useSegmentTiming.js +13 -10
  50. package/dist/index.js +24 -15
  51. package/dist/lib/facet.js +5 -1
  52. package/dist/lib/theme/atoms.js +153 -148
  53. package/dist/lib/theme/atoms.types.js +2 -1
  54. package/dist/lib/theme/index.js +31 -5
  55. package/dist/lib/theme/theme.js +91 -83
  56. package/dist/lib/theme/tokens.js +15 -12
  57. package/dist/lib/utils.js +22 -11
  58. package/dist/livestream-provider/index.js +19 -14
  59. package/dist/livestream-provider/websocket.js +14 -10
  60. package/dist/livestream-store/chat.js +26 -19
  61. package/dist/livestream-store/context.js +5 -2
  62. package/dist/livestream-store/index.js +7 -4
  63. package/dist/livestream-store/livestream-state.js +2 -1
  64. package/dist/livestream-store/livestream-store.js +31 -18
  65. package/dist/livestream-store/stream-key.js +22 -18
  66. package/dist/livestream-store/websocket-consumer.js +18 -14
  67. package/dist/player-store/context.js +5 -2
  68. package/dist/player-store/index.js +8 -5
  69. package/dist/player-store/player-provider.js +20 -15
  70. package/dist/player-store/player-state.js +9 -6
  71. package/dist/player-store/player-store.js +32 -21
  72. package/dist/player-store/single-player-provider.js +35 -23
  73. package/dist/streamplace-provider/context.js +5 -2
  74. package/dist/streamplace-provider/index.js +14 -10
  75. package/dist/streamplace-provider/poller.js +20 -17
  76. package/dist/streamplace-store/block.js +6 -3
  77. package/dist/streamplace-store/index.js +6 -3
  78. package/dist/streamplace-store/stream.js +14 -10
  79. package/dist/streamplace-store/streamplace-store.js +23 -13
  80. package/dist/streamplace-store/user.js +19 -14
  81. package/dist/streamplace-store/xrpc.js +10 -7
  82. package/node-compile-cache/v22.15.0-x64-92db9086-0/37be0eec +0 -0
  83. package/node-compile-cache/v22.15.0-x64-92db9086-0/56540125 +0 -0
  84. package/node-compile-cache/{v22.15.0-x64-efe9a9df-0 → v22.15.0-x64-92db9086-0}/67b1eb60 +0 -0
  85. package/node-compile-cache/{v22.15.0-x64-efe9a9df-0 → v22.15.0-x64-92db9086-0}/7c275f90 +0 -0
  86. package/package.json +6 -7
  87. package/src/components/mobile-player/ui/index.ts +1 -0
  88. package/src/components/mobile-player/ui/viewer-context-menu.tsx +5 -4
  89. package/src/components/mobile-player/ui/viewers.tsx +32 -0
  90. package/src/components/mobile-player/video.native.tsx +50 -5
  91. package/src/components/ui/resizeable.tsx +15 -3
  92. package/src/hooks/index.ts +1 -0
  93. package/src/hooks/useSegmentDimensions.tsx +18 -0
  94. package/tsconfig.json +2 -1
  95. package/tsconfig.tsbuildinfo +1 -1
  96. package/node-compile-cache/v22.15.0-x64-efe9a9df-0/37be0eec +0 -0
  97. package/node-compile-cache/v22.15.0-x64-efe9a9df-0/56540125 +0 -0
@@ -1,9 +1,14 @@
1
- import { useContext } from "react";
2
- import { createStore, useStore } from "zustand";
3
- import { LivestreamContext } from "./context";
4
- import { handleWebSocketMessages } from "./websocket-consumer";
5
- export const makeLivestreamStore = () => {
6
- return createStore()((set) => ({
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useRenditions = exports.useSegment = exports.useLivestream = exports.useViewers = exports.useProfile = exports.useChat = exports.useHandleWebsocketMessages = exports.makeLivestreamStore = void 0;
4
+ exports.getStoreFromContext = getStoreFromContext;
5
+ exports.useLivestreamStore = useLivestreamStore;
6
+ const react_1 = require("react");
7
+ const zustand_1 = require("zustand");
8
+ const context_1 = require("./context");
9
+ const websocket_consumer_1 = require("./websocket-consumer");
10
+ const makeLivestreamStore = () => {
11
+ return (0, zustand_1.createStore)()((set) => ({
7
12
  profile: null,
8
13
  chatIndex: {},
9
14
  chat: [],
@@ -17,26 +22,34 @@ export const makeLivestreamStore = () => {
17
22
  authors: {},
18
23
  }));
19
24
  };
20
- export function getStoreFromContext() {
21
- const context = useContext(LivestreamContext);
25
+ exports.makeLivestreamStore = makeLivestreamStore;
26
+ function getStoreFromContext() {
27
+ const context = (0, react_1.useContext)(context_1.LivestreamContext);
22
28
  if (!context) {
23
29
  throw new Error("useLivestreamStore must be used within a LivestreamProvider");
24
30
  }
25
31
  return context.store;
26
32
  }
27
- export function useLivestreamStore(selector) {
33
+ function useLivestreamStore(selector) {
28
34
  const store = getStoreFromContext();
29
- return useStore(store, selector);
35
+ return (0, zustand_1.useStore)(store, selector);
30
36
  }
31
- export const useHandleWebsocketMessages = () => {
37
+ const useHandleWebsocketMessages = () => {
32
38
  const store = getStoreFromContext();
33
39
  return (messages) => {
34
- store.setState((state) => handleWebSocketMessages(state, messages));
40
+ store.setState((state) => (0, websocket_consumer_1.handleWebSocketMessages)(state, messages));
35
41
  };
36
42
  };
37
- export const useChat = () => useLivestreamStore((x) => x.chat);
38
- export const useProfile = () => useLivestreamStore((x) => x.profile);
39
- export const useViewers = () => useLivestreamStore((x) => x.viewers);
40
- export const useLivestream = () => useLivestreamStore((x) => x.livestream);
41
- export const useSegment = () => useLivestreamStore((x) => x.segment);
42
- export const useRenditions = () => useLivestreamStore((x) => x.renditions);
43
+ exports.useHandleWebsocketMessages = useHandleWebsocketMessages;
44
+ const useChat = () => useLivestreamStore((x) => x.chat);
45
+ exports.useChat = useChat;
46
+ const useProfile = () => useLivestreamStore((x) => x.profile);
47
+ exports.useProfile = useProfile;
48
+ const useViewers = () => useLivestreamStore((x) => x.viewers);
49
+ exports.useViewers = useViewers;
50
+ const useLivestream = () => useLivestreamStore((x) => x.livestream);
51
+ exports.useLivestream = useLivestream;
52
+ const useSegment = () => useLivestreamStore((x) => x.segment);
53
+ exports.useSegment = useSegment;
54
+ const useRenditions = () => useLivestreamStore((x) => x.renditions);
55
+ exports.useRenditions = useRenditions;
@@ -1,9 +1,12 @@
1
- import { bytesToMultibase, Secp256k1Keypair } from "@atproto/crypto";
2
- import { useEffect, useState } from "react";
3
- import { Platform } from "react-native";
4
- import { privateKeyToAccount } from "viem/accounts";
5
- import { usePDSAgent } from "../streamplace-store/xrpc";
6
- import { useLivestreamStore } from "./livestream-store";
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useStreamKey = void 0;
4
+ const crypto_1 = require("@atproto/crypto");
5
+ const react_1 = require("react");
6
+ const react_native_1 = require("react-native");
7
+ const accounts_1 = require("viem/accounts");
8
+ const xrpc_1 = require("../streamplace-store/xrpc");
9
+ const livestream_store_1 = require("./livestream-store");
7
10
  function getBrowserName(userAgent) {
8
11
  // The order matters here, and this may report false positives for unlisted browsers.
9
12
  if (userAgent.includes("Firefox")) {
@@ -36,13 +39,13 @@ function getBrowserName(userAgent) {
36
39
  }
37
40
  return "unknown";
38
41
  }
39
- export const useStreamKey = () => {
40
- const pdsAgent = usePDSAgent();
41
- const streamKey = useLivestreamStore((state) => state.streamKey);
42
- const setStreamKey = useLivestreamStore((state) => state.setStreamKey);
43
- const [key, setKey] = useState(streamKey ? JSON.parse(streamKey) : null);
44
- const [error, setError] = useState(null);
45
- useEffect(() => {
42
+ const useStreamKey = () => {
43
+ const pdsAgent = (0, xrpc_1.usePDSAgent)();
44
+ const streamKey = (0, livestream_store_1.useLivestreamStore)((state) => state.streamKey);
45
+ const setStreamKey = (0, livestream_store_1.useLivestreamStore)((state) => state.setStreamKey);
46
+ const [key, setKey] = (0, react_1.useState)(streamKey ? JSON.parse(streamKey) : null);
47
+ const [error, setError] = (0, react_1.useState)(null);
48
+ (0, react_1.useEffect)(() => {
46
49
  if (key)
47
50
  return; // already have key
48
51
  const generateKey = async () => {
@@ -55,22 +58,22 @@ export const useStreamKey = () => {
55
58
  setError("PDS Agent did is not available (not logged in?)");
56
59
  return;
57
60
  }
58
- const keypair = await Secp256k1Keypair.create({ exportable: true });
61
+ const keypair = await crypto_1.Secp256k1Keypair.create({ exportable: true });
59
62
  const exportedKey = await keypair.export();
60
63
  const didBytes = new TextEncoder().encode(did);
61
64
  const combinedKey = new Uint8Array([...exportedKey, ...didBytes]);
62
- const multibaseKey = bytesToMultibase(combinedKey, "base58btc");
65
+ const multibaseKey = (0, crypto_1.bytesToMultibase)(combinedKey, "base58btc");
63
66
  const hexKey = Array.from(exportedKey)
64
67
  .map((b) => b.toString(16).padStart(2, "0"))
65
68
  .join("");
66
- const account = privateKeyToAccount(`0x${hexKey}`);
69
+ const account = (0, accounts_1.privateKeyToAccount)(`0x${hexKey}`);
67
70
  const newKey = {
68
71
  privateKey: multibaseKey,
69
72
  did: keypair.did(),
70
73
  address: account.address.toLowerCase(),
71
74
  };
72
- let platform = Platform.OS;
73
- if (Platform.OS === "web" &&
75
+ let platform = react_native_1.Platform.OS;
76
+ if (react_native_1.Platform.OS === "web" &&
74
77
  typeof window !== "undefined" &&
75
78
  window.navigator) {
76
79
  if (window.navigator.userAgent.includes("streamplace-desktop")) {
@@ -113,3 +116,4 @@ export const useStreamKey = () => {
113
116
  }, [key, setStreamKey]);
114
117
  return { streamKey: key, error };
115
118
  };
119
+ exports.useStreamKey = useStreamKey;
@@ -1,21 +1,24 @@
1
- import { AppBskyActorDefs } from "@atproto/api";
2
- import { PlaceStreamChatDefs, PlaceStreamDefs, PlaceStreamLivestream, PlaceStreamSegment, } from "streamplace";
3
- import { reduceChat } from "./chat";
4
- export const handleWebSocketMessages = (state, messages) => {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.handleWebSocketMessages = void 0;
4
+ const api_1 = require("@atproto/api");
5
+ const streamplace_1 = require("streamplace");
6
+ const chat_1 = require("./chat");
7
+ const handleWebSocketMessages = (state, messages) => {
5
8
  for (const message of messages) {
6
- if (PlaceStreamLivestream.isLivestreamView(message)) {
9
+ if (streamplace_1.PlaceStreamLivestream.isLivestreamView(message)) {
7
10
  state = {
8
11
  ...state,
9
12
  livestream: message,
10
13
  };
11
14
  }
12
- else if (PlaceStreamLivestream.isViewerCount(message)) {
15
+ else if (streamplace_1.PlaceStreamLivestream.isViewerCount(message)) {
13
16
  state = {
14
17
  ...state,
15
18
  viewers: message.count,
16
19
  };
17
20
  }
18
- else if (PlaceStreamChatDefs.isMessageView(message)) {
21
+ else if (streamplace_1.PlaceStreamChatDefs.isMessageView(message)) {
19
22
  // Explicitly map MessageView to MessageViewHydrated
20
23
  const hydrated = {
21
24
  uri: message.uri,
@@ -26,30 +29,31 @@ export const handleWebSocketMessages = (state, messages) => {
26
29
  chatProfile: message.chatProfile,
27
30
  replyTo: message.replyTo,
28
31
  };
29
- state = reduceChat(state, [hydrated], []);
32
+ state = (0, chat_1.reduceChat)(state, [hydrated], []);
30
33
  }
31
- else if (PlaceStreamSegment.isRecord(message)) {
34
+ else if (streamplace_1.PlaceStreamSegment.isRecord(message)) {
32
35
  state = {
33
36
  ...state,
34
37
  segment: message,
35
38
  };
36
39
  }
37
- else if (PlaceStreamDefs.isBlockView(message)) {
40
+ else if (streamplace_1.PlaceStreamDefs.isBlockView(message)) {
38
41
  const block = message;
39
- state = reduceChat(state, [], [block]);
42
+ state = (0, chat_1.reduceChat)(state, [], [block]);
40
43
  }
41
- else if (PlaceStreamDefs.isRenditions(message)) {
44
+ else if (streamplace_1.PlaceStreamDefs.isRenditions(message)) {
42
45
  state = {
43
46
  ...state,
44
47
  renditions: message.renditions,
45
48
  };
46
49
  }
47
- else if (AppBskyActorDefs.isProfileViewBasic(message)) {
50
+ else if (api_1.AppBskyActorDefs.isProfileViewBasic(message)) {
48
51
  state = {
49
52
  ...state,
50
53
  profile: message,
51
54
  };
52
55
  }
53
56
  }
54
- return reduceChat(state, [], []);
57
+ return (0, chat_1.reduceChat)(state, [], []);
55
58
  };
59
+ exports.handleWebSocketMessages = handleWebSocketMessages;
@@ -1,2 +1,5 @@
1
- import { createContext } from "react";
2
- export const PlayerContext = createContext(null);
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PlayerContext = void 0;
4
+ const react_1 = require("react");
5
+ exports.PlayerContext = (0, react_1.createContext)(null);
@@ -1,6 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
1
4
  // barrel file :)
2
- export * from "./context";
3
- export * from "./player-provider";
4
- export * from "./player-state";
5
- export * from "./player-store";
6
- export * from "./single-player-provider";
5
+ tslib_1.__exportStar(require("./context"), exports);
6
+ tslib_1.__exportStar(require("./player-provider"), exports);
7
+ tslib_1.__exportStar(require("./player-state"), exports);
8
+ tslib_1.__exportStar(require("./player-store"), exports);
9
+ tslib_1.__exportStar(require("./single-player-provider"), exports);
@@ -1,30 +1,34 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { useCallback, useMemo, useState } from "react";
3
- import { PlayerContext } from "./context";
4
- import { makePlayerStore } from "./player-store";
5
- export const PlayerProvider = ({ children, initialPlayers = [], defaultId = Math.random().toString(36).slice(8), }) => {
6
- const [players, setPlayers] = useState(() => {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PlayerProvider = void 0;
4
+ exports.withPlayerProvider = withPlayerProvider;
5
+ const jsx_runtime_1 = require("react/jsx-runtime");
6
+ const react_1 = require("react");
7
+ const context_1 = require("./context");
8
+ const player_store_1 = require("./player-store");
9
+ const PlayerProvider = ({ children, initialPlayers = [], defaultId = Math.random().toString(36).slice(8), }) => {
10
+ const [players, setPlayers] = (0, react_1.useState)(() => {
7
11
  // Initialize with any initial player IDs provided
8
12
  const initialPlayerStores = {};
9
13
  for (const playerId of initialPlayers) {
10
- initialPlayerStores[playerId] = makePlayerStore(playerId);
14
+ initialPlayerStores[playerId] = (0, player_store_1.makePlayerStore)(playerId);
11
15
  }
12
16
  // Always create at least one player by default
13
17
  if (initialPlayers.length === 0) {
14
- initialPlayerStores[defaultId] = makePlayerStore(defaultId);
18
+ initialPlayerStores[defaultId] = (0, player_store_1.makePlayerStore)(defaultId);
15
19
  }
16
20
  return initialPlayerStores;
17
21
  });
18
- const createPlayer = useCallback((id) => {
22
+ const createPlayer = (0, react_1.useCallback)((id) => {
19
23
  const playerId = id || Math.random().toString(36).slice(8);
20
- const playerStore = makePlayerStore(playerId);
24
+ const playerStore = (0, player_store_1.makePlayerStore)(playerId);
21
25
  setPlayers((prev) => ({
22
26
  ...prev,
23
27
  [playerId]: playerStore,
24
28
  }));
25
29
  return playerId;
26
30
  }, []);
27
- const removePlayer = useCallback((id) => {
31
+ const removePlayer = (0, react_1.useCallback)((id) => {
28
32
  setPlayers((prev) => {
29
33
  // Don't remove the last player
30
34
  if (Object.keys(prev).length <= 1) {
@@ -36,17 +40,18 @@ export const PlayerProvider = ({ children, initialPlayers = [], defaultId = Math
36
40
  return newPlayers;
37
41
  });
38
42
  }, []);
39
- const contextValue = useMemo(() => ({
43
+ const contextValue = (0, react_1.useMemo)(() => ({
40
44
  players,
41
45
  createPlayer,
42
46
  removePlayer,
43
47
  }), [players, createPlayer, removePlayer]);
44
- return (_jsx(PlayerContext.Provider, { value: contextValue, children: children }));
48
+ return ((0, jsx_runtime_1.jsx)(context_1.PlayerContext.Provider, { value: contextValue, children: children }));
45
49
  };
50
+ exports.PlayerProvider = PlayerProvider;
46
51
  // HOC to wrap components that need player context
47
- export function withPlayerProvider(Component) {
52
+ function withPlayerProvider(Component) {
48
53
  return function WithPlayerProvider(props) {
49
54
  const { initialPlayers, ...componentProps } = props;
50
- return (_jsx(PlayerProvider, { initialPlayers: initialPlayers, children: _jsx(Component, { ...componentProps }) }));
55
+ return ((0, jsx_runtime_1.jsx)(exports.PlayerProvider, { initialPlayers: initialPlayers, children: (0, jsx_runtime_1.jsx)(Component, { ...componentProps }) }));
51
56
  };
52
57
  }
@@ -1,11 +1,14 @@
1
- export var PlayerProtocol;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IngestMediaSource = exports.PlayerStatus = exports.PlayerProtocol = void 0;
4
+ var PlayerProtocol;
2
5
  (function (PlayerProtocol) {
3
6
  PlayerProtocol["WEBRTC"] = "webrtc";
4
7
  PlayerProtocol["HLS"] = "hls";
5
8
  PlayerProtocol["PROGRESSIVE_MP4"] = "progressive-mp4";
6
9
  PlayerProtocol["PROGRESSIVE_WEBM"] = "progressive-webm";
7
- })(PlayerProtocol || (PlayerProtocol = {}));
8
- export var PlayerStatus;
10
+ })(PlayerProtocol || (exports.PlayerProtocol = PlayerProtocol = {}));
11
+ var PlayerStatus;
9
12
  (function (PlayerStatus) {
10
13
  PlayerStatus["START"] = "start";
11
14
  PlayerStatus["PLAYING"] = "playing";
@@ -14,9 +17,9 @@ export var PlayerStatus;
14
17
  PlayerStatus["WAITING"] = "waiting";
15
18
  PlayerStatus["PAUSE"] = "pause";
16
19
  PlayerStatus["MUTE"] = "mute";
17
- })(PlayerStatus || (PlayerStatus = {}));
18
- export var IngestMediaSource;
20
+ })(PlayerStatus || (exports.PlayerStatus = PlayerStatus = {}));
21
+ var IngestMediaSource;
19
22
  (function (IngestMediaSource) {
20
23
  IngestMediaSource["USER"] = "user";
21
24
  IngestMediaSource["DISPLAY"] = "display";
22
- })(IngestMediaSource || (IngestMediaSource = {}));
25
+ })(IngestMediaSource || (exports.IngestMediaSource = IngestMediaSource = {}));
@@ -1,13 +1,21 @@
1
- import { useContext } from "react";
2
- import { createStore, useStore } from "zustand";
3
- import { PlayerContext } from "./context";
4
- import { PlayerProtocol, PlayerStatus, } from "./player-state";
5
- export const makePlayerStore = (id) => {
6
- return createStore()((set) => ({
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.intoPlayerProtocol = exports.usePlayerProtocol = exports.makePlayerStore = void 0;
4
+ exports.usePlayerContext = usePlayerContext;
5
+ exports.getPlayerStoreById = getPlayerStoreById;
6
+ exports.getFirstPlayerID = getFirstPlayerID;
7
+ exports.getPlayerStoreFromContext = getPlayerStoreFromContext;
8
+ exports.usePlayerStore = usePlayerStore;
9
+ const react_1 = require("react");
10
+ const zustand_1 = require("zustand");
11
+ const context_1 = require("./context");
12
+ const player_state_1 = require("./player-state");
13
+ const makePlayerStore = (id) => {
14
+ return (0, zustand_1.createStore)()((set) => ({
7
15
  id: id || Math.random().toString(36).slice(8),
8
16
  selectedRendition: "source",
9
17
  setSelectedRendition: (rendition) => set((state) => ({ ...state, selectedRendition: rendition })),
10
- protocol: PlayerProtocol.WEBRTC,
18
+ protocol: player_state_1.PlayerProtocol.WEBRTC,
11
19
  setProtocol: (protocol) => set((state) => ({ ...state, protocol: protocol })),
12
20
  src: "",
13
21
  setSrc: (src) => set(() => ({ src })),
@@ -29,7 +37,7 @@ export const makePlayerStore = (id) => {
29
37
  setVolume: (volume) => set(() => ({ volume, muteWasForced: false })),
30
38
  fullscreen: false,
31
39
  setFullscreen: (isFullscreen) => set(() => ({ fullscreen: isFullscreen })),
32
- status: PlayerStatus.START,
40
+ status: player_state_1.PlayerStatus.START,
33
41
  setStatus: (status) => set(() => ({ status })),
34
42
  playTime: 0,
35
43
  setPlayTime: (playTime) => set(() => ({ playTime })),
@@ -100,15 +108,16 @@ export const makePlayerStore = (id) => {
100
108
  setModMessage: (modMessage) => set(() => ({ modMessage })),
101
109
  }));
102
110
  };
103
- export function usePlayerContext() {
104
- const context = useContext(PlayerContext);
111
+ exports.makePlayerStore = makePlayerStore;
112
+ function usePlayerContext() {
113
+ const context = (0, react_1.useContext)(context_1.PlayerContext);
105
114
  if (!context) {
106
115
  throw new Error("usePlayerContext must be used within a PlayerProvider");
107
116
  }
108
117
  return context;
109
118
  }
110
119
  // Get a specific player store by ID
111
- export function getPlayerStoreById(id) {
120
+ function getPlayerStoreById(id) {
112
121
  const { players } = usePlayerContext();
113
122
  const playerStore = players[id];
114
123
  if (!playerStore) {
@@ -117,7 +126,7 @@ export function getPlayerStoreById(id) {
117
126
  return playerStore;
118
127
  }
119
128
  // Will get the first player ID in the context
120
- export function getFirstPlayerID() {
129
+ function getFirstPlayerID() {
121
130
  const { players } = usePlayerContext();
122
131
  const playerIds = Object.keys(players);
123
132
  if (playerIds.length === 0) {
@@ -125,7 +134,7 @@ export function getFirstPlayerID() {
125
134
  }
126
135
  return playerIds[0];
127
136
  }
128
- export function getPlayerStoreFromContext() {
137
+ function getPlayerStoreFromContext() {
129
138
  console.warn("getPlayerStoreFromContext is deprecated. Use getPlayerStoreById instead.");
130
139
  const { players } = usePlayerContext();
131
140
  const playerIds = Object.keys(players);
@@ -136,24 +145,26 @@ export function getPlayerStoreFromContext() {
136
145
  }
137
146
  // Use a specific player store by ID
138
147
  // If no ID is provided, it will use the first player in the context
139
- export function usePlayerStore(selector, playerId) {
148
+ function usePlayerStore(selector, playerId) {
140
149
  if (!playerId) {
141
150
  playerId = Object.keys(usePlayerContext().players)[0];
142
151
  }
143
152
  const store = getPlayerStoreById(playerId);
144
- return useStore(store, selector);
153
+ return (0, zustand_1.useStore)(store, selector);
145
154
  }
146
155
  /* Convenience selectors/hooks */
147
- export const usePlayerProtocol = (playerId) => usePlayerStore((x) => [x.protocol, x.setProtocol], playerId);
148
- export const intoPlayerProtocol = (protocol) => {
156
+ const usePlayerProtocol = (playerId) => usePlayerStore((x) => [x.protocol, x.setProtocol], playerId);
157
+ exports.usePlayerProtocol = usePlayerProtocol;
158
+ const intoPlayerProtocol = (protocol) => {
149
159
  switch (protocol) {
150
160
  case "hls":
151
- return PlayerProtocol.HLS;
161
+ return player_state_1.PlayerProtocol.HLS;
152
162
  case "progressive-mp4":
153
- return PlayerProtocol.PROGRESSIVE_MP4;
163
+ return player_state_1.PlayerProtocol.PROGRESSIVE_MP4;
154
164
  case "progressive-webm":
155
- return PlayerProtocol.PROGRESSIVE_WEBM;
165
+ return player_state_1.PlayerProtocol.PROGRESSIVE_WEBM;
156
166
  default:
157
- return PlayerProtocol.WEBRTC;
167
+ return player_state_1.PlayerProtocol.WEBRTC;
158
168
  }
159
169
  };
170
+ exports.intoPlayerProtocol = intoPlayerProtocol;
@@ -1,17 +1,28 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import React, { createContext, useContext, useMemo } from "react";
3
- import { useStore } from "zustand";
4
- import { usePlayerContext } from "../player-store";
5
- import { PlayerProtocol } from "./player-state";
6
- const SinglePlayerContext = createContext(null);
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SinglePlayerProvider = void 0;
4
+ exports.useSinglePlayerContext = useSinglePlayerContext;
5
+ exports.useCurrentPlayerId = useCurrentPlayerId;
6
+ exports.useCurrentPlayerStore = useCurrentPlayerStore;
7
+ exports.useCurrentPlayerProtocol = useCurrentPlayerProtocol;
8
+ exports.useCurrentPlayerRendition = useCurrentPlayerRendition;
9
+ exports.useCurrentPlayerIngest = useCurrentPlayerIngest;
10
+ exports.withSinglePlayer = withSinglePlayer;
11
+ const tslib_1 = require("tslib");
12
+ const jsx_runtime_1 = require("react/jsx-runtime");
13
+ const react_1 = tslib_1.__importStar(require("react"));
14
+ const zustand_1 = require("zustand");
15
+ const player_store_1 = require("../player-store");
16
+ const player_state_1 = require("./player-state");
17
+ const SinglePlayerContext = (0, react_1.createContext)(null);
7
18
  /**
8
19
  * Provider component for a single player that creates a scoped context
9
20
  * This allows components to access a specific player's state without passing IDs around
10
21
  */
11
- export const SinglePlayerProvider = ({ children, playerId: providedPlayerId, protocol = PlayerProtocol.WEBRTC, rendition = "auto", }) => {
12
- const { players, createPlayer } = usePlayerContext();
22
+ const SinglePlayerProvider = ({ children, playerId: providedPlayerId, protocol = player_state_1.PlayerProtocol.WEBRTC, rendition = "auto", }) => {
23
+ const { players, createPlayer } = (0, player_store_1.usePlayerContext)();
13
24
  // Create or get a player ID
14
- const playerId = useMemo(() => {
25
+ const playerId = (0, react_1.useMemo)(() => {
15
26
  // If a player ID is provided and exists, use it
16
27
  if (providedPlayerId && players[providedPlayerId]) {
17
28
  return providedPlayerId;
@@ -24,11 +35,11 @@ export const SinglePlayerProvider = ({ children, playerId: providedPlayerId, pro
24
35
  return createPlayer();
25
36
  }, [providedPlayerId, players, createPlayer]);
26
37
  // Get the player store
27
- const playerStore = useMemo(() => {
38
+ const playerStore = (0, react_1.useMemo)(() => {
28
39
  return players[playerId];
29
40
  }, [players, playerId]);
30
41
  // Set initial protocol and rendition if provided
31
- React.useEffect(() => {
42
+ react_1.default.useEffect(() => {
32
43
  if (protocol) {
33
44
  playerStore.setState((state) => ({
34
45
  ...state,
@@ -43,17 +54,18 @@ export const SinglePlayerProvider = ({ children, playerId: providedPlayerId, pro
43
54
  }
44
55
  }, [playerStore, protocol, rendition]);
45
56
  // Create context value
46
- const contextValue = useMemo(() => ({
57
+ const contextValue = (0, react_1.useMemo)(() => ({
47
58
  playerId,
48
59
  playerStore,
49
60
  }), [playerId, playerStore]);
50
- return (_jsx(SinglePlayerContext.Provider, { value: contextValue, children: children }));
61
+ return ((0, jsx_runtime_1.jsx)(SinglePlayerContext.Provider, { value: contextValue, children: children }));
51
62
  };
63
+ exports.SinglePlayerProvider = SinglePlayerProvider;
52
64
  /**
53
65
  * Hook to access the current single player context
54
66
  */
55
- export function useSinglePlayerContext() {
56
- const context = useContext(SinglePlayerContext);
67
+ function useSinglePlayerContext() {
68
+ const context = (0, react_1.useContext)(SinglePlayerContext);
57
69
  if (!context) {
58
70
  throw new Error("useSinglePlayerContext must be used within a SinglePlayerProvider");
59
71
  }
@@ -62,33 +74,33 @@ export function useSinglePlayerContext() {
62
74
  /**
63
75
  * Hook to access the current player ID from the single player context
64
76
  */
65
- export function useCurrentPlayerId() {
77
+ function useCurrentPlayerId() {
66
78
  const { playerId } = useSinglePlayerContext();
67
79
  return playerId;
68
80
  }
69
81
  /**
70
82
  * Hook to access state from the current player without needing to specify the ID
71
83
  */
72
- export function useCurrentPlayerStore(selector) {
84
+ function useCurrentPlayerStore(selector) {
73
85
  const { playerStore } = useSinglePlayerContext();
74
- return useStore(playerStore, selector);
86
+ return (0, zustand_1.useStore)(playerStore, selector);
75
87
  }
76
88
  /**
77
89
  * Hook to get the protocol of the current player
78
90
  */
79
- export function useCurrentPlayerProtocol() {
91
+ function useCurrentPlayerProtocol() {
80
92
  return useCurrentPlayerStore((state) => [state.protocol, state.setProtocol]);
81
93
  }
82
94
  /**
83
95
  * Hook to get the selected rendition of the current player
84
96
  */
85
- export function useCurrentPlayerRendition() {
97
+ function useCurrentPlayerRendition() {
86
98
  return useCurrentPlayerStore((state) => [state.selectedRendition, state.setSelectedRendition]);
87
99
  }
88
100
  /**
89
101
  * Hook to get the ingest state of the current player
90
102
  */
91
- export function useCurrentPlayerIngest() {
103
+ function useCurrentPlayerIngest() {
92
104
  return useCurrentPlayerStore((state) => ({
93
105
  starting: state.ingestStarting,
94
106
  setStarting: state.setIngestStarting,
@@ -101,9 +113,9 @@ export function useCurrentPlayerIngest() {
101
113
  /**
102
114
  * HOC to wrap components with a SinglePlayerProvider
103
115
  */
104
- export function withSinglePlayer(Component) {
116
+ function withSinglePlayer(Component) {
105
117
  return function WithSinglePlayer(props) {
106
118
  const { playerId, protocol, rendition, ...componentProps } = props;
107
- return (_jsx(SinglePlayerProvider, { playerId: playerId, protocol: protocol, rendition: rendition, children: _jsx(Component, { ...componentProps }) }));
119
+ return ((0, jsx_runtime_1.jsx)(exports.SinglePlayerProvider, { playerId: playerId, protocol: protocol, rendition: rendition, children: (0, jsx_runtime_1.jsx)(Component, { ...componentProps }) }));
108
120
  };
109
121
  }
@@ -1,2 +1,5 @@
1
- import { createContext } from "react";
2
- export const StreamplaceContext = createContext(null);
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StreamplaceContext = void 0;
4
+ const react_1 = require("react");
5
+ exports.StreamplaceContext = (0, react_1.createContext)(null);
@@ -1,16 +1,20 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { useEffect, useRef } from "react";
3
- import { makeStreamplaceStore } from "../streamplace-store/streamplace-store";
4
- import { StreamplaceContext } from "./context";
5
- import Poller from "./poller";
6
- export function StreamplaceProvider({ children, url, oauthSession, }) {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StreamplaceProvider = StreamplaceProvider;
4
+ const tslib_1 = require("tslib");
5
+ const jsx_runtime_1 = require("react/jsx-runtime");
6
+ const react_1 = require("react");
7
+ const streamplace_store_1 = require("../streamplace-store/streamplace-store");
8
+ const context_1 = require("./context");
9
+ const poller_1 = tslib_1.__importDefault(require("./poller"));
10
+ function StreamplaceProvider({ children, url, oauthSession, }) {
7
11
  // todo: handle url changes?
8
- const store = useRef(makeStreamplaceStore({ url })).current;
9
- useEffect(() => {
12
+ const store = (0, react_1.useRef)((0, streamplace_store_1.makeStreamplaceStore)({ url })).current;
13
+ (0, react_1.useEffect)(() => {
10
14
  store.setState({ url });
11
15
  }, [url]);
12
- useEffect(() => {
16
+ (0, react_1.useEffect)(() => {
13
17
  store.setState({ oauthSession });
14
18
  }, [oauthSession]);
15
- return (_jsx(StreamplaceContext.Provider, { value: { store: store }, children: _jsx(Poller, { children: children }) }));
19
+ return ((0, jsx_runtime_1.jsx)(context_1.StreamplaceContext.Provider, { value: { store: store }, children: (0, jsx_runtime_1.jsx)(poller_1.default, { children: children }) }));
16
20
  }