@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
package/dist/index.js
CHANGED
|
@@ -32,6 +32,7 @@ function DialTribeProvider({
|
|
|
32
32
|
sessionToken: initialToken,
|
|
33
33
|
onTokenRefresh,
|
|
34
34
|
onTokenExpired,
|
|
35
|
+
apiBaseUrl,
|
|
35
36
|
children
|
|
36
37
|
}) {
|
|
37
38
|
const [sessionToken, setSessionTokenState] = react.useState(initialToken);
|
|
@@ -60,7 +61,8 @@ function DialTribeProvider({
|
|
|
60
61
|
sessionToken,
|
|
61
62
|
setSessionToken,
|
|
62
63
|
isExpired,
|
|
63
|
-
markExpired
|
|
64
|
+
markExpired,
|
|
65
|
+
apiBaseUrl
|
|
64
66
|
};
|
|
65
67
|
return /* @__PURE__ */ jsxRuntime.jsx(DialTribeContext.Provider, { value, children });
|
|
66
68
|
}
|
|
@@ -75,18 +77,28 @@ function useDialTribe() {
|
|
|
75
77
|
}
|
|
76
78
|
|
|
77
79
|
// src/client/DialTribeClient.ts
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
80
|
+
function getDefaultApiBaseUrl() {
|
|
81
|
+
if (typeof process !== "undefined" && process.env?.NEXT_PUBLIC_DIALTRIBE_API_URL) {
|
|
82
|
+
return process.env.NEXT_PUBLIC_DIALTRIBE_API_URL;
|
|
83
|
+
}
|
|
84
|
+
return "https://dialtribe.com/api/public/v1";
|
|
85
|
+
}
|
|
86
|
+
var DIALTRIBE_API_BASE = getDefaultApiBaseUrl();
|
|
87
|
+
function getEndpoints(baseUrl = DIALTRIBE_API_BASE) {
|
|
88
|
+
return {
|
|
89
|
+
broadcasts: `${baseUrl}/broadcasts`,
|
|
90
|
+
broadcast: (id) => `${baseUrl}/broadcasts/${id}`,
|
|
91
|
+
contentPlay: `${baseUrl}/content/play`,
|
|
92
|
+
presignedUrl: `${baseUrl}/media/presigned-url`,
|
|
93
|
+
sessionStart: `${baseUrl}/session/start`,
|
|
94
|
+
sessionPing: `${baseUrl}/session/ping`
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
var ENDPOINTS = getEndpoints();
|
|
87
98
|
var DialTribeClient = class {
|
|
88
99
|
constructor(config) {
|
|
89
100
|
this.config = config;
|
|
101
|
+
this.endpoints = config.apiBaseUrl ? getEndpoints(config.apiBaseUrl) : ENDPOINTS;
|
|
90
102
|
}
|
|
91
103
|
/**
|
|
92
104
|
* Make an authenticated request to DialTribe API
|
|
@@ -133,7 +145,7 @@ var DialTribeClient = class {
|
|
|
133
145
|
if (params?.broadcastStatus) searchParams.set("broadcastStatus", params.broadcastStatus.toString());
|
|
134
146
|
if (params?.search) searchParams.set("search", params.search);
|
|
135
147
|
if (params?.includeDeleted) searchParams.set("includeDeleted", "true");
|
|
136
|
-
const url = `${
|
|
148
|
+
const url = `${this.endpoints.broadcasts}${searchParams.toString() ? `?${searchParams}` : ""}`;
|
|
137
149
|
const response = await this.fetch(url);
|
|
138
150
|
if (!response.ok) {
|
|
139
151
|
throw new Error(`Failed to fetch broadcasts: ${response.status} ${response.statusText}`);
|
|
@@ -144,7 +156,7 @@ var DialTribeClient = class {
|
|
|
144
156
|
* Get a single broadcast by ID
|
|
145
157
|
*/
|
|
146
158
|
async getBroadcast(id) {
|
|
147
|
-
const response = await this.fetch(
|
|
159
|
+
const response = await this.fetch(this.endpoints.broadcast(id));
|
|
148
160
|
if (!response.ok) {
|
|
149
161
|
if (response.status === 404) {
|
|
150
162
|
throw new Error("Broadcast not found");
|
|
@@ -166,7 +178,7 @@ var DialTribeClient = class {
|
|
|
166
178
|
});
|
|
167
179
|
if (params.hash) searchParams.set("hash", params.hash);
|
|
168
180
|
if (params.action) searchParams.set("action", params.action);
|
|
169
|
-
const url = `${
|
|
181
|
+
const url = `${this.endpoints.contentPlay}?${searchParams}`;
|
|
170
182
|
const response = await this.fetch(url, {
|
|
171
183
|
redirect: "manual"
|
|
172
184
|
// Don't follow redirect, we want the URL
|
|
@@ -190,7 +202,7 @@ var DialTribeClient = class {
|
|
|
190
202
|
hash: params.hash,
|
|
191
203
|
fileType: params.fileType
|
|
192
204
|
});
|
|
193
|
-
const url = `${
|
|
205
|
+
const url = `${this.endpoints.presignedUrl}?${searchParams}`;
|
|
194
206
|
const response = await this.fetch(url);
|
|
195
207
|
if (!response.ok) {
|
|
196
208
|
throw new Error(`Failed to refresh URL: ${response.status} ${response.statusText}`);
|
|
@@ -203,7 +215,7 @@ var DialTribeClient = class {
|
|
|
203
215
|
* @returns audienceId and optional resumePosition
|
|
204
216
|
*/
|
|
205
217
|
async startSession(params) {
|
|
206
|
-
const response = await this.fetch(
|
|
218
|
+
const response = await this.fetch(this.endpoints.sessionStart, {
|
|
207
219
|
method: "POST",
|
|
208
220
|
body: JSON.stringify(params)
|
|
209
221
|
});
|
|
@@ -222,7 +234,7 @@ var DialTribeClient = class {
|
|
|
222
234
|
* - 3: UNMOUNT
|
|
223
235
|
*/
|
|
224
236
|
async sendSessionPing(params) {
|
|
225
|
-
const response = await this.fetch(
|
|
237
|
+
const response = await this.fetch(this.endpoints.sessionPing, {
|
|
226
238
|
method: "POST",
|
|
227
239
|
body: JSON.stringify(params)
|
|
228
240
|
});
|
|
@@ -765,11 +777,12 @@ function BroadcastPlayer({
|
|
|
765
777
|
className = "",
|
|
766
778
|
enableKeyboardShortcuts = false
|
|
767
779
|
}) {
|
|
768
|
-
const { sessionToken, setSessionToken, markExpired } = useDialTribe();
|
|
780
|
+
const { sessionToken, setSessionToken, markExpired, apiBaseUrl } = useDialTribe();
|
|
769
781
|
const clientRef = react.useRef(null);
|
|
770
782
|
if (!clientRef.current && sessionToken) {
|
|
771
783
|
clientRef.current = new DialTribeClient({
|
|
772
784
|
sessionToken,
|
|
785
|
+
apiBaseUrl,
|
|
773
786
|
onTokenRefresh: (newToken, expiresAt) => {
|
|
774
787
|
debug.log(`[DialTribeClient] Token refreshed, expires at ${expiresAt}`);
|
|
775
788
|
setSessionToken(newToken, expiresAt);
|