@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.mjs
CHANGED
|
@@ -26,6 +26,7 @@ function DialTribeProvider({
|
|
|
26
26
|
sessionToken: initialToken,
|
|
27
27
|
onTokenRefresh,
|
|
28
28
|
onTokenExpired,
|
|
29
|
+
apiBaseUrl,
|
|
29
30
|
children
|
|
30
31
|
}) {
|
|
31
32
|
const [sessionToken, setSessionTokenState] = useState(initialToken);
|
|
@@ -54,7 +55,8 @@ function DialTribeProvider({
|
|
|
54
55
|
sessionToken,
|
|
55
56
|
setSessionToken,
|
|
56
57
|
isExpired,
|
|
57
|
-
markExpired
|
|
58
|
+
markExpired,
|
|
59
|
+
apiBaseUrl
|
|
58
60
|
};
|
|
59
61
|
return /* @__PURE__ */ jsx(DialTribeContext.Provider, { value, children });
|
|
60
62
|
}
|
|
@@ -69,18 +71,28 @@ function useDialTribe() {
|
|
|
69
71
|
}
|
|
70
72
|
|
|
71
73
|
// src/client/DialTribeClient.ts
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
74
|
+
function getDefaultApiBaseUrl() {
|
|
75
|
+
if (typeof process !== "undefined" && process.env?.NEXT_PUBLIC_DIALTRIBE_API_URL) {
|
|
76
|
+
return process.env.NEXT_PUBLIC_DIALTRIBE_API_URL;
|
|
77
|
+
}
|
|
78
|
+
return "https://dialtribe.com/api/public/v1";
|
|
79
|
+
}
|
|
80
|
+
var DIALTRIBE_API_BASE = getDefaultApiBaseUrl();
|
|
81
|
+
function getEndpoints(baseUrl = DIALTRIBE_API_BASE) {
|
|
82
|
+
return {
|
|
83
|
+
broadcasts: `${baseUrl}/broadcasts`,
|
|
84
|
+
broadcast: (id) => `${baseUrl}/broadcasts/${id}`,
|
|
85
|
+
contentPlay: `${baseUrl}/content/play`,
|
|
86
|
+
presignedUrl: `${baseUrl}/media/presigned-url`,
|
|
87
|
+
sessionStart: `${baseUrl}/session/start`,
|
|
88
|
+
sessionPing: `${baseUrl}/session/ping`
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
var ENDPOINTS = getEndpoints();
|
|
81
92
|
var DialTribeClient = class {
|
|
82
93
|
constructor(config) {
|
|
83
94
|
this.config = config;
|
|
95
|
+
this.endpoints = config.apiBaseUrl ? getEndpoints(config.apiBaseUrl) : ENDPOINTS;
|
|
84
96
|
}
|
|
85
97
|
/**
|
|
86
98
|
* Make an authenticated request to DialTribe API
|
|
@@ -127,7 +139,7 @@ var DialTribeClient = class {
|
|
|
127
139
|
if (params?.broadcastStatus) searchParams.set("broadcastStatus", params.broadcastStatus.toString());
|
|
128
140
|
if (params?.search) searchParams.set("search", params.search);
|
|
129
141
|
if (params?.includeDeleted) searchParams.set("includeDeleted", "true");
|
|
130
|
-
const url = `${
|
|
142
|
+
const url = `${this.endpoints.broadcasts}${searchParams.toString() ? `?${searchParams}` : ""}`;
|
|
131
143
|
const response = await this.fetch(url);
|
|
132
144
|
if (!response.ok) {
|
|
133
145
|
throw new Error(`Failed to fetch broadcasts: ${response.status} ${response.statusText}`);
|
|
@@ -138,7 +150,7 @@ var DialTribeClient = class {
|
|
|
138
150
|
* Get a single broadcast by ID
|
|
139
151
|
*/
|
|
140
152
|
async getBroadcast(id) {
|
|
141
|
-
const response = await this.fetch(
|
|
153
|
+
const response = await this.fetch(this.endpoints.broadcast(id));
|
|
142
154
|
if (!response.ok) {
|
|
143
155
|
if (response.status === 404) {
|
|
144
156
|
throw new Error("Broadcast not found");
|
|
@@ -160,7 +172,7 @@ var DialTribeClient = class {
|
|
|
160
172
|
});
|
|
161
173
|
if (params.hash) searchParams.set("hash", params.hash);
|
|
162
174
|
if (params.action) searchParams.set("action", params.action);
|
|
163
|
-
const url = `${
|
|
175
|
+
const url = `${this.endpoints.contentPlay}?${searchParams}`;
|
|
164
176
|
const response = await this.fetch(url, {
|
|
165
177
|
redirect: "manual"
|
|
166
178
|
// Don't follow redirect, we want the URL
|
|
@@ -184,7 +196,7 @@ var DialTribeClient = class {
|
|
|
184
196
|
hash: params.hash,
|
|
185
197
|
fileType: params.fileType
|
|
186
198
|
});
|
|
187
|
-
const url = `${
|
|
199
|
+
const url = `${this.endpoints.presignedUrl}?${searchParams}`;
|
|
188
200
|
const response = await this.fetch(url);
|
|
189
201
|
if (!response.ok) {
|
|
190
202
|
throw new Error(`Failed to refresh URL: ${response.status} ${response.statusText}`);
|
|
@@ -197,7 +209,7 @@ var DialTribeClient = class {
|
|
|
197
209
|
* @returns audienceId and optional resumePosition
|
|
198
210
|
*/
|
|
199
211
|
async startSession(params) {
|
|
200
|
-
const response = await this.fetch(
|
|
212
|
+
const response = await this.fetch(this.endpoints.sessionStart, {
|
|
201
213
|
method: "POST",
|
|
202
214
|
body: JSON.stringify(params)
|
|
203
215
|
});
|
|
@@ -216,7 +228,7 @@ var DialTribeClient = class {
|
|
|
216
228
|
* - 3: UNMOUNT
|
|
217
229
|
*/
|
|
218
230
|
async sendSessionPing(params) {
|
|
219
|
-
const response = await this.fetch(
|
|
231
|
+
const response = await this.fetch(this.endpoints.sessionPing, {
|
|
220
232
|
method: "POST",
|
|
221
233
|
body: JSON.stringify(params)
|
|
222
234
|
});
|
|
@@ -759,11 +771,12 @@ function BroadcastPlayer({
|
|
|
759
771
|
className = "",
|
|
760
772
|
enableKeyboardShortcuts = false
|
|
761
773
|
}) {
|
|
762
|
-
const { sessionToken, setSessionToken, markExpired } = useDialTribe();
|
|
774
|
+
const { sessionToken, setSessionToken, markExpired, apiBaseUrl } = useDialTribe();
|
|
763
775
|
const clientRef = useRef(null);
|
|
764
776
|
if (!clientRef.current && sessionToken) {
|
|
765
777
|
clientRef.current = new DialTribeClient({
|
|
766
778
|
sessionToken,
|
|
779
|
+
apiBaseUrl,
|
|
767
780
|
onTokenRefresh: (newToken, expiresAt) => {
|
|
768
781
|
debug.log(`[DialTribeClient] Token refreshed, expires at ${expiresAt}`);
|
|
769
782
|
setSessionToken(newToken, expiresAt);
|