@dialtribe/react-sdk 0.1.0-alpha.5 → 0.1.0-alpha.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/broadcast-player.d.mts +49 -18
- package/dist/broadcast-player.d.ts +49 -18
- package/dist/broadcast-player.js +30 -17
- package/dist/broadcast-player.js.map +1 -1
- package/dist/broadcast-player.mjs +30 -17
- package/dist/broadcast-player.mjs.map +1 -1
- package/dist/index.js +30 -17
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +30 -17
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -14,6 +14,8 @@ interface DialTribeContextValue {
|
|
|
14
14
|
isExpired: boolean;
|
|
15
15
|
/** Mark token as expired */
|
|
16
16
|
markExpired: () => void;
|
|
17
|
+
/** Optional API base URL override */
|
|
18
|
+
apiBaseUrl?: string;
|
|
17
19
|
}
|
|
18
20
|
interface DialTribeProviderProps {
|
|
19
21
|
/** Session token from your backend (required) */
|
|
@@ -22,6 +24,12 @@ interface DialTribeProviderProps {
|
|
|
22
24
|
onTokenRefresh?: (newToken: string, expiresAt: string) => void;
|
|
23
25
|
/** Called when the session token expires or becomes invalid */
|
|
24
26
|
onTokenExpired?: () => void;
|
|
27
|
+
/**
|
|
28
|
+
* Optional: Override API base URL (for local development)
|
|
29
|
+
* If not provided, uses NEXT_PUBLIC_DIALTRIBE_API_URL environment variable or production default
|
|
30
|
+
* @example "http://localhost:3001/api/public/v1"
|
|
31
|
+
*/
|
|
32
|
+
apiBaseUrl?: string;
|
|
25
33
|
/** Your React app */
|
|
26
34
|
children: React$1.ReactNode;
|
|
27
35
|
}
|
|
@@ -32,22 +40,32 @@ interface DialTribeProviderProps {
|
|
|
32
40
|
*
|
|
33
41
|
* @example
|
|
34
42
|
* ```tsx
|
|
43
|
+
* // Production (default)
|
|
44
|
+
* <DialTribeProvider
|
|
45
|
+
* sessionToken="sess_xxx..."
|
|
46
|
+
* onTokenRefresh={(newToken) => setToken(newToken)}
|
|
47
|
+
* onTokenExpired={() => router.push('/login')}
|
|
48
|
+
* >
|
|
49
|
+
* <App />
|
|
50
|
+
* </DialTribeProvider>
|
|
51
|
+
*
|
|
52
|
+
* // Local development (explicit)
|
|
35
53
|
* <DialTribeProvider
|
|
36
54
|
* sessionToken="sess_xxx..."
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
* setToken(newToken);
|
|
40
|
-
* }}
|
|
41
|
-
* onTokenExpired={() => {
|
|
42
|
-
* // Redirect to login or refresh
|
|
43
|
-
* router.push('/login');
|
|
44
|
-
* }}
|
|
55
|
+
* apiBaseUrl="http://localhost:3001/api/public/v1"
|
|
56
|
+
* onTokenRefresh={(newToken) => setToken(newToken)}
|
|
45
57
|
* >
|
|
46
58
|
* <App />
|
|
47
59
|
* </DialTribeProvider>
|
|
60
|
+
*
|
|
61
|
+
* // Local development (via env var - recommended)
|
|
62
|
+
* // Set NEXT_PUBLIC_DIALTRIBE_API_URL=http://localhost:3001/api/public/v1 in .env
|
|
63
|
+
* <DialTribeProvider sessionToken="sess_xxx...">
|
|
64
|
+
* <App />
|
|
65
|
+
* </DialTribeProvider>
|
|
48
66
|
* ```
|
|
49
67
|
*/
|
|
50
|
-
declare function DialTribeProvider({ sessionToken: initialToken, onTokenRefresh, onTokenExpired, children, }: DialTribeProviderProps): react_jsx_runtime.JSX.Element;
|
|
68
|
+
declare function DialTribeProvider({ sessionToken: initialToken, onTokenRefresh, onTokenExpired, apiBaseUrl, children, }: DialTribeProviderProps): react_jsx_runtime.JSX.Element;
|
|
51
69
|
/**
|
|
52
70
|
* Hook to access DialTribe context
|
|
53
71
|
*
|
|
@@ -63,19 +81,25 @@ declare function useDialTribe(): DialTribeContextValue;
|
|
|
63
81
|
/**
|
|
64
82
|
* DialTribe API Client
|
|
65
83
|
*
|
|
66
|
-
* Handles all API communication with
|
|
84
|
+
* Handles all API communication with DialTribe endpoints.
|
|
67
85
|
* Automatically manages session token refresh via X-Session-Token headers.
|
|
86
|
+
*
|
|
87
|
+
* Supports configurable API base URL for development:
|
|
88
|
+
* 1. Via environment variable: NEXT_PUBLIC_DIALTRIBE_API_URL
|
|
89
|
+
* 2. Via apiBaseUrl prop on DialTribeProvider (takes precedence)
|
|
90
|
+
*
|
|
91
|
+
* Defaults to production URL if neither is specified.
|
|
68
92
|
*/
|
|
69
|
-
/**
|
|
70
|
-
declare const DIALTRIBE_API_BASE
|
|
71
|
-
/** API endpoints (
|
|
93
|
+
/** Default API base URL (production or from environment) */
|
|
94
|
+
declare const DIALTRIBE_API_BASE: string;
|
|
95
|
+
/** Default API endpoints (uses default base URL) */
|
|
72
96
|
declare const ENDPOINTS: {
|
|
73
|
-
readonly broadcasts:
|
|
97
|
+
readonly broadcasts: `${string}/broadcasts`;
|
|
74
98
|
readonly broadcast: (id: number) => string;
|
|
75
|
-
readonly contentPlay:
|
|
76
|
-
readonly presignedUrl:
|
|
77
|
-
readonly sessionStart:
|
|
78
|
-
readonly sessionPing:
|
|
99
|
+
readonly contentPlay: `${string}/content/play`;
|
|
100
|
+
readonly presignedUrl: `${string}/media/presigned-url`;
|
|
101
|
+
readonly sessionStart: `${string}/session/start`;
|
|
102
|
+
readonly sessionPing: `${string}/session/ping`;
|
|
79
103
|
};
|
|
80
104
|
interface ApiClientConfig {
|
|
81
105
|
/** Session token for authentication */
|
|
@@ -84,6 +108,12 @@ interface ApiClientConfig {
|
|
|
84
108
|
onTokenRefresh?: (newToken: string, expiresAt: string) => void;
|
|
85
109
|
/** Called when token expires or becomes invalid */
|
|
86
110
|
onTokenExpired?: () => void;
|
|
111
|
+
/**
|
|
112
|
+
* Optional: Override API base URL (e.g., for local development)
|
|
113
|
+
* If not provided, uses environment variable or production default
|
|
114
|
+
* @example "http://localhost:3001/api/public/v1"
|
|
115
|
+
*/
|
|
116
|
+
apiBaseUrl?: string;
|
|
87
117
|
}
|
|
88
118
|
/**
|
|
89
119
|
* DialTribe API Client
|
|
@@ -93,6 +123,7 @@ interface ApiClientConfig {
|
|
|
93
123
|
*/
|
|
94
124
|
declare class DialTribeClient {
|
|
95
125
|
private config;
|
|
126
|
+
private endpoints;
|
|
96
127
|
constructor(config: ApiClientConfig);
|
|
97
128
|
/**
|
|
98
129
|
* Make an authenticated request to DialTribe API
|
|
@@ -14,6 +14,8 @@ interface DialTribeContextValue {
|
|
|
14
14
|
isExpired: boolean;
|
|
15
15
|
/** Mark token as expired */
|
|
16
16
|
markExpired: () => void;
|
|
17
|
+
/** Optional API base URL override */
|
|
18
|
+
apiBaseUrl?: string;
|
|
17
19
|
}
|
|
18
20
|
interface DialTribeProviderProps {
|
|
19
21
|
/** Session token from your backend (required) */
|
|
@@ -22,6 +24,12 @@ interface DialTribeProviderProps {
|
|
|
22
24
|
onTokenRefresh?: (newToken: string, expiresAt: string) => void;
|
|
23
25
|
/** Called when the session token expires or becomes invalid */
|
|
24
26
|
onTokenExpired?: () => void;
|
|
27
|
+
/**
|
|
28
|
+
* Optional: Override API base URL (for local development)
|
|
29
|
+
* If not provided, uses NEXT_PUBLIC_DIALTRIBE_API_URL environment variable or production default
|
|
30
|
+
* @example "http://localhost:3001/api/public/v1"
|
|
31
|
+
*/
|
|
32
|
+
apiBaseUrl?: string;
|
|
25
33
|
/** Your React app */
|
|
26
34
|
children: React$1.ReactNode;
|
|
27
35
|
}
|
|
@@ -32,22 +40,32 @@ interface DialTribeProviderProps {
|
|
|
32
40
|
*
|
|
33
41
|
* @example
|
|
34
42
|
* ```tsx
|
|
43
|
+
* // Production (default)
|
|
44
|
+
* <DialTribeProvider
|
|
45
|
+
* sessionToken="sess_xxx..."
|
|
46
|
+
* onTokenRefresh={(newToken) => setToken(newToken)}
|
|
47
|
+
* onTokenExpired={() => router.push('/login')}
|
|
48
|
+
* >
|
|
49
|
+
* <App />
|
|
50
|
+
* </DialTribeProvider>
|
|
51
|
+
*
|
|
52
|
+
* // Local development (explicit)
|
|
35
53
|
* <DialTribeProvider
|
|
36
54
|
* sessionToken="sess_xxx..."
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
* setToken(newToken);
|
|
40
|
-
* }}
|
|
41
|
-
* onTokenExpired={() => {
|
|
42
|
-
* // Redirect to login or refresh
|
|
43
|
-
* router.push('/login');
|
|
44
|
-
* }}
|
|
55
|
+
* apiBaseUrl="http://localhost:3001/api/public/v1"
|
|
56
|
+
* onTokenRefresh={(newToken) => setToken(newToken)}
|
|
45
57
|
* >
|
|
46
58
|
* <App />
|
|
47
59
|
* </DialTribeProvider>
|
|
60
|
+
*
|
|
61
|
+
* // Local development (via env var - recommended)
|
|
62
|
+
* // Set NEXT_PUBLIC_DIALTRIBE_API_URL=http://localhost:3001/api/public/v1 in .env
|
|
63
|
+
* <DialTribeProvider sessionToken="sess_xxx...">
|
|
64
|
+
* <App />
|
|
65
|
+
* </DialTribeProvider>
|
|
48
66
|
* ```
|
|
49
67
|
*/
|
|
50
|
-
declare function DialTribeProvider({ sessionToken: initialToken, onTokenRefresh, onTokenExpired, children, }: DialTribeProviderProps): react_jsx_runtime.JSX.Element;
|
|
68
|
+
declare function DialTribeProvider({ sessionToken: initialToken, onTokenRefresh, onTokenExpired, apiBaseUrl, children, }: DialTribeProviderProps): react_jsx_runtime.JSX.Element;
|
|
51
69
|
/**
|
|
52
70
|
* Hook to access DialTribe context
|
|
53
71
|
*
|
|
@@ -63,19 +81,25 @@ declare function useDialTribe(): DialTribeContextValue;
|
|
|
63
81
|
/**
|
|
64
82
|
* DialTribe API Client
|
|
65
83
|
*
|
|
66
|
-
* Handles all API communication with
|
|
84
|
+
* Handles all API communication with DialTribe endpoints.
|
|
67
85
|
* Automatically manages session token refresh via X-Session-Token headers.
|
|
86
|
+
*
|
|
87
|
+
* Supports configurable API base URL for development:
|
|
88
|
+
* 1. Via environment variable: NEXT_PUBLIC_DIALTRIBE_API_URL
|
|
89
|
+
* 2. Via apiBaseUrl prop on DialTribeProvider (takes precedence)
|
|
90
|
+
*
|
|
91
|
+
* Defaults to production URL if neither is specified.
|
|
68
92
|
*/
|
|
69
|
-
/**
|
|
70
|
-
declare const DIALTRIBE_API_BASE
|
|
71
|
-
/** API endpoints (
|
|
93
|
+
/** Default API base URL (production or from environment) */
|
|
94
|
+
declare const DIALTRIBE_API_BASE: string;
|
|
95
|
+
/** Default API endpoints (uses default base URL) */
|
|
72
96
|
declare const ENDPOINTS: {
|
|
73
|
-
readonly broadcasts:
|
|
97
|
+
readonly broadcasts: `${string}/broadcasts`;
|
|
74
98
|
readonly broadcast: (id: number) => string;
|
|
75
|
-
readonly contentPlay:
|
|
76
|
-
readonly presignedUrl:
|
|
77
|
-
readonly sessionStart:
|
|
78
|
-
readonly sessionPing:
|
|
99
|
+
readonly contentPlay: `${string}/content/play`;
|
|
100
|
+
readonly presignedUrl: `${string}/media/presigned-url`;
|
|
101
|
+
readonly sessionStart: `${string}/session/start`;
|
|
102
|
+
readonly sessionPing: `${string}/session/ping`;
|
|
79
103
|
};
|
|
80
104
|
interface ApiClientConfig {
|
|
81
105
|
/** Session token for authentication */
|
|
@@ -84,6 +108,12 @@ interface ApiClientConfig {
|
|
|
84
108
|
onTokenRefresh?: (newToken: string, expiresAt: string) => void;
|
|
85
109
|
/** Called when token expires or becomes invalid */
|
|
86
110
|
onTokenExpired?: () => void;
|
|
111
|
+
/**
|
|
112
|
+
* Optional: Override API base URL (e.g., for local development)
|
|
113
|
+
* If not provided, uses environment variable or production default
|
|
114
|
+
* @example "http://localhost:3001/api/public/v1"
|
|
115
|
+
*/
|
|
116
|
+
apiBaseUrl?: string;
|
|
87
117
|
}
|
|
88
118
|
/**
|
|
89
119
|
* DialTribe API Client
|
|
@@ -93,6 +123,7 @@ interface ApiClientConfig {
|
|
|
93
123
|
*/
|
|
94
124
|
declare class DialTribeClient {
|
|
95
125
|
private config;
|
|
126
|
+
private endpoints;
|
|
96
127
|
constructor(config: ApiClientConfig);
|
|
97
128
|
/**
|
|
98
129
|
* Make an authenticated request to DialTribe API
|
package/dist/broadcast-player.js
CHANGED
|
@@ -14,6 +14,7 @@ function DialTribeProvider({
|
|
|
14
14
|
sessionToken: initialToken,
|
|
15
15
|
onTokenRefresh,
|
|
16
16
|
onTokenExpired,
|
|
17
|
+
apiBaseUrl,
|
|
17
18
|
children
|
|
18
19
|
}) {
|
|
19
20
|
const [sessionToken, setSessionTokenState] = react.useState(initialToken);
|
|
@@ -42,7 +43,8 @@ function DialTribeProvider({
|
|
|
42
43
|
sessionToken,
|
|
43
44
|
setSessionToken,
|
|
44
45
|
isExpired,
|
|
45
|
-
markExpired
|
|
46
|
+
markExpired,
|
|
47
|
+
apiBaseUrl
|
|
46
48
|
};
|
|
47
49
|
return /* @__PURE__ */ jsxRuntime.jsx(DialTribeContext.Provider, { value, children });
|
|
48
50
|
}
|
|
@@ -57,18 +59,28 @@ function useDialTribe() {
|
|
|
57
59
|
}
|
|
58
60
|
|
|
59
61
|
// src/client/DialTribeClient.ts
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
62
|
+
function getDefaultApiBaseUrl() {
|
|
63
|
+
if (typeof process !== "undefined" && process.env?.NEXT_PUBLIC_DIALTRIBE_API_URL) {
|
|
64
|
+
return process.env.NEXT_PUBLIC_DIALTRIBE_API_URL;
|
|
65
|
+
}
|
|
66
|
+
return "https://dialtribe.com/api/public/v1";
|
|
67
|
+
}
|
|
68
|
+
var DIALTRIBE_API_BASE = getDefaultApiBaseUrl();
|
|
69
|
+
function getEndpoints(baseUrl = DIALTRIBE_API_BASE) {
|
|
70
|
+
return {
|
|
71
|
+
broadcasts: `${baseUrl}/broadcasts`,
|
|
72
|
+
broadcast: (id) => `${baseUrl}/broadcasts/${id}`,
|
|
73
|
+
contentPlay: `${baseUrl}/content/play`,
|
|
74
|
+
presignedUrl: `${baseUrl}/media/presigned-url`,
|
|
75
|
+
sessionStart: `${baseUrl}/session/start`,
|
|
76
|
+
sessionPing: `${baseUrl}/session/ping`
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
var ENDPOINTS = getEndpoints();
|
|
69
80
|
var DialTribeClient = class {
|
|
70
81
|
constructor(config) {
|
|
71
82
|
this.config = config;
|
|
83
|
+
this.endpoints = config.apiBaseUrl ? getEndpoints(config.apiBaseUrl) : ENDPOINTS;
|
|
72
84
|
}
|
|
73
85
|
/**
|
|
74
86
|
* Make an authenticated request to DialTribe API
|
|
@@ -115,7 +127,7 @@ var DialTribeClient = class {
|
|
|
115
127
|
if (params?.broadcastStatus) searchParams.set("broadcastStatus", params.broadcastStatus.toString());
|
|
116
128
|
if (params?.search) searchParams.set("search", params.search);
|
|
117
129
|
if (params?.includeDeleted) searchParams.set("includeDeleted", "true");
|
|
118
|
-
const url = `${
|
|
130
|
+
const url = `${this.endpoints.broadcasts}${searchParams.toString() ? `?${searchParams}` : ""}`;
|
|
119
131
|
const response = await this.fetch(url);
|
|
120
132
|
if (!response.ok) {
|
|
121
133
|
throw new Error(`Failed to fetch broadcasts: ${response.status} ${response.statusText}`);
|
|
@@ -126,7 +138,7 @@ var DialTribeClient = class {
|
|
|
126
138
|
* Get a single broadcast by ID
|
|
127
139
|
*/
|
|
128
140
|
async getBroadcast(id) {
|
|
129
|
-
const response = await this.fetch(
|
|
141
|
+
const response = await this.fetch(this.endpoints.broadcast(id));
|
|
130
142
|
if (!response.ok) {
|
|
131
143
|
if (response.status === 404) {
|
|
132
144
|
throw new Error("Broadcast not found");
|
|
@@ -148,7 +160,7 @@ var DialTribeClient = class {
|
|
|
148
160
|
});
|
|
149
161
|
if (params.hash) searchParams.set("hash", params.hash);
|
|
150
162
|
if (params.action) searchParams.set("action", params.action);
|
|
151
|
-
const url = `${
|
|
163
|
+
const url = `${this.endpoints.contentPlay}?${searchParams}`;
|
|
152
164
|
const response = await this.fetch(url, {
|
|
153
165
|
redirect: "manual"
|
|
154
166
|
// Don't follow redirect, we want the URL
|
|
@@ -172,7 +184,7 @@ var DialTribeClient = class {
|
|
|
172
184
|
hash: params.hash,
|
|
173
185
|
fileType: params.fileType
|
|
174
186
|
});
|
|
175
|
-
const url = `${
|
|
187
|
+
const url = `${this.endpoints.presignedUrl}?${searchParams}`;
|
|
176
188
|
const response = await this.fetch(url);
|
|
177
189
|
if (!response.ok) {
|
|
178
190
|
throw new Error(`Failed to refresh URL: ${response.status} ${response.statusText}`);
|
|
@@ -185,7 +197,7 @@ var DialTribeClient = class {
|
|
|
185
197
|
* @returns audienceId and optional resumePosition
|
|
186
198
|
*/
|
|
187
199
|
async startSession(params) {
|
|
188
|
-
const response = await this.fetch(
|
|
200
|
+
const response = await this.fetch(this.endpoints.sessionStart, {
|
|
189
201
|
method: "POST",
|
|
190
202
|
body: JSON.stringify(params)
|
|
191
203
|
});
|
|
@@ -204,7 +216,7 @@ var DialTribeClient = class {
|
|
|
204
216
|
* - 3: UNMOUNT
|
|
205
217
|
*/
|
|
206
218
|
async sendSessionPing(params) {
|
|
207
|
-
const response = await this.fetch(
|
|
219
|
+
const response = await this.fetch(this.endpoints.sessionPing, {
|
|
208
220
|
method: "POST",
|
|
209
221
|
body: JSON.stringify(params)
|
|
210
222
|
});
|
|
@@ -747,11 +759,12 @@ function BroadcastPlayer({
|
|
|
747
759
|
className = "",
|
|
748
760
|
enableKeyboardShortcuts = false
|
|
749
761
|
}) {
|
|
750
|
-
const { sessionToken, setSessionToken, markExpired } = useDialTribe();
|
|
762
|
+
const { sessionToken, setSessionToken, markExpired, apiBaseUrl } = useDialTribe();
|
|
751
763
|
const clientRef = react.useRef(null);
|
|
752
764
|
if (!clientRef.current && sessionToken) {
|
|
753
765
|
clientRef.current = new DialTribeClient({
|
|
754
766
|
sessionToken,
|
|
767
|
+
apiBaseUrl,
|
|
755
768
|
onTokenRefresh: (newToken, expiresAt) => {
|
|
756
769
|
debug.log(`[DialTribeClient] Token refreshed, expires at ${expiresAt}`);
|
|
757
770
|
setSessionToken(newToken, expiresAt);
|