@thestatic-tv/dcl-sdk 1.0.4 → 1.0.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/index.d.mts CHANGED
@@ -351,4 +351,28 @@ declare class StaticTVClient {
351
351
  destroy(): Promise<void>;
352
352
  }
353
353
 
354
- 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 };
354
+ /**
355
+ * Identity utilities for getting player information
356
+ * Uses getUserData from ~system/UserIdentity for reliable data in both
357
+ * local preview and production environments.
358
+ */
359
+ /**
360
+ * Fetch and cache user data from DCL
361
+ * Call this early in scene initialization
362
+ */
363
+ declare function fetchUserData(): Promise<{
364
+ wallet: string | null;
365
+ name: string | null;
366
+ }>;
367
+ /**
368
+ * Get the current player's wallet address from DCL SDK
369
+ * Returns cached value if available, otherwise attempts sync fetch
370
+ */
371
+ declare function getPlayerWallet(): string | null;
372
+ /**
373
+ * Get the current player's display name from DCL SDK
374
+ * Returns cached value if available, otherwise attempts sync fetch
375
+ */
376
+ declare function getPlayerDisplayName(): string | null;
377
+
378
+ export { type Channel, GuideModule, type GuideResponse, HeartbeatModule, type HeartbeatResponse, type InteractionResponse, InteractionsModule, KEY_TYPE_CHANNEL, KEY_TYPE_SCENE, type PlayerData, type SceneStats, type SceneStatsResponse, SessionModule, type SessionResponse, StaticTVClient, type StaticTVConfig, type Vod, fetchUserData, getPlayerDisplayName, getPlayerWallet };
package/dist/index.d.ts CHANGED
@@ -351,4 +351,28 @@ declare class StaticTVClient {
351
351
  destroy(): Promise<void>;
352
352
  }
353
353
 
354
- 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 };
354
+ /**
355
+ * Identity utilities for getting player information
356
+ * Uses getUserData from ~system/UserIdentity for reliable data in both
357
+ * local preview and production environments.
358
+ */
359
+ /**
360
+ * Fetch and cache user data from DCL
361
+ * Call this early in scene initialization
362
+ */
363
+ declare function fetchUserData(): Promise<{
364
+ wallet: string | null;
365
+ name: string | null;
366
+ }>;
367
+ /**
368
+ * Get the current player's wallet address from DCL SDK
369
+ * Returns cached value if available, otherwise attempts sync fetch
370
+ */
371
+ declare function getPlayerWallet(): string | null;
372
+ /**
373
+ * Get the current player's display name from DCL SDK
374
+ * Returns cached value if available, otherwise attempts sync fetch
375
+ */
376
+ declare function getPlayerDisplayName(): string | null;
377
+
378
+ export { type Channel, GuideModule, type GuideResponse, HeartbeatModule, type HeartbeatResponse, type InteractionResponse, InteractionsModule, KEY_TYPE_CHANNEL, KEY_TYPE_SCENE, type PlayerData, type SceneStats, type SceneStatsResponse, SessionModule, type SessionResponse, StaticTVClient, type StaticTVConfig, type Vod, fetchUserData, getPlayerDisplayName, getPlayerWallet };
package/dist/index.js CHANGED
@@ -26,7 +26,10 @@ __export(index_exports, {
26
26
  KEY_TYPE_CHANNEL: () => KEY_TYPE_CHANNEL,
27
27
  KEY_TYPE_SCENE: () => KEY_TYPE_SCENE,
28
28
  SessionModule: () => SessionModule,
29
- StaticTVClient: () => StaticTVClient
29
+ StaticTVClient: () => StaticTVClient,
30
+ fetchUserData: () => fetchUserData,
31
+ getPlayerDisplayName: () => getPlayerDisplayName,
32
+ getPlayerWallet: () => getPlayerWallet
30
33
  });
31
34
  module.exports = __toCommonJS(index_exports);
32
35
 
@@ -97,7 +100,29 @@ var GuideModule = class {
97
100
  };
98
101
 
99
102
  // src/utils/identity.ts
103
+ var cachedWallet = null;
104
+ var cachedDisplayName = null;
105
+ var hasFetched = false;
106
+ async function fetchUserData() {
107
+ if (hasFetched) {
108
+ return { wallet: cachedWallet, name: cachedDisplayName };
109
+ }
110
+ try {
111
+ const UserIdentity = require("~system/UserIdentity");
112
+ const userData = await UserIdentity.getUserData({});
113
+ cachedWallet = userData?.data?.userId || null;
114
+ cachedDisplayName = userData?.data?.displayName || null;
115
+ hasFetched = true;
116
+ return { wallet: cachedWallet, name: cachedDisplayName };
117
+ } catch {
118
+ hasFetched = true;
119
+ return { wallet: null, name: null };
120
+ }
121
+ }
100
122
  function getPlayerWallet() {
123
+ if (hasFetched) {
124
+ return cachedWallet;
125
+ }
101
126
  try {
102
127
  const { getPlayer } = require("@dcl/sdk/players");
103
128
  const player = getPlayer();
@@ -107,6 +132,9 @@ function getPlayerWallet() {
107
132
  }
108
133
  }
109
134
  function getPlayerDisplayName() {
135
+ if (hasFetched) {
136
+ return cachedDisplayName;
137
+ }
110
138
  try {
111
139
  const { getPlayer } = require("@dcl/sdk/players");
112
140
  const player = getPlayer();
@@ -524,8 +552,15 @@ var StaticTVClient = class {
524
552
  this.interactions = null;
525
553
  }
526
554
  if (this.config.autoStartSession) {
527
- this.session.startSession().catch((err) => {
528
- this.log(`Auto-start session failed: ${err}`);
555
+ fetchUserData().then(() => {
556
+ this.session.startSession().catch((err) => {
557
+ this.log(`Auto-start session failed: ${err}`);
558
+ });
559
+ }).catch((err) => {
560
+ this.log(`Failed to fetch user data: ${err}`);
561
+ this.session.startSession().catch((err2) => {
562
+ this.log(`Auto-start session failed: ${err2}`);
563
+ });
529
564
  });
530
565
  }
531
566
  this.log(`StaticTVClient initialized (${this._keyType} mode)`);
@@ -592,5 +627,8 @@ var StaticTVClient = class {
592
627
  KEY_TYPE_CHANNEL,
593
628
  KEY_TYPE_SCENE,
594
629
  SessionModule,
595
- StaticTVClient
630
+ StaticTVClient,
631
+ fetchUserData,
632
+ getPlayerDisplayName,
633
+ getPlayerWallet
596
634
  });
package/dist/index.mjs CHANGED
@@ -72,7 +72,29 @@ var GuideModule = class {
72
72
  };
73
73
 
74
74
  // src/utils/identity.ts
75
+ var cachedWallet = null;
76
+ var cachedDisplayName = null;
77
+ var hasFetched = false;
78
+ async function fetchUserData() {
79
+ if (hasFetched) {
80
+ return { wallet: cachedWallet, name: cachedDisplayName };
81
+ }
82
+ try {
83
+ const UserIdentity = __require("~system/UserIdentity");
84
+ const userData = await UserIdentity.getUserData({});
85
+ cachedWallet = userData?.data?.userId || null;
86
+ cachedDisplayName = userData?.data?.displayName || null;
87
+ hasFetched = true;
88
+ return { wallet: cachedWallet, name: cachedDisplayName };
89
+ } catch {
90
+ hasFetched = true;
91
+ return { wallet: null, name: null };
92
+ }
93
+ }
75
94
  function getPlayerWallet() {
95
+ if (hasFetched) {
96
+ return cachedWallet;
97
+ }
76
98
  try {
77
99
  const { getPlayer } = __require("@dcl/sdk/players");
78
100
  const player = getPlayer();
@@ -82,6 +104,9 @@ function getPlayerWallet() {
82
104
  }
83
105
  }
84
106
  function getPlayerDisplayName() {
107
+ if (hasFetched) {
108
+ return cachedDisplayName;
109
+ }
85
110
  try {
86
111
  const { getPlayer } = __require("@dcl/sdk/players");
87
112
  const player = getPlayer();
@@ -499,8 +524,15 @@ var StaticTVClient = class {
499
524
  this.interactions = null;
500
525
  }
501
526
  if (this.config.autoStartSession) {
502
- this.session.startSession().catch((err) => {
503
- this.log(`Auto-start session failed: ${err}`);
527
+ fetchUserData().then(() => {
528
+ this.session.startSession().catch((err) => {
529
+ this.log(`Auto-start session failed: ${err}`);
530
+ });
531
+ }).catch((err) => {
532
+ this.log(`Failed to fetch user data: ${err}`);
533
+ this.session.startSession().catch((err2) => {
534
+ this.log(`Auto-start session failed: ${err2}`);
535
+ });
504
536
  });
505
537
  }
506
538
  this.log(`StaticTVClient initialized (${this._keyType} mode)`);
@@ -566,5 +598,8 @@ export {
566
598
  KEY_TYPE_CHANNEL,
567
599
  KEY_TYPE_SCENE,
568
600
  SessionModule,
569
- StaticTVClient
601
+ StaticTVClient,
602
+ fetchUserData,
603
+ getPlayerDisplayName,
604
+ getPlayerWallet
570
605
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thestatic-tv/dcl-sdk",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
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",