playertwo-sdk 0.2.5 → 0.2.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.
Files changed (3) hide show
  1. package/index.d.ts +8 -2
  2. package/index.mjs +14 -8
  3. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -412,6 +412,10 @@ export interface Voice {
412
412
  volume(id: string, volume: number): void;
413
413
  /** Whether a player (or you) is speaking now. */
414
414
  speaking(id: string): boolean;
415
+ /** Whether a player reaches you through Player Two's party voice now (your party, both of you in its voice, their
416
+ microphone on there): their voice in this room is silent to you meanwhile, so you don't hear them twice. They stay
417
+ in `who`, and "speaking" still says when they talk (as the party's voice hears them). */
418
+ viaParty(id: string): boolean;
415
419
  }
416
420
 
417
421
  export interface SendOptions {
@@ -771,12 +775,14 @@ declare global {
771
775
 
772
776
  /** Where the SDK is loaded from when the page doesn't have it. */
773
777
  export const SDK_URL: string;
778
+ /** Where it is looked for, in turn: SDK_URL (playertwo.lol), then playertwo.plus. */
779
+ export const SDK_URLS: readonly string[];
774
780
 
775
- /** window.PlayerTwo, loading the script from `src` (SDK_URL) first if the page doesn't have it. */
781
+ /** window.PlayerTwo, loading the script from `src`, else from each of SDK_URLS in turn, if the page doesn't have it. */
776
782
  export function load(src?: string): Promise<PlayerTwoGlobal>;
777
783
 
778
784
  /** PlayerTwo.init(options), loading the SDK first if the page doesn't have it. */
779
785
  export function init(options?: InitOptions): Promise<P2>;
780
786
 
781
- declare const sdk: { init: typeof init; load: typeof load; SDK_URL: string };
787
+ declare const sdk: { init: typeof init; load: typeof load; SDK_URL: string; SDK_URLS: readonly string[] };
782
788
  export default sdk;
package/index.mjs CHANGED
@@ -7,6 +7,9 @@
7
7
  // const p2 = await init(); // the same as PlayerTwo.init(), with the same options
8
8
 
9
9
  export const SDK_URL = "https://playertwo.lol/sdk/v1.js";
10
+ /** Where the script is looked for, in turn: playertwo.lol, then playertwo.plus (which stood in for it while it was held
11
+ by its registry, 2026-11-09, and still serves the same SDK). */
12
+ export const SDK_URLS = [SDK_URL, "https://playertwo.plus/sdk/v1.js"];
10
13
 
11
14
  let loading = null;
12
15
 
@@ -17,26 +20,29 @@ function refused(code, message) {
17
20
  return e;
18
21
  }
19
22
 
20
- /** window.PlayerTwo, loading the script first if the page doesn't have it. */
21
- export function load(src = SDK_URL) {
23
+ /** window.PlayerTwo, loading the script first if the page doesn't have it (from `src`, or from each of SDK_URLS in turn
24
+ until one loads). */
25
+ export function load(src) {
22
26
  if (typeof window === "undefined" || typeof document === "undefined") return Promise.reject(refused("no-window", "Player Two's SDK runs in a browser."));
23
27
  if (window.PlayerTwo && window.PlayerTwo.v === 1) return Promise.resolve(window.PlayerTwo);
24
28
  if (loading) return loading;
25
- loading = new Promise((resolve, reject) => {
29
+ const from = src ? [src] : SDK_URLS.slice();
30
+ const one = (url) => new Promise((resolve, reject) => {
26
31
  const s = document.createElement("script");
27
- s.src = src;
32
+ s.src = url;
28
33
  s.async = true;
29
34
  s.onload = () => {
30
35
  if (window.PlayerTwo && window.PlayerTwo.v === 1) resolve(window.PlayerTwo);
31
- else { loading = null; reject(refused("offline", "Player Two's SDK loaded, but didn't start.")); }
36
+ else reject(refused("offline", "Player Two's SDK loaded, but didn't start."));
32
37
  };
33
38
  s.onerror = () => {
34
- loading = null;
35
39
  s.remove();
36
- reject(refused("offline", `Player Two's SDK couldn't be loaded from ${src}.`));
40
+ reject(refused("offline", `Player Two's SDK couldn't be loaded from ${url}.`));
37
41
  };
38
42
  (document.head || document.documentElement).appendChild(s);
39
43
  });
44
+ const next = (i) => one(from[i]).catch((e) => (i + 1 < from.length && e.message.includes("couldn't be loaded") ? next(i + 1) : Promise.reject(e)));
45
+ loading = next(0).catch((e) => { loading = null; throw e; });
40
46
  return loading;
41
47
  }
42
48
 
@@ -45,4 +51,4 @@ export function init(options) {
45
51
  return load().then((PlayerTwo) => PlayerTwo.init(options));
46
52
  }
47
53
 
48
- export default { init, load, SDK_URL };
54
+ export default { init, load, SDK_URL, SDK_URLS };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "playertwo-sdk",
3
- "version": "0.2.5",
3
+ "version": "0.2.6",
4
4
  "description": "SDK for HTML5 and browser games on Player Two (playertwo.lol): trophies, leaderboards, stats, cloud saves, in-game purchases, voice chat and multiplayer rooms with server-side room code.",
5
5
  "keywords": [
6
6
  "playertwo",