@thestatic-tv/dcl-sdk 1.0.0 → 1.0.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.
package/dist/index.d.mts CHANGED
@@ -84,6 +84,26 @@ interface InteractionResponse {
84
84
  alreadyExists: boolean;
85
85
  version: string;
86
86
  }
87
+ /**
88
+ * Scene stats for display in-world
89
+ */
90
+ interface SceneStats {
91
+ date: string;
92
+ totalSessions: number;
93
+ uniqueVisitors: number;
94
+ totalMinutes: number;
95
+ visitorNumber: number | null;
96
+ isFirstVisitor: boolean;
97
+ }
98
+ /**
99
+ * Scene stats response from the API
100
+ */
101
+ interface SceneStatsResponse {
102
+ success: boolean;
103
+ stats: SceneStats;
104
+ sceneName: string | null;
105
+ version: string;
106
+ }
87
107
 
88
108
  /**
89
109
  * Guide module - fetch channel lineup from thestatic.tv
@@ -160,6 +180,11 @@ declare class SessionModule {
160
180
  * Check if a session is currently active
161
181
  */
162
182
  isSessionActive(): boolean;
183
+ /**
184
+ * Get scene stats (visitors, sessions, etc.)
185
+ * Useful for displaying metrics in-world
186
+ */
187
+ getStats(): Promise<SceneStatsResponse['stats'] | null>;
163
188
  }
164
189
 
165
190
  /**
@@ -294,4 +319,4 @@ declare class StaticTVClient {
294
319
  destroy(): Promise<void>;
295
320
  }
296
321
 
297
- export { type Channel, GuideModule, type GuideResponse, HeartbeatModule, type HeartbeatResponse, type InteractionResponse, InteractionsModule, KEY_TYPE_CHANNEL, KEY_TYPE_SCENE, SessionModule, type SessionResponse, StaticTVClient, type StaticTVConfig, type Vod };
322
+ export { type Channel, GuideModule, type GuideResponse, HeartbeatModule, type HeartbeatResponse, type InteractionResponse, InteractionsModule, KEY_TYPE_CHANNEL, KEY_TYPE_SCENE, type SceneStats, type SceneStatsResponse, SessionModule, type SessionResponse, StaticTVClient, type StaticTVConfig, type Vod };
package/dist/index.d.ts CHANGED
@@ -84,6 +84,26 @@ interface InteractionResponse {
84
84
  alreadyExists: boolean;
85
85
  version: string;
86
86
  }
87
+ /**
88
+ * Scene stats for display in-world
89
+ */
90
+ interface SceneStats {
91
+ date: string;
92
+ totalSessions: number;
93
+ uniqueVisitors: number;
94
+ totalMinutes: number;
95
+ visitorNumber: number | null;
96
+ isFirstVisitor: boolean;
97
+ }
98
+ /**
99
+ * Scene stats response from the API
100
+ */
101
+ interface SceneStatsResponse {
102
+ success: boolean;
103
+ stats: SceneStats;
104
+ sceneName: string | null;
105
+ version: string;
106
+ }
87
107
 
88
108
  /**
89
109
  * Guide module - fetch channel lineup from thestatic.tv
@@ -160,6 +180,11 @@ declare class SessionModule {
160
180
  * Check if a session is currently active
161
181
  */
162
182
  isSessionActive(): boolean;
183
+ /**
184
+ * Get scene stats (visitors, sessions, etc.)
185
+ * Useful for displaying metrics in-world
186
+ */
187
+ getStats(): Promise<SceneStatsResponse['stats'] | null>;
163
188
  }
164
189
 
165
190
  /**
@@ -294,4 +319,4 @@ declare class StaticTVClient {
294
319
  destroy(): Promise<void>;
295
320
  }
296
321
 
297
- export { type Channel, GuideModule, type GuideResponse, HeartbeatModule, type HeartbeatResponse, type InteractionResponse, InteractionsModule, KEY_TYPE_CHANNEL, KEY_TYPE_SCENE, SessionModule, type SessionResponse, StaticTVClient, type StaticTVConfig, type Vod };
322
+ export { type Channel, GuideModule, type GuideResponse, HeartbeatModule, type HeartbeatResponse, type InteractionResponse, InteractionsModule, KEY_TYPE_CHANNEL, KEY_TYPE_SCENE, type SceneStats, type SceneStatsResponse, SessionModule, type SessionResponse, StaticTVClient, type StaticTVConfig, type Vod };
package/dist/index.js CHANGED
@@ -32,22 +32,13 @@ module.exports = __toCommonJS(index_exports);
32
32
 
33
33
  // src/utils/http.ts
34
34
  async function request(url, options = {}) {
35
- const { timeout = 1e4, ...fetchOptions } = options;
36
- const controller = new AbortController();
37
- const timeoutId = setTimeout(() => controller.abort(), timeout);
38
- try {
39
- const response = await fetch(url, {
40
- ...fetchOptions,
41
- signal: controller.signal
42
- });
43
- if (!response.ok) {
44
- const errorData = await response.json().catch(() => ({}));
45
- throw new Error(errorData.error || `HTTP ${response.status}`);
46
- }
47
- return response.json();
48
- } finally {
49
- clearTimeout(timeoutId);
35
+ const { timeout: _timeout, ...fetchOptions } = options;
36
+ const response = await fetch(url, fetchOptions);
37
+ if (!response.ok) {
38
+ const errorData = await response.json().catch(() => ({}));
39
+ throw new Error(errorData.error || `HTTP ${response.status}`);
50
40
  }
41
+ return response.json();
51
42
  }
52
43
 
53
44
  // src/modules/guide.ts
@@ -108,7 +99,7 @@ var GuideModule = class {
108
99
  // src/utils/identity.ts
109
100
  function getPlayerWallet() {
110
101
  try {
111
- const { getPlayer } = require("@dcl/sdk/src/players");
102
+ const { getPlayer } = require("@dcl/sdk/players");
112
103
  const player = getPlayer();
113
104
  return player?.userId ?? null;
114
105
  } catch {
@@ -117,7 +108,7 @@ function getPlayerWallet() {
117
108
  }
118
109
  function getPlayerDisplayName() {
119
110
  try {
120
- const { getPlayer } = require("@dcl/sdk/src/players");
111
+ const { getPlayer } = require("@dcl/sdk/players");
121
112
  const player = getPlayer();
122
113
  return player?.name ?? null;
123
114
  } catch {
@@ -237,6 +228,28 @@ var SessionModule = class {
237
228
  isSessionActive() {
238
229
  return this.isActive;
239
230
  }
231
+ /**
232
+ * Get scene stats (visitors, sessions, etc.)
233
+ * Useful for displaying metrics in-world
234
+ */
235
+ async getStats() {
236
+ try {
237
+ const wallet = getPlayerWallet();
238
+ const queryParam = wallet ? `?wallet=${wallet}` : "";
239
+ const response = await this.client.request(
240
+ `/scene-stats${queryParam}`,
241
+ { method: "GET" }
242
+ );
243
+ if (response.success && response.stats) {
244
+ this.client.log("Stats fetched:", response.stats);
245
+ return response.stats;
246
+ }
247
+ return null;
248
+ } catch (error) {
249
+ this.client.log(`Failed to fetch stats: ${error}`);
250
+ return null;
251
+ }
252
+ }
240
253
  };
241
254
 
242
255
  // src/modules/heartbeat.ts
package/dist/index.mjs CHANGED
@@ -7,22 +7,13 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
7
7
 
8
8
  // src/utils/http.ts
9
9
  async function request(url, options = {}) {
10
- const { timeout = 1e4, ...fetchOptions } = options;
11
- const controller = new AbortController();
12
- const timeoutId = setTimeout(() => controller.abort(), timeout);
13
- try {
14
- const response = await fetch(url, {
15
- ...fetchOptions,
16
- signal: controller.signal
17
- });
18
- if (!response.ok) {
19
- const errorData = await response.json().catch(() => ({}));
20
- throw new Error(errorData.error || `HTTP ${response.status}`);
21
- }
22
- return response.json();
23
- } finally {
24
- clearTimeout(timeoutId);
10
+ const { timeout: _timeout, ...fetchOptions } = options;
11
+ const response = await fetch(url, fetchOptions);
12
+ if (!response.ok) {
13
+ const errorData = await response.json().catch(() => ({}));
14
+ throw new Error(errorData.error || `HTTP ${response.status}`);
25
15
  }
16
+ return response.json();
26
17
  }
27
18
 
28
19
  // src/modules/guide.ts
@@ -83,7 +74,7 @@ var GuideModule = class {
83
74
  // src/utils/identity.ts
84
75
  function getPlayerWallet() {
85
76
  try {
86
- const { getPlayer } = __require("@dcl/sdk/src/players");
77
+ const { getPlayer } = __require("@dcl/sdk/players");
87
78
  const player = getPlayer();
88
79
  return player?.userId ?? null;
89
80
  } catch {
@@ -92,7 +83,7 @@ function getPlayerWallet() {
92
83
  }
93
84
  function getPlayerDisplayName() {
94
85
  try {
95
- const { getPlayer } = __require("@dcl/sdk/src/players");
86
+ const { getPlayer } = __require("@dcl/sdk/players");
96
87
  const player = getPlayer();
97
88
  return player?.name ?? null;
98
89
  } catch {
@@ -212,6 +203,28 @@ var SessionModule = class {
212
203
  isSessionActive() {
213
204
  return this.isActive;
214
205
  }
206
+ /**
207
+ * Get scene stats (visitors, sessions, etc.)
208
+ * Useful for displaying metrics in-world
209
+ */
210
+ async getStats() {
211
+ try {
212
+ const wallet = getPlayerWallet();
213
+ const queryParam = wallet ? `?wallet=${wallet}` : "";
214
+ const response = await this.client.request(
215
+ `/scene-stats${queryParam}`,
216
+ { method: "GET" }
217
+ );
218
+ if (response.success && response.stats) {
219
+ this.client.log("Stats fetched:", response.stats);
220
+ return response.stats;
221
+ }
222
+ return null;
223
+ } catch (error) {
224
+ this.client.log(`Failed to fetch stats: ${error}`);
225
+ return null;
226
+ }
227
+ }
215
228
  };
216
229
 
217
230
  // src/modules/heartbeat.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thestatic-tv/dcl-sdk",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "Connect your Decentraland scene to thestatic.tv - full channel lineup, metrics tracking, and interactions",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",