playkit-sdk 1.2.9 → 1.2.10

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.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * playkit-sdk v1.2.9
2
+ * playkit-sdk v1.2.10
3
3
  * PlayKit SDK for JavaScript
4
4
  * @license SEE LICENSE IN LICENSE
5
5
  */
@@ -2456,6 +2456,22 @@ class AuthManager extends EventEmitter {
2456
2456
  await this.exchangeJWT(this.config.playerJWT);
2457
2457
  return;
2458
2458
  }
2459
+ // Check for platform-injected token (same-domain scenario)
2460
+ // This allows seamless auth when SDK runs in a context where the platform
2461
+ // (e.g., Agentland-Space) has already stored a token in localStorage
2462
+ if (this.config.autoDetectPlatformToken !== false && typeof window !== 'undefined') {
2463
+ const platformToken = this.detectPlatformToken();
2464
+ if (platformToken) {
2465
+ this.logger.info('Platform token detected, using for authentication');
2466
+ this.authState = {
2467
+ isAuthenticated: true,
2468
+ token: platformToken,
2469
+ tokenType: 'player',
2470
+ };
2471
+ this.emit('authenticated', this.authState);
2472
+ return;
2473
+ }
2474
+ }
2459
2475
  // Not authenticated - trigger auto-login UI
2460
2476
  this.emit('unauthenticated');
2461
2477
  // In server mode, don't try to show UI - just throw error
@@ -2616,6 +2632,35 @@ class AuthManager extends EventEmitter {
2616
2632
  this.config.developerToken = undefined;
2617
2633
  }
2618
2634
  }
2635
+ /**
2636
+ * Detect platform-injected token (for same-domain scenarios).
2637
+ * Checks localStorage and window object for tokens stored by the platform.
2638
+ *
2639
+ * @returns Platform token if found, null otherwise
2640
+ */
2641
+ detectPlatformToken() {
2642
+ if (typeof window === 'undefined')
2643
+ return null;
2644
+ try {
2645
+ // Check localStorage with configured key
2646
+ const key = this.config.platformTokenKey || 'shared_token';
2647
+ const token = localStorage.getItem(key);
2648
+ if (token) {
2649
+ this.logger.debug(`Platform token found in localStorage[${key}]`);
2650
+ return token;
2651
+ }
2652
+ // Also check window object for injected token
2653
+ const windowToken = window.__PLAYKIT_PLATFORM_TOKEN__;
2654
+ if (windowToken) {
2655
+ this.logger.debug('Platform token found in window.__PLAYKIT_PLATFORM_TOKEN__');
2656
+ return windowToken;
2657
+ }
2658
+ }
2659
+ catch (error) {
2660
+ this.logger.warn('Error detecting platform token:', error);
2661
+ }
2662
+ return null;
2663
+ }
2619
2664
  /**
2620
2665
  * Check if token is expired
2621
2666
  */