@thestatic-tv/dcl-sdk 1.0.2 → 1.0.3

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
@@ -148,7 +148,7 @@ declare class GuideModule {
148
148
  declare class SessionModule {
149
149
  private client;
150
150
  private sessionId;
151
- private heartbeatInterval;
151
+ private heartbeatTimerId;
152
152
  private isActive;
153
153
  constructor(client: StaticTVClient);
154
154
  /**
@@ -161,7 +161,7 @@ declare class SessionModule {
161
161
  */
162
162
  startSession(metadata?: Record<string, unknown>): Promise<string | null>;
163
163
  /**
164
- * Start the heartbeat interval
164
+ * Start the heartbeat interval using DCL-compatible timer
165
165
  */
166
166
  private startHeartbeat;
167
167
  /**
@@ -193,7 +193,7 @@ declare class SessionModule {
193
193
 
194
194
  declare class HeartbeatModule {
195
195
  private client;
196
- private watchInterval;
196
+ private watchTimerId;
197
197
  private currentChannel;
198
198
  private isWatching;
199
199
  constructor(client: StaticTVClient);
package/dist/index.d.ts CHANGED
@@ -148,7 +148,7 @@ declare class GuideModule {
148
148
  declare class SessionModule {
149
149
  private client;
150
150
  private sessionId;
151
- private heartbeatInterval;
151
+ private heartbeatTimerId;
152
152
  private isActive;
153
153
  constructor(client: StaticTVClient);
154
154
  /**
@@ -161,7 +161,7 @@ declare class SessionModule {
161
161
  */
162
162
  startSession(metadata?: Record<string, unknown>): Promise<string | null>;
163
163
  /**
164
- * Start the heartbeat interval
164
+ * Start the heartbeat interval using DCL-compatible timer
165
165
  */
166
166
  private startHeartbeat;
167
167
  /**
@@ -193,7 +193,7 @@ declare class SessionModule {
193
193
 
194
194
  declare class HeartbeatModule {
195
195
  private client;
196
- private watchInterval;
196
+ private watchTimerId;
197
197
  private currentChannel;
198
198
  private isWatching;
199
199
  constructor(client: StaticTVClient);
package/dist/index.js CHANGED
@@ -116,11 +116,54 @@ function getPlayerDisplayName() {
116
116
  }
117
117
  }
118
118
 
119
+ // src/utils/timer.ts
120
+ var import_ecs = require("@dcl/sdk/ecs");
121
+ var nextTimerId = 1;
122
+ var timers = /* @__PURE__ */ new Map();
123
+ var systemAdded = false;
124
+ function ensureTimerSystem() {
125
+ if (systemAdded) return;
126
+ import_ecs.engine.addSystem((dt) => {
127
+ for (const timer of timers.values()) {
128
+ if (!timer.active) continue;
129
+ timer.elapsedTime += dt;
130
+ if (timer.elapsedTime >= timer.intervalSeconds) {
131
+ timer.elapsedTime = 0;
132
+ try {
133
+ timer.callback();
134
+ } catch (e) {
135
+ console.error("[StaticTV Timer] Callback error:", e);
136
+ }
137
+ }
138
+ }
139
+ });
140
+ systemAdded = true;
141
+ }
142
+ function dclSetInterval(callback, intervalMs) {
143
+ ensureTimerSystem();
144
+ const id = nextTimerId++;
145
+ timers.set(id, {
146
+ id,
147
+ callback,
148
+ intervalSeconds: intervalMs / 1e3,
149
+ elapsedTime: 0,
150
+ active: true
151
+ });
152
+ return id;
153
+ }
154
+ function dclClearInterval(timerId) {
155
+ const timer = timers.get(timerId);
156
+ if (timer) {
157
+ timer.active = false;
158
+ timers.delete(timerId);
159
+ }
160
+ }
161
+
119
162
  // src/modules/session.ts
120
163
  var SessionModule = class {
121
164
  constructor(client) {
122
165
  this.sessionId = null;
123
- this.heartbeatInterval = null;
166
+ this.heartbeatTimerId = null;
124
167
  this.isActive = false;
125
168
  this.client = client;
126
169
  }
@@ -163,12 +206,12 @@ var SessionModule = class {
163
206
  }
164
207
  }
165
208
  /**
166
- * Start the heartbeat interval
209
+ * Start the heartbeat interval using DCL-compatible timer
167
210
  */
168
211
  startHeartbeat() {
169
- if (this.heartbeatInterval) return;
212
+ if (this.heartbeatTimerId !== null) return;
170
213
  const interval = this.client.getConfig().sessionHeartbeatInterval || 3e4;
171
- this.heartbeatInterval = setInterval(() => {
214
+ this.heartbeatTimerId = dclSetInterval(() => {
172
215
  this.sendHeartbeat();
173
216
  }, interval);
174
217
  }
@@ -195,9 +238,9 @@ var SessionModule = class {
195
238
  */
196
239
  async endSession() {
197
240
  if (!this.isActive) return;
198
- if (this.heartbeatInterval) {
199
- clearInterval(this.heartbeatInterval);
200
- this.heartbeatInterval = null;
241
+ if (this.heartbeatTimerId !== null) {
242
+ dclClearInterval(this.heartbeatTimerId);
243
+ this.heartbeatTimerId = null;
201
244
  }
202
245
  if (this.sessionId) {
203
246
  try {
@@ -255,7 +298,7 @@ var SessionModule = class {
255
298
  // src/modules/heartbeat.ts
256
299
  var HeartbeatModule = class {
257
300
  constructor(client) {
258
- this.watchInterval = null;
301
+ this.watchTimerId = null;
259
302
  this.currentChannel = null;
260
303
  this.isWatching = false;
261
304
  this.client = client;
@@ -278,7 +321,7 @@ var HeartbeatModule = class {
278
321
  this.isWatching = true;
279
322
  this.sendHeartbeat();
280
323
  const interval = this.client.getConfig().watchHeartbeatInterval || 6e4;
281
- this.watchInterval = setInterval(() => {
324
+ this.watchTimerId = dclSetInterval(() => {
282
325
  this.sendHeartbeat();
283
326
  }, interval);
284
327
  this.client.log(`Started watching ${channelSlug}`);
@@ -288,9 +331,9 @@ var HeartbeatModule = class {
288
331
  */
289
332
  stopWatching() {
290
333
  if (!this.isWatching) return;
291
- if (this.watchInterval) {
292
- clearInterval(this.watchInterval);
293
- this.watchInterval = null;
334
+ if (this.watchTimerId !== null) {
335
+ dclClearInterval(this.watchTimerId);
336
+ this.watchTimerId = null;
294
337
  }
295
338
  this.client.log(`Stopped watching ${this.currentChannel}`);
296
339
  this.currentChannel = null;
package/dist/index.mjs CHANGED
@@ -91,11 +91,54 @@ function getPlayerDisplayName() {
91
91
  }
92
92
  }
93
93
 
94
+ // src/utils/timer.ts
95
+ import { engine } from "@dcl/sdk/ecs";
96
+ var nextTimerId = 1;
97
+ var timers = /* @__PURE__ */ new Map();
98
+ var systemAdded = false;
99
+ function ensureTimerSystem() {
100
+ if (systemAdded) return;
101
+ engine.addSystem((dt) => {
102
+ for (const timer of timers.values()) {
103
+ if (!timer.active) continue;
104
+ timer.elapsedTime += dt;
105
+ if (timer.elapsedTime >= timer.intervalSeconds) {
106
+ timer.elapsedTime = 0;
107
+ try {
108
+ timer.callback();
109
+ } catch (e) {
110
+ console.error("[StaticTV Timer] Callback error:", e);
111
+ }
112
+ }
113
+ }
114
+ });
115
+ systemAdded = true;
116
+ }
117
+ function dclSetInterval(callback, intervalMs) {
118
+ ensureTimerSystem();
119
+ const id = nextTimerId++;
120
+ timers.set(id, {
121
+ id,
122
+ callback,
123
+ intervalSeconds: intervalMs / 1e3,
124
+ elapsedTime: 0,
125
+ active: true
126
+ });
127
+ return id;
128
+ }
129
+ function dclClearInterval(timerId) {
130
+ const timer = timers.get(timerId);
131
+ if (timer) {
132
+ timer.active = false;
133
+ timers.delete(timerId);
134
+ }
135
+ }
136
+
94
137
  // src/modules/session.ts
95
138
  var SessionModule = class {
96
139
  constructor(client) {
97
140
  this.sessionId = null;
98
- this.heartbeatInterval = null;
141
+ this.heartbeatTimerId = null;
99
142
  this.isActive = false;
100
143
  this.client = client;
101
144
  }
@@ -138,12 +181,12 @@ var SessionModule = class {
138
181
  }
139
182
  }
140
183
  /**
141
- * Start the heartbeat interval
184
+ * Start the heartbeat interval using DCL-compatible timer
142
185
  */
143
186
  startHeartbeat() {
144
- if (this.heartbeatInterval) return;
187
+ if (this.heartbeatTimerId !== null) return;
145
188
  const interval = this.client.getConfig().sessionHeartbeatInterval || 3e4;
146
- this.heartbeatInterval = setInterval(() => {
189
+ this.heartbeatTimerId = dclSetInterval(() => {
147
190
  this.sendHeartbeat();
148
191
  }, interval);
149
192
  }
@@ -170,9 +213,9 @@ var SessionModule = class {
170
213
  */
171
214
  async endSession() {
172
215
  if (!this.isActive) return;
173
- if (this.heartbeatInterval) {
174
- clearInterval(this.heartbeatInterval);
175
- this.heartbeatInterval = null;
216
+ if (this.heartbeatTimerId !== null) {
217
+ dclClearInterval(this.heartbeatTimerId);
218
+ this.heartbeatTimerId = null;
176
219
  }
177
220
  if (this.sessionId) {
178
221
  try {
@@ -230,7 +273,7 @@ var SessionModule = class {
230
273
  // src/modules/heartbeat.ts
231
274
  var HeartbeatModule = class {
232
275
  constructor(client) {
233
- this.watchInterval = null;
276
+ this.watchTimerId = null;
234
277
  this.currentChannel = null;
235
278
  this.isWatching = false;
236
279
  this.client = client;
@@ -253,7 +296,7 @@ var HeartbeatModule = class {
253
296
  this.isWatching = true;
254
297
  this.sendHeartbeat();
255
298
  const interval = this.client.getConfig().watchHeartbeatInterval || 6e4;
256
- this.watchInterval = setInterval(() => {
299
+ this.watchTimerId = dclSetInterval(() => {
257
300
  this.sendHeartbeat();
258
301
  }, interval);
259
302
  this.client.log(`Started watching ${channelSlug}`);
@@ -263,9 +306,9 @@ var HeartbeatModule = class {
263
306
  */
264
307
  stopWatching() {
265
308
  if (!this.isWatching) return;
266
- if (this.watchInterval) {
267
- clearInterval(this.watchInterval);
268
- this.watchInterval = null;
309
+ if (this.watchTimerId !== null) {
310
+ dclClearInterval(this.watchTimerId);
311
+ this.watchTimerId = null;
269
312
  }
270
313
  this.client.log(`Stopped watching ${this.currentChannel}`);
271
314
  this.currentChannel = null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thestatic-tv/dcl-sdk",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
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",