@dialtribe/react-sdk 0.1.0-alpha.10 → 0.1.0-alpha.12

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.
@@ -2,9 +2,9 @@ import { createContext, useState, useCallback, useEffect, useContext, useRef, Co
2
2
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
3
3
  import ReactPlayer from 'react-player';
4
4
 
5
- // src/context/DialTribeProvider.tsx
6
- var DialTribeContext = createContext(null);
7
- function DialTribeProvider({
5
+ // src/context/DialtribeProvider.tsx
6
+ var DialtribeContext = createContext(null);
7
+ function DialtribeProvider({
8
8
  sessionToken: initialToken,
9
9
  onTokenRefresh,
10
10
  onTokenExpired,
@@ -40,19 +40,19 @@ function DialTribeProvider({
40
40
  markExpired,
41
41
  apiBaseUrl
42
42
  };
43
- return /* @__PURE__ */ jsx(DialTribeContext.Provider, { value, children });
43
+ return /* @__PURE__ */ jsx(DialtribeContext.Provider, { value, children });
44
44
  }
45
- function useDialTribe() {
46
- const context = useContext(DialTribeContext);
45
+ function useDialtribe() {
46
+ const context = useContext(DialtribeContext);
47
47
  if (!context) {
48
48
  throw new Error(
49
- 'useDialTribe must be used within a DialTribeProvider. Wrap your app with <DialTribeProvider sessionToken="sess_xxx">...</DialTribeProvider>'
49
+ 'useDialtribe must be used within a DialtribeProvider. Wrap your app with <DialtribeProvider sessionToken="sess_xxx">...</DialtribeProvider>'
50
50
  );
51
51
  }
52
52
  return context;
53
53
  }
54
54
 
55
- // src/client/DialTribeClient.ts
55
+ // src/client/DialtribeClient.ts
56
56
  function getDefaultApiBaseUrl() {
57
57
  if (typeof process !== "undefined" && process.env?.NEXT_PUBLIC_DIALTRIBE_API_URL) {
58
58
  return process.env.NEXT_PUBLIC_DIALTRIBE_API_URL;
@@ -66,18 +66,19 @@ function getEndpoints(baseUrl = DIALTRIBE_API_BASE) {
66
66
  broadcast: (id) => `${baseUrl}/broadcasts/${id}`,
67
67
  contentPlay: `${baseUrl}/content/play`,
68
68
  presignedUrl: `${baseUrl}/media/presigned-url`,
69
- sessionStart: `${baseUrl}/session/start`,
70
- sessionPing: `${baseUrl}/session/ping`
69
+ audienceStart: `${baseUrl}/audiences/start`,
70
+ audiencePing: `${baseUrl}/audiences/ping`,
71
+ sessionPing: `${baseUrl}/sessions/ping`
71
72
  };
72
73
  }
73
74
  var ENDPOINTS = getEndpoints();
74
- var DialTribeClient = class {
75
+ var DialtribeClient = class {
75
76
  constructor(config) {
76
77
  this.config = config;
77
78
  this.endpoints = config.apiBaseUrl ? getEndpoints(config.apiBaseUrl) : ENDPOINTS;
78
79
  }
79
80
  /**
80
- * Make an authenticated request to DialTribe API
81
+ * Make an authenticated request to Dialtribe API
81
82
  *
82
83
  * Automatically:
83
84
  * - Adds Authorization header with session token
@@ -191,7 +192,7 @@ var DialTribeClient = class {
191
192
  * @returns audienceId and optional resumePosition
192
193
  */
193
194
  async startSession(params) {
194
- const response = await this.fetch(this.endpoints.sessionStart, {
195
+ const response = await this.fetch(this.endpoints.audienceStart, {
195
196
  method: "POST",
196
197
  body: JSON.stringify(params)
197
198
  });
@@ -210,7 +211,7 @@ var DialTribeClient = class {
210
211
  * - 3: UNMOUNT
211
212
  */
212
213
  async sendSessionPing(params) {
213
- const response = await this.fetch(this.endpoints.sessionPing, {
214
+ const response = await this.fetch(this.endpoints.audiencePing, {
214
215
  method: "POST",
215
216
  body: JSON.stringify(params)
216
217
  });
@@ -742,7 +743,7 @@ function getErrorMessage(error) {
742
743
  }
743
744
  return "Unable to play media. Please try refreshing the page or contact support if the problem persists.";
744
745
  }
745
- function BroadcastPlayer({
746
+ function DialtribePlayer({
746
747
  broadcast,
747
748
  appId,
748
749
  contentId,
@@ -753,18 +754,18 @@ function BroadcastPlayer({
753
754
  className = "",
754
755
  enableKeyboardShortcuts = false
755
756
  }) {
756
- const { sessionToken, setSessionToken, markExpired, apiBaseUrl } = useDialTribe();
757
+ const { sessionToken, setSessionToken, markExpired, apiBaseUrl } = useDialtribe();
757
758
  const clientRef = useRef(null);
758
759
  if (!clientRef.current && sessionToken) {
759
- clientRef.current = new DialTribeClient({
760
+ clientRef.current = new DialtribeClient({
760
761
  sessionToken,
761
762
  apiBaseUrl,
762
763
  onTokenRefresh: (newToken, expiresAt) => {
763
- debug.log(`[DialTribeClient] Token refreshed, expires at ${expiresAt}`);
764
+ debug.log(`[DialtribeClient] Token refreshed, expires at ${expiresAt}`);
764
765
  setSessionToken(newToken, expiresAt);
765
766
  },
766
767
  onTokenExpired: () => {
767
- debug.error("[DialTribeClient] Token expired");
768
+ debug.error("[DialtribeClient] Token expired");
768
769
  markExpired();
769
770
  }
770
771
  });
@@ -1209,7 +1210,7 @@ function BroadcastPlayer({
1209
1210
  setAudioElement(internalPlayer);
1210
1211
  }
1211
1212
  } catch (error) {
1212
- debug.error("[BroadcastPlayer] Error getting internal player:", error);
1213
+ debug.error("[DialtribePlayer] Error getting internal player:", error);
1213
1214
  }
1214
1215
  };
1215
1216
  useEffect(() => {
@@ -1417,7 +1418,7 @@ function BroadcastPlayer({
1417
1418
  return /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center p-8", children: /* @__PURE__ */ jsx(LoadingSpinner, { variant: "white", text: "Loading..." }) });
1418
1419
  }
1419
1420
  const hasTranscript = broadcast.transcriptStatus === 2 && transcriptData && (transcriptData.segments && transcriptData.segments.some((s) => s.words && s.words.length > 0) || transcriptData.words && transcriptData.words.length > 0);
1420
- return /* @__PURE__ */ jsxs("div", { className: `bg-black rounded-lg shadow-2xl w-full max-h-full flex flex-col overflow-hidden ${className}`, children: [
1421
+ const playerContent = /* @__PURE__ */ jsxs("div", { className: `bg-black rounded-lg shadow-2xl w-full max-h-full flex flex-col overflow-hidden ${className}`, children: [
1421
1422
  /* @__PURE__ */ jsxs("div", { className: "bg-zinc-900/50 backdrop-blur-sm border-b border-zinc-800 px-3 sm:px-4 md:px-6 py-2 sm:py-3 md:py-4 flex justify-between items-center rounded-t-lg shrink-0", children: [
1422
1423
  /* @__PURE__ */ jsxs("div", { children: [
1423
1424
  /* @__PURE__ */ jsx("h3", { className: "text-lg font-semibold text-white", children: broadcast.streamKeyRecord?.foreignName || "Broadcast" }),
@@ -1949,90 +1950,9 @@ function BroadcastPlayer({
1949
1950
  }
1950
1951
  ` })
1951
1952
  ] });
1953
+ return playerContent;
1952
1954
  }
1953
- function BroadcastPlayerModal({
1954
- broadcast,
1955
- isOpen,
1956
- onClose,
1957
- appId,
1958
- contentId,
1959
- foreignId,
1960
- foreignTier,
1961
- renderClipCreator,
1962
- className,
1963
- enableKeyboardShortcuts = false
1964
- }) {
1965
- const closeButtonRef = useRef(null);
1966
- const previousActiveElement = useRef(null);
1967
- useEffect(() => {
1968
- if (!isOpen) return;
1969
- previousActiveElement.current = document.activeElement;
1970
- setTimeout(() => {
1971
- closeButtonRef.current?.focus();
1972
- }, 100);
1973
- return () => {
1974
- if (previousActiveElement.current) {
1975
- previousActiveElement.current.focus();
1976
- }
1977
- };
1978
- }, [isOpen]);
1979
- useEffect(() => {
1980
- if (!isOpen) return;
1981
- const handleKeyDown = (e) => {
1982
- if (e.key === "Escape") {
1983
- onClose();
1984
- }
1985
- };
1986
- document.addEventListener("keydown", handleKeyDown);
1987
- return () => document.removeEventListener("keydown", handleKeyDown);
1988
- }, [isOpen, onClose]);
1989
- if (!isOpen) return null;
1990
- const handleBackdropClick = (e) => {
1991
- if (e.target === e.currentTarget) {
1992
- onClose();
1993
- }
1994
- };
1995
- return /* @__PURE__ */ jsx(
1996
- "div",
1997
- {
1998
- className: "fixed inset-0 bg-black/70 backdrop-blur-xl flex items-center justify-center z-50 p-2 sm:p-4",
1999
- onClick: handleBackdropClick,
2000
- role: "dialog",
2001
- "aria-modal": "true",
2002
- "aria-label": "Broadcast player",
2003
- children: /* @__PURE__ */ jsxs("div", { className: "relative w-full max-w-7xl max-h-[95vh] sm:max-h-[90vh] overflow-hidden", children: [
2004
- /* @__PURE__ */ jsx(
2005
- "button",
2006
- {
2007
- ref: closeButtonRef,
2008
- onClick: onClose,
2009
- className: "absolute top-2 right-2 sm:top-4 sm:right-4 z-10 text-gray-400 hover:text-white text-2xl leading-none transition-colors w-8 h-8 flex items-center justify-center bg-black/50 rounded-full",
2010
- title: "Close (ESC)",
2011
- "aria-label": "Close player",
2012
- children: "\xD7"
2013
- }
2014
- ),
2015
- /* @__PURE__ */ jsx(
2016
- BroadcastPlayer,
2017
- {
2018
- broadcast,
2019
- appId,
2020
- contentId,
2021
- foreignId,
2022
- foreignTier,
2023
- renderClipCreator,
2024
- className,
2025
- enableKeyboardShortcuts,
2026
- onError: (error) => {
2027
- debug.error("[BroadcastPlayerModal] Player error:", error);
2028
- }
2029
- }
2030
- )
2031
- ] })
2032
- }
2033
- );
2034
- }
2035
- var BroadcastPlayerErrorBoundary = class extends Component {
1955
+ var DialtribePlayerErrorBoundary = class extends Component {
2036
1956
  constructor(props) {
2037
1957
  super(props);
2038
1958
  this.handleReset = () => {
@@ -2158,7 +2078,85 @@ var BroadcastPlayerErrorBoundary = class extends Component {
2158
2078
  return this.props.children;
2159
2079
  }
2160
2080
  };
2081
+ var overlayStyles = {
2082
+ modal: {
2083
+ backdrop: "bg-black/70 backdrop-blur-xl p-2 sm:p-4",
2084
+ container: "max-w-7xl max-h-[95vh] sm:max-h-[90vh]"
2085
+ },
2086
+ fullscreen: {
2087
+ backdrop: "bg-black",
2088
+ container: "h-full"
2089
+ }
2090
+ };
2091
+ function DialtribeOverlay({
2092
+ isOpen,
2093
+ onClose,
2094
+ mode = "modal",
2095
+ children,
2096
+ ariaLabel = "Dialog",
2097
+ showCloseButton = true,
2098
+ closeOnBackdropClick = true,
2099
+ closeOnEsc = true
2100
+ }) {
2101
+ const closeButtonRef = useRef(null);
2102
+ const previousActiveElement = useRef(null);
2103
+ useEffect(() => {
2104
+ if (!isOpen) return;
2105
+ previousActiveElement.current = document.activeElement;
2106
+ setTimeout(() => {
2107
+ closeButtonRef.current?.focus();
2108
+ }, 100);
2109
+ return () => {
2110
+ if (previousActiveElement.current) {
2111
+ previousActiveElement.current.focus();
2112
+ }
2113
+ };
2114
+ }, [isOpen]);
2115
+ useEffect(() => {
2116
+ if (!isOpen || !closeOnEsc) return;
2117
+ const handleKeyDown = (e) => {
2118
+ if (e.key === "Escape") {
2119
+ onClose();
2120
+ }
2121
+ };
2122
+ document.addEventListener("keydown", handleKeyDown);
2123
+ return () => document.removeEventListener("keydown", handleKeyDown);
2124
+ }, [isOpen, onClose, closeOnEsc]);
2125
+ if (!isOpen) {
2126
+ return null;
2127
+ }
2128
+ const handleBackdropClick = (e) => {
2129
+ if (closeOnBackdropClick && e.target === e.currentTarget) {
2130
+ onClose();
2131
+ }
2132
+ };
2133
+ const styles = overlayStyles[mode];
2134
+ return /* @__PURE__ */ jsx(
2135
+ "div",
2136
+ {
2137
+ className: `fixed inset-0 flex items-center justify-center z-50 ${styles.backdrop}`,
2138
+ onClick: handleBackdropClick,
2139
+ role: "dialog",
2140
+ "aria-modal": "true",
2141
+ "aria-label": ariaLabel,
2142
+ children: /* @__PURE__ */ jsxs("div", { className: `relative w-full overflow-hidden ${styles.container}`, children: [
2143
+ showCloseButton && /* @__PURE__ */ jsx(
2144
+ "button",
2145
+ {
2146
+ ref: closeButtonRef,
2147
+ onClick: onClose,
2148
+ className: "absolute top-2 right-2 sm:top-4 sm:right-4 z-10 text-gray-400 hover:text-white text-2xl leading-none transition-colors w-8 h-8 flex items-center justify-center bg-black/50 rounded-full",
2149
+ title: "Close (ESC)",
2150
+ "aria-label": "Close",
2151
+ children: "\xD7"
2152
+ }
2153
+ ),
2154
+ children
2155
+ ] })
2156
+ }
2157
+ );
2158
+ }
2161
2159
 
2162
- export { AudioWaveform, BroadcastPlayer, BroadcastPlayerErrorBoundary, BroadcastPlayerModal, CDN_DOMAIN, DIALTRIBE_API_BASE, DialTribeClient, DialTribeProvider, ENDPOINTS, HTTP_STATUS, LoadingSpinner, buildBroadcastCdnUrl, buildBroadcastS3KeyPrefix, formatTime, useDialTribe };
2163
- //# sourceMappingURL=broadcast-player.mjs.map
2164
- //# sourceMappingURL=broadcast-player.mjs.map
2160
+ export { AudioWaveform, CDN_DOMAIN, DIALTRIBE_API_BASE, DialtribeClient, DialtribeOverlay, DialtribePlayer, DialtribePlayerErrorBoundary, DialtribeProvider, ENDPOINTS, HTTP_STATUS, LoadingSpinner, buildBroadcastCdnUrl, buildBroadcastS3KeyPrefix, formatTime, useDialtribe };
2161
+ //# sourceMappingURL=dialtribe-player.mjs.map
2162
+ //# sourceMappingURL=dialtribe-player.mjs.map