playertwo-sdk 0.2.6 → 0.2.8

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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2026 Player Two
3
+ Copyright (c) 2026 PlayerTwo
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,13 +1,13 @@
1
1
  # playertwo-sdk
2
2
 
3
- The game SDK for [Player Two](https://playertwo.lol), with TypeScript types. Trophies, XP and levels, stats,
3
+ The game SDK for [PlayerTwo](https://playertwo.lol), with TypeScript types. Trophies, XP and levels, stats,
4
4
  leaderboards, cloud saves, presence, invites, add-ons, in-game purchases, the player's avatar, travel between games,
5
5
  and multiplayer rooms with no server of your own (voice chat, worlds, replays and your own server code in `room.js`
6
6
  included).
7
7
 
8
- Player Two is a game store and a launchpad. Games are sold (or free) to play in the browser or download, and raises
8
+ PlayerTwo is a game store and a launchpad. Games are sold (or free) to play in the browser or download, and raises
9
9
  let players back a game while it is being made, paid to its developer stage by stage as they post proof. A web game
10
- hosted on Player Two gets its own address on `playertwo.cc` and every service below through one account per player.
10
+ hosted on PlayerTwo gets its own address on `playertwo.cc` and every service below through one account per player.
11
11
 
12
12
  - Docs: https://playertwo.lol/docs/sdk
13
13
  - Everything a game gets, with a link to its part of the docs: https://playertwo.lol/llms.txt
@@ -25,12 +25,12 @@ Or no install at all: the SDK itself is one script.
25
25
  <script src="https://playertwo.lol/sdk/v1.js"></script>
26
26
  <script>
27
27
  PlayerTwo.init().then((p2) => p2.trophies.unlock("first-win")).catch(() => {
28
- /* not on Player Two (e.code "not-on-player-two"): the game plays on without services */
28
+ /* not on PlayerTwo (e.code "not-on-player-two"): the game plays on without services */
29
29
  });
30
30
  </script>
31
31
  ```
32
32
 
33
- On Player Two the script is already in your game's page. `init()` from the npm package uses that copy, and loads
33
+ On PlayerTwo the script is already in your game's page. `init()` from the npm package uses that copy, and loads
34
34
  `https://playertwo.lol/sdk/v1.js` only when the page doesn't have it (on localhost, say).
35
35
 
36
36
  ## Quick start
@@ -39,7 +39,7 @@ On Player Two the script is already in your game's page. `init()` from the npm p
39
39
  import { init } from "playertwo-sdk";
40
40
 
41
41
  const p2 = await init({
42
- // localhost only: the stand-in's trophies (it refuses keys you don't list, as Player Two would)
42
+ // localhost only: the stand-in's trophies (it refuses keys you don't list, as PlayerTwo would)
43
43
  local: { trophies: [{ key: "first-win", name: "First win", tier: 1 }] },
44
44
  });
45
45
  console.log(p2.env, p2.player?.name, p2.player?.level); // env: "p2" | "local" | "disabled"
@@ -61,8 +61,8 @@ sync.on("leave", (id) => removeMesh(id));
61
61
  ```
62
62
 
63
63
  Every call returns a promise. A refusal rejects with an `Error` that has a `code` and a `status` (the codes:
64
- https://playertwo.lol/docs/sdk#call-errors). Off Player Two and off localhost, `init()` rejects after 1.5 seconds
65
- with code `not-on-player-two`; with `{ required: true }` the page says "Play this on Player Two" and stops.
64
+ https://playertwo.lol/docs/sdk#call-errors). Off PlayerTwo and off localhost, `init()` rejects after 1.5 seconds
65
+ with code `not-on-player-two`; with `{ required: true }` the page says "Play this on PlayerTwo" and stops.
66
66
 
67
67
  ## What it gives your game
68
68
 
@@ -105,16 +105,16 @@ Multiplayer, through `p2.rooms`:
105
105
  | Voice chat (24 a room) | `room.voice.join()`, `.leave()`, `.mute()`, `.volume(id, v)`, `.speaking(id)` | [rooms-voice](https://playertwo.lol/docs/sdk#rooms-voice) |
106
106
  | A bad connection, on purpose | `p2.rooms.simulate({ lag, jitter, loss })` or `?p2-net=150,30,0.02` | [rooms-simulate](https://playertwo.lol/docs/sdk#rooms-simulate) |
107
107
 
108
- Rooms are 1 to 64 players (256 in an area of a world) and are for games hosted on Player Two (a build you push, or
109
- your own site served through Player Two). A release never mixes versions in a room. All limits:
108
+ Rooms are 1 to 64 players (256 in an area of a world) and are for games hosted on PlayerTwo (a build you push, or
109
+ your own site served through PlayerTwo). A release never mixes versions in a room. All limits:
110
110
  https://playertwo.lol/docs/sdk#rooms-limits.
111
111
 
112
112
  ## A room's server: `playertwo-sdk/room`
113
113
 
114
114
  Put a `room.js` (one ES module, up to 1 MB) at the root of the build you push, and every room of that build runs it on
115
- Player Two's servers: a sandbox with no network, 100 ms of CPU a call, 1 to 60 ticks a second. In a scripted room your
115
+ PlayerTwo's servers: a sandbox with no network, 100 ms of CPU a call, 1 to 60 ticks a second. In a scripted room your
116
116
  pages' messages go to your code, and only your code writes the shared state, so a player can't fake a hit or a score.
117
- Player Two takes the file out of your build and never serves it to players.
117
+ PlayerTwo takes the file out of your build and never serves it to players.
118
118
 
119
119
  Plain JavaScript with JSDoc types (it is pushed as it is):
120
120
 
@@ -146,14 +146,14 @@ export const { tickRate, onCreate, onJoin, onLeave, onMessage, onSync, onTick }
146
146
  Hooks: `onCreate`, `onStart`, `onJoin`, `onLeave`, `onMessage`, `onSync`, `onTick`. Everything `room` has:
147
147
  [`room.d.ts`](./room.d.ts).
148
148
 
149
- ## Building without Player Two
149
+ ## Building without PlayerTwo
150
150
 
151
151
  On localhost, a stand-in answers every call from memory, and two tabs are two players. If your dev server serves
152
152
  `/room.js`, the first tab runs it as the room's server. Give the stand-in your trophies, add-ons, products and params
153
153
  with `init({ local: { ... } })`; `local: true` (or `{ force: true }`) uses it wherever the game runs. Voice needs a
154
- room on Player Two. Docs: https://playertwo.lol/docs/sdk#start-local.
154
+ room on PlayerTwo. Docs: https://playertwo.lol/docs/sdk#start-local.
155
155
 
156
- On Player Two you, your team and your playtesters play in test mode (`p2.test` is true): every call works, nothing is
156
+ On PlayerTwo you, your team and your playtesters play in test mode (`p2.test` is true): every call works, nothing is
157
157
  paid, and what you earn is kept apart. Docs: https://playertwo.lol/docs/sdk#test.
158
158
 
159
159
  Using the script tag and only want the types of the global `PlayerTwo`? Add `"types": ["playertwo-sdk"]` to your
@@ -162,10 +162,10 @@ Using the script tag and only want the types of the global `PlayerTwo`? Add `"ty
162
162
  ## In-game purchases
163
163
 
164
164
  Two ways, and a game can use both: products you make in your studio (`p2.store.buy(key)`), or charges your own server
165
- makes at its own prices with your game key (`p2.store.pay(chargeId)`). Player Two's own card takes the player's yes
166
- and the payment from their Player Two balance (USDC on Base). You get 80% of every in-game purchase, Player Two keeps
165
+ makes at its own prices with your game key (`p2.store.pay(chargeId)`). PlayerTwo's own card takes the player's yes
166
+ and the payment from their PlayerTwo balance (USDC on Base). You get 80% of every in-game purchase, PlayerTwo keeps
167
167
  20% (less your backers' share if your game raised with a share of its sales). Add-ons sold on the game's page are split
168
- as its sales are: Player Two keeps 10%. Every purchase gives your game a signed receipt (a JWT typed `p2-buy`, RS256,
168
+ as its sales are: PlayerTwo keeps 10%. Every purchase gives your game a signed receipt (a JWT typed `p2-buy`, RS256,
169
169
  keys at https://playertwo.lol/.well-known/p2-keys.json) and your studio's webhooks a `purchase` event. Docs:
170
170
  https://playertwo.lol/docs/sdk#purchases.
171
171
 
@@ -176,7 +176,7 @@ A game key (`p2g_...`, made in your studio) lets your server check a session or
176
176
  consumables and report matches, under `https://playertwo.lol/api/v1/sdk/server/...`. Docs:
177
177
  https://playertwo.lol/docs/sdk#server and https://playertwo.lol/docs/sdk/connect (a game played on its own site).
178
178
 
179
- ## Putting it on Player Two
179
+ ## Putting it on PlayerTwo
180
180
 
181
181
  A whole game to start from: `npm create playertwo-game@latest my-game` (a small multiplayer Three.js game with rooms
182
182
  and `room.js`, see [create-playertwo-game](https://www.npmjs.com/package/create-playertwo-game)).
@@ -190,12 +190,12 @@ curl -fsSLO https://playertwo.lol/cli/p2.mjs
190
190
  P2_AGENT_KEY=p2_agent_... node p2.mjs push dist --game your-game --version 1.0.0
191
191
  ```
192
192
 
193
- It plays at `https://your-game.playertwo.cc/` in Player Two's player, with no code changes. A pushed folder may be up to
194
- 5 GB and 20,000 files; only the files Player Two doesn't have yet are sent. Docs: https://playertwo.lol/docs/hosting.
193
+ It plays at `https://your-game.playertwo.cc/` in PlayerTwo's player, with no code changes. A pushed folder may be up to
194
+ 5 GB and 20,000 files; only the files PlayerTwo doesn't have yet are sent. Docs: https://playertwo.lol/docs/hosting.
195
195
 
196
196
  ## For AI agents: MCP and the agent API
197
197
 
198
- Player Two runs an MCP server (Streamable HTTP) at `https://playertwo.lol/api/mcp`:
198
+ PlayerTwo runs an MCP server (Streamable HTTP) at `https://playertwo.lol/api/mcp`:
199
199
 
200
200
  ```
201
201
  claude mcp add --transport http player-two https://playertwo.lol/api/mcp
@@ -207,7 +207,7 @@ The first line is enough for the public tools, which need no key: `get_submissio
207
207
  (submit it, edit its page, upload media and web builds, define trophies, leaderboards and products, roll back builds,
208
208
  post updates, read its rooms) need the player's agent key, made in their studio on playertwo.lol under Agents, or no
209
209
  key at all in a client that signs in (Claude's and ChatGPT's connectors, Claude Code, Cursor): the first time it calls
210
- one, the player is asked to sign in to Player Two and allow it (OAuth 2.1 with PKCE). Its MCP Registry name is
210
+ one, the player is asked to sign in to PlayerTwo and allow it (OAuth 2.1 with PKCE). Its MCP Registry name is
211
211
  `lol.playertwo/mcp`; its server card is at https://playertwo.lol/.well-known/mcp.json.
212
212
 
213
213
  - The agent API: `GET https://playertwo.lol/api/v1/agent/guide` explains every field; submit with
@@ -218,4 +218,4 @@ one, the player is asked to sign in to Player Two and allow it (OAuth 2.1 with P
218
218
 
219
219
  ## License
220
220
 
221
- MIT. Copyright (c) 2026 Player Two.
221
+ MIT. Copyright (c) 2026 PlayerTwo.
package/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Types for Player Two's game SDK, https://playertwo.lol/sdk/v1.js (its source: public/sdk/v1.js in Player Two's code;
2
+ * Types for PlayerTwo's game SDK, https://playertwo.lol/sdk/v1.js (its source: public/sdk/v1.js in PlayerTwo's code;
3
3
  * keep these in step with its part 4, "the helpers the game uses", and part 4b, "rooms"). Docs: https://playertwo.lol/docs/sdk
4
4
  *
5
5
  * import { init } from "playertwo-sdk"; // or the global PlayerTwo, from the script tag
@@ -12,7 +12,7 @@
12
12
  /** Anything that goes through JSON: what messages, the room's state and saves carry. */
13
13
  export type Json = string | number | boolean | null | Json[] | { [key: string]: Json };
14
14
 
15
- /** Where the game is: on Player Two or in its app, on localhost (the stand-in), or anywhere else. */
15
+ /** Where the game is: on PlayerTwo or in its app, on localhost (the stand-in), or anywhere else. */
16
16
  export type Env = "p2" | "local" | "disabled";
17
17
 
18
18
  /** Every refusal rejects with one of these. */
@@ -52,9 +52,9 @@ export interface LocalOptions {
52
52
  }
53
53
 
54
54
  export interface InitOptions {
55
- /** Outside Player Two, fill the page with "Play this on Player Two" and stop. */
55
+ /** Outside PlayerTwo, fill the page with "Play this on PlayerTwo" and stop. */
56
56
  required?: boolean;
57
- /** The Player Two app's local address (the app sets P2_BRIDGE itself). */
57
+ /** The PlayerTwo app's local address (the app sets P2_BRIDGE itself). */
58
58
  bridge?: string;
59
59
  /** The stand-in's trophies, add-ons and params; true (or { force: true }) uses the stand-in wherever the game runs. */
60
60
  local?: true | LocalOptions;
@@ -68,7 +68,7 @@ export interface Me {
68
68
  session: string;
69
69
  test: boolean;
70
70
  demo: boolean;
71
- /** "web": Player Two's player; "desktop": the app. */
71
+ /** "web": PlayerTwo's player; "desktop": the app. */
72
72
  from: "web" | "desktop";
73
73
  params: Record<string, string> | null;
74
74
  }
@@ -224,7 +224,7 @@ export type Bought =
224
224
  product: { key: string; kind: string; n: number };
225
225
  /** A consumable's: how many the player has now. */
226
226
  count?: number;
227
- /** A JWT typed "p2-buy", RS256 with Player Two's keys (/.well-known/p2-keys.json), for your own server: an hour. */
227
+ /** A JWT typed "p2-buy", RS256 with PlayerTwo's keys (/.well-known/p2-keys.json), for your own server: an hour. */
228
228
  receipt: string;
229
229
  exp: number;
230
230
  /** A test purchase (the game's team, a tester): nothing was paid. */
@@ -240,7 +240,7 @@ export type Paid =
240
240
  charge: { id: string; name: string; ref: string | null };
241
241
  /** What was paid, in US dollars (0 for a test). */
242
242
  amount: number;
243
- /** A JWT typed "p2-buy" (kind "charge", key the charge's id), RS256 with Player Two's keys, for your own server: an hour. */
243
+ /** A JWT typed "p2-buy" (kind "charge", key the charge's id), RS256 with PlayerTwo's keys, for your own server: an hour. */
244
244
  receipt: string;
245
245
  exp: number;
246
246
  /** A test payment (the game's team, a tester): nothing was paid. */
@@ -253,13 +253,13 @@ export interface Store {
253
253
  list(): Promise<Product[]>;
254
254
  /** What the player has. */
255
255
  owned(): Promise<Holding[]>;
256
- /** Asks Player Two to sell one: its own step, outside the game's frame, where the player says yes. Rejects with code
257
- "no-store" where it can't (outside Player Two's player on the web), "busy" (its sheet is open already),
256
+ /** Asks PlayerTwo to sell one: its own step, outside the game's frame, where the player says yes. Rejects with code
257
+ "no-store" where it can't (outside PlayerTwo's player on the web), "busy" (its sheet is open already),
258
258
  "unknown-product", "owned" (a skin, item or mod they have), "no-game" (they don't have the game yet), "guest" or
259
259
  "offline". */
260
260
  buy(key: string): Promise<Bought>;
261
261
  /** Asks the player to pay a charge your server made (POST /api/v1/sdk/server/store/charges, your game's key): its
262
- name and price on Player Two's card, paid once; one paid already answers its receipt again. Rejects with code
262
+ name and price on PlayerTwo's card, paid once; one paid already answers its receipt again. Rejects with code
263
263
  "unknown-charge", "expired" (30 minutes unpaid), "withdrawn" (your server cancelled it), "no-game", "busy",
264
264
  "no-store", "guest" or "offline". */
265
265
  pay(charge: string): Promise<Paid>;
@@ -392,7 +392,7 @@ export interface NetSimulation {
392
392
  loss?: number;
393
393
  }
394
394
 
395
- /** Voice chat in a room: each player's microphone to everyone else in voice, through Player Two's servers. */
395
+ /** Voice chat in a room: each player's microphone to everyone else in voice, through PlayerTwo's servers. */
396
396
  export interface Voice {
397
397
  /** Who is in voice: their ids. */
398
398
  readonly who: readonly string[];
@@ -412,7 +412,7 @@ 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
415
+ /** Whether a player reaches you through PlayerTwo's party voice now (your party, both of you in its voice, their
416
416
  microphone on there): their voice in this room is silent to you meanwhile, so you don't hear them twice. They stay
417
417
  in `who`, and "speaking" still says when they talk (as the party's voice hears them). */
418
418
  viaParty(id: string): boolean;
@@ -568,7 +568,7 @@ export interface Room {
568
568
  readonly state: Record<string, any>;
569
569
  /** Whose each key is (the first writer's; a leaver's become the host's). */
570
570
  readonly owners: Record<string, string | null>;
571
- /** The build has a room.js, running on Player Two's servers: only it writes the shared state. */
571
+ /** The build has a room.js, running on PlayerTwo's servers: only it writes the shared state. */
572
572
  readonly scripted: boolean;
573
573
  /** Whether it is a world, kept for good (p2.rooms.world). */
574
574
  readonly world: boolean;
@@ -642,11 +642,11 @@ export interface Avatar {
642
642
  level: number;
643
643
  picture: string | null;
644
644
  critter: {
645
- /** The name it is drawn from: the same name, the same critter, everywhere on Player Two. */
645
+ /** The name it is drawn from: the same name, the same critter, everywhere on PlayerTwo. */
646
646
  face: string;
647
647
  /** Its box: 18 pixels a side. */
648
648
  size: number;
649
- /** The colour of the tile it stands on in Player Two's own pages. */
649
+ /** The colour of the tile it stands on in PlayerTwo's own pages. */
650
650
  tile: string;
651
651
  /** Every pixel of it, eyes open. */
652
652
  pixels: Pixel[];
@@ -658,7 +658,7 @@ export interface Avatar {
658
658
  worn: { key: string; name: string; slot: string; model: string | null; picture: string | null }[];
659
659
  }
660
660
 
661
- /** One of the player's things from Player Two's shop in the Plaza (p2.items.list). */
661
+ /** One of the player's things from PlayerTwo's shop in the Plaza (p2.items.list). */
662
662
  export interface Item {
663
663
  key: string;
664
664
  name: string;
@@ -693,13 +693,13 @@ export interface Door {
693
693
  owned: boolean;
694
694
  }
695
695
 
696
- /** Travel to other games on Player Two, with the player's party. In Player Two's player on the web; elsewhere each
696
+ /** Travel to other games on PlayerTwo, with the player's party. In PlayerTwo's player on the web; elsewhere each
697
697
  rejects with code "no-travel". */
698
698
  export interface Travel {
699
699
  /** To another game, by its address (playertwo.lol/game/<slug>): it is given p2.params (yours, then `from`, this
700
700
  game's address, and `place`). Resolves as the player goes; this page is closed after. */
701
701
  to(slug: string, options?: { params?: Record<string, string>; place?: string }): Promise<{ to: { slug: string; title: string }; params: Record<string, string> }>;
702
- /** Back to the Plaza, where every game on Player Two has its screen. */
702
+ /** Back to the Plaza, where every game on PlayerTwo has its screen. */
703
703
  home(): Promise<{ to: { slug: null; title: string; url: string } }>;
704
704
  /** The doors to show in your own menu: where the party is, the games friends are in, the player's recent ones, the
705
705
  busiest (up to 12). */
@@ -722,9 +722,9 @@ export interface P2 {
722
722
  /** Any call by its name (the helpers are these). */
723
723
  call<T = unknown>(method: string, args?: unknown[]): Promise<T>;
724
724
  me(): Promise<Me>;
725
- /** Who is playing, for your own servers: a JWT signed by Player Two (RS256, typed "p2-id"), ten minutes. */
725
+ /** Who is playing, for your own servers: a JWT signed by PlayerTwo (RS256, typed "p2-id"), ten minutes. */
726
726
  identity(): Promise<string>;
727
- /** A link to your game on Player Two that opens it with these params (up to 16 strings, 512 bytes). */
727
+ /** A link to your game on PlayerTwo that opens it with these params (up to 16 strings, 512 bytes). */
728
728
  invite(params?: Record<string, string>): Promise<string>;
729
729
  trophies: Trophies;
730
730
  addons: Addons;
@@ -743,15 +743,15 @@ export interface P2 {
743
743
  /** Who the player is, to dress your game's character with: their critter as pixels and as a 3D model, and what they
744
744
  wear. */
745
745
  avatar(): Promise<Avatar>;
746
- /** What the player has from Player Two's shop in the Plaza (avatars, skins, wearables, emotes, effects), and what
746
+ /** What the player has from PlayerTwo's shop in the Plaza (avatars, skins, wearables, emotes, effects), and what
747
747
  they have on: a game can dress its own character in them. */
748
748
  items: { list(): Promise<Item[]> };
749
- /** Travel to other games on Player Two, with the player's party. */
749
+ /** Travel to other games on PlayerTwo, with the player's party. */
750
750
  travel: Travel;
751
- /** Whether a small live picture of the game goes to the Plaza's screens while it is played here (Player Two does
751
+ /** Whether a small live picture of the game goes to the Plaza's screens while it is played here (PlayerTwo does
752
752
  it; the player can stop it). */
753
753
  onAir: boolean;
754
- /** Player Two's own layer over the game opened (true) or closed (false). */
754
+ /** PlayerTwo's own layer over the game opened (true) or closed (false). */
755
755
  on(type: "overlay", fn: (open: boolean) => void): () => void;
756
756
  /** The player is about to close the game: what you keep should go now (a promise is waited for). */
757
757
  on(type: "flush", fn: (closing: true) => void | Promise<unknown>): () => void;
@@ -762,14 +762,14 @@ export interface PlayerTwoGlobal {
762
762
  readonly v: 1;
763
763
  /** Certain once init has settled. */
764
764
  env: Env;
765
- /** Finds Player Two once: every call answers the same promise, and the first call's options are the ones used. */
765
+ /** Finds PlayerTwo once: every call answers the same promise, and the first call's options are the ones used. */
766
766
  init(options?: InitOptions): Promise<P2>;
767
- /** Settles once init has been called and Player Two found, or not. */
767
+ /** Settles once init has been called and PlayerTwo found, or not. */
768
768
  readonly ready: Promise<P2>;
769
769
  }
770
770
 
771
771
  declare global {
772
- /** Player Two's SDK, from https://playertwo.lol/sdk/v1.js (on Player Two, already in the page). */
772
+ /** PlayerTwo's SDK, from https://playertwo.lol/sdk/v1.js (on PlayerTwo, already in the page). */
773
773
  var PlayerTwo: PlayerTwoGlobal;
774
774
  }
775
775
 
package/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
- // playertwo-sdk: Player Two's game SDK for code that is bundled (Vite, webpack, esbuild). The SDK itself is one
2
- // script, https://playertwo.lol/sdk/v1.js, which Player Two's games host puts in a hosted game's page; this uses that
1
+ // playertwo-sdk: PlayerTwo's game SDK for code that is bundled (Vite, webpack, esbuild). The SDK itself is one
2
+ // script, https://playertwo.lol/sdk/v1.js, which PlayerTwo's games host puts in a hosted game's page; this uses that
3
3
  // copy when the page has it, and otherwise loads the script and waits for it. Types: index.d.ts. Docs:
4
4
  // https://playertwo.lol/docs/sdk
5
5
  //
@@ -23,7 +23,7 @@ function refused(code, message) {
23
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
24
  until one loads). */
25
25
  export function load(src) {
26
- if (typeof window === "undefined" || typeof document === "undefined") return Promise.reject(refused("no-window", "Player Two's SDK runs in a browser."));
26
+ if (typeof window === "undefined" || typeof document === "undefined") return Promise.reject(refused("no-window", "PlayerTwo's SDK runs in a browser."));
27
27
  if (window.PlayerTwo && window.PlayerTwo.v === 1) return Promise.resolve(window.PlayerTwo);
28
28
  if (loading) return loading;
29
29
  const from = src ? [src] : SDK_URLS.slice();
@@ -33,11 +33,11 @@ export function load(src) {
33
33
  s.async = true;
34
34
  s.onload = () => {
35
35
  if (window.PlayerTwo && window.PlayerTwo.v === 1) resolve(window.PlayerTwo);
36
- else reject(refused("offline", "Player Two's SDK loaded, but didn't start."));
36
+ else reject(refused("offline", "PlayerTwo's SDK loaded, but didn't start."));
37
37
  };
38
38
  s.onerror = () => {
39
39
  s.remove();
40
- reject(refused("offline", `Player Two's SDK couldn't be loaded from ${url}.`));
40
+ reject(refused("offline", `PlayerTwo's SDK couldn't be loaded from ${url}.`));
41
41
  };
42
42
  (document.head || document.documentElement).appendChild(s);
43
43
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "playertwo-sdk",
3
- "version": "0.2.6",
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.",
3
+ "version": "0.2.8",
4
+ "description": "SDK for HTML5 and browser games on PlayerTwo (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",
7
7
  "player-two",
@@ -34,7 +34,7 @@
34
34
  "directory": "packages/sdk"
35
35
  },
36
36
  "license": "MIT",
37
- "author": "Player Two <hello@playertwo.lol>",
37
+ "author": "PlayerTwo <hello@playertwo.lol>",
38
38
  "type": "module",
39
39
  "main": "./index.mjs",
40
40
  "module": "./index.mjs",
package/room.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Types for a room's own server script: room.js at the root of a build pushed to Player Two, run on Player Two's
2
+ * Types for a room's own server script: room.js at the root of a build pushed to PlayerTwo, run on PlayerTwo's
3
3
  * servers, one copy for each room (on localhost, the SDK's stand-in runs it in the first tab). It is an ES module that
4
4
  * exports the hooks it needs; in a room with a room.js only the script writes the shared state.
5
5
  *
@@ -114,8 +114,15 @@ export interface Room<D extends object = Record<string, any>> {
114
114
  the room has the edge): in the region nearest the furthest of them, every page moved there by itself
115
115
  ("reconnecting", "reconnected", "moved"). Your code starts again there as after a restart, with room.data and the
116
116
  shared state (onCreate doesn't run again; what lives only in your module's own variables doesn't come along).
117
- Players near each other stay where they are; once a minute at most. Call it as a match starts, say. */
118
- between(): void;
117
+ Players near each other stay where they are; once a minute at most. Call it as a match starts, say. It waits
118
+ until every player has a measured round trip, and the room it opens goes back where it was, once, when the
119
+ furthest player isn't at least 10 ms faster there (then it doesn't move by itself again). It picks only wnam,
120
+ enam, weur, apac and oc by itself. `{ region }` names one instead, not checked or undone. */
121
+ between(options?: { region?: "wnam" | "enam" | "sam" | "weur" | "apac" | "oc" | "me" }): void;
122
+ /** Where the room is: `colo`, the Cloudflare data centre it runs in ("FRA", "SIN"; null for its first moment),
123
+ `region`, the one it was opened in (null: near its first player), and `moved`, its last move (where it came
124
+ from, when, the worst round trip there in ms, and whether it was a move back). */
125
+ readonly where: { colo: string | null; region: string | null; moved: { from: string | null; at: number; before: number | null; back: boolean } | null } | null;
119
126
  /** Yours to keep things in, for as long as the room is open (a world's: for good). */
120
127
  data: D;
121
128
  /** The room's own key-value store, read and written at once, for what doesn't fit in data (a world's map, its
@@ -127,7 +134,7 @@ export interface Room<D extends object = Record<string, any>> {
127
134
  /** Its keys starting with `prefix`, in order (up to `limit`, 1000). */
128
135
  keys(prefix?: string, limit?: number): string[];
129
136
  };
130
- /** Keep what the game knows of a player on Player Two's servers, for good (up to 64 KB): their player.saved in any
137
+ /** Keep what the game knows of a player on PlayerTwo's servers, for good (up to 64 KB): their player.saved in any
131
138
  of the game's rooms and worlds from then on. null forgets it. */
132
139
  save(id: string, data: Json | null): void;
133
140
  /** The room's clock (ms), the same as the pages' room.now(). */