playertwo-sdk 0.2.4 → 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.
- package/README.md +180 -27
- package/index.d.ts +13 -3
- package/index.mjs +14 -8
- package/package.json +35 -12
package/README.md
CHANGED
|
@@ -1,41 +1,122 @@
|
|
|
1
1
|
# playertwo-sdk
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
invites, add-ons, in-game purchases
|
|
5
|
-
multiplayer rooms (voice chat,
|
|
6
|
-
|
|
7
|
-
Everything it offers, each with its part of the docs: https://playertwo.lol/llms.txt
|
|
3
|
+
The game SDK for [Player Two](https://playertwo.lol), with TypeScript types. Trophies, XP and levels, stats,
|
|
4
|
+
leaderboards, cloud saves, presence, invites, add-ons, in-game purchases, the player's avatar, travel between games,
|
|
5
|
+
and multiplayer rooms with no server of your own (voice chat, worlds, replays and your own server code in `room.js`
|
|
6
|
+
included).
|
|
8
7
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
Player Two is a game store and a launchpad. Games are sold (or free) to play in the browser or download, and raises
|
|
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.
|
|
11
|
+
|
|
12
|
+
- Docs: https://playertwo.lol/docs/sdk
|
|
13
|
+
- Everything a game gets, with a link to its part of the docs: https://playertwo.lol/llms.txt
|
|
14
|
+
- Source of these packages, examples and Markdown docs: https://github.com/TheDudeCommits/playertwo-sdk
|
|
15
|
+
|
|
16
|
+
## Install
|
|
12
17
|
|
|
13
18
|
```
|
|
14
19
|
npm install playertwo-sdk
|
|
15
20
|
```
|
|
16
21
|
|
|
22
|
+
Or no install at all: the SDK itself is one script.
|
|
23
|
+
|
|
24
|
+
```html
|
|
25
|
+
<script src="https://playertwo.lol/sdk/v1.js"></script>
|
|
26
|
+
<script>
|
|
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 */
|
|
29
|
+
});
|
|
30
|
+
</script>
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
On Player Two the script is already in your game's page. `init()` from the npm package uses that copy, and loads
|
|
34
|
+
`https://playertwo.lol/sdk/v1.js` only when the page doesn't have it (on localhost, say).
|
|
35
|
+
|
|
36
|
+
## Quick start
|
|
37
|
+
|
|
17
38
|
```ts
|
|
18
39
|
import { init } from "playertwo-sdk";
|
|
19
40
|
|
|
20
|
-
const p2 = await init(
|
|
21
|
-
|
|
41
|
+
const p2 = await init({
|
|
42
|
+
// localhost only: the stand-in's trophies (it refuses keys you don't list, as Player Two would)
|
|
43
|
+
local: { trophies: [{ key: "first-win", name: "First win", tier: 1 }] },
|
|
44
|
+
});
|
|
45
|
+
console.log(p2.env, p2.player?.name, p2.player?.level); // env: "p2" | "local" | "disabled"
|
|
46
|
+
|
|
47
|
+
await p2.trophies.unlock("first-win"); // the player sees the toast
|
|
48
|
+
await p2.scores.submit("time-attack", 83400); // a board you made in your studio
|
|
49
|
+
await p2.stats.add("duels-won");
|
|
50
|
+
await p2.saves.list(); // read before you write over a slot
|
|
51
|
+
await p2.saves.put("slot-1", { level: 3 });
|
|
22
52
|
|
|
23
53
|
const room = await p2.rooms.join({ mode: "arena", size: 16 });
|
|
24
|
-
room.on("message:
|
|
25
|
-
room.send("emote", "wave");
|
|
54
|
+
room.on("message:emote", (kind, from) => showEmote(from, kind));
|
|
55
|
+
room.send("emote", "wave"); // to everyone else in the room
|
|
26
56
|
|
|
27
|
-
const sync = room.sync(myMesh, { fields: ["position.x", "position.y", "position.z", "rotation.y"],
|
|
28
|
-
sync.on("join", (id) => sync.bind(id, makeMesh(id)));
|
|
29
|
-
|
|
57
|
+
const sync = room.sync(myMesh, { fields: ["position.x", "position.y", "position.z", "rotation.y"], angles: ["rotation.y"] });
|
|
58
|
+
sync.on("join", (id) => sync.bind(id, makeMesh(id))); // everyone else's mesh, moved smoothly
|
|
59
|
+
sync.on("leave", (id) => removeMesh(id));
|
|
60
|
+
// once a frame, after you move: sync.step();
|
|
30
61
|
```
|
|
31
62
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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.
|
|
66
|
+
|
|
67
|
+
## What it gives your game
|
|
68
|
+
|
|
69
|
+
| Feature | Calls | Docs |
|
|
70
|
+
| --- | --- | --- |
|
|
71
|
+
| Who is playing | `p2.player`, `p2.game`, `p2.me()` | [call-me](https://playertwo.lol/docs/sdk#call-me) |
|
|
72
|
+
| Trophies, XP and levels | `p2.trophies.list()`, `p2.trophies.unlock(key)` | [call-trophies](https://playertwo.lol/docs/sdk#call-trophies) |
|
|
73
|
+
| Leaderboards | `p2.scores.submit(board, value)`, `p2.scores.list(board, { around, friends, limit })` | [call-scores](https://playertwo.lol/docs/sdk#call-scores) |
|
|
74
|
+
| Stats | `p2.stats.get()`, `.get(key)`, `.set(key, n)`, `.add(key, n?)` | [call-stats](https://playertwo.lol/docs/sdk#call-stats) |
|
|
75
|
+
| Cloud saves (8 slots, 1 MB each) | `p2.saves.list()`, `.get(slot)`, `.put(slot, data, { version })`, `.delete(slot)` | [call-saves](https://playertwo.lol/docs/sdk#call-saves) |
|
|
76
|
+
| Add-ons (sold on the game's page) | `p2.addons.list()`, `p2.addons.has(key)` | [addons](https://playertwo.lol/docs/sdk#addons) |
|
|
77
|
+
| In-game purchases | `p2.store.list()`, `.owned()`, `.buy(key)`, `.pay(chargeId)` | [purchases](https://playertwo.lol/docs/sdk#purchases) |
|
|
78
|
+
| Presence | `p2.presence.set(line, { join })` | [call-presence](https://playertwo.lol/docs/sdk#call-presence) |
|
|
79
|
+
| Identity and invites | `p2.identity()`, `p2.invite(params)`, `p2.params` | [call-identity](https://playertwo.lol/docs/sdk#call-identity) |
|
|
80
|
+
| Loading and play events | `p2.loading.done()`, `p2.gameplay.start()`, `.stop()` | [call-gameplay](https://playertwo.lol/docs/sdk#call-gameplay) |
|
|
81
|
+
| The overlay, and closing | `p2.on("overlay", fn)`, `p2.on("flush", fn)` | [call-overlay](https://playertwo.lol/docs/sdk#call-overlay) |
|
|
82
|
+
| On air in the Plaza | `p2.onAir` | [call-air](https://playertwo.lol/docs/sdk#call-air) |
|
|
83
|
+
| Test mode and demos | `p2.test`, `p2.demo` | [test](https://playertwo.lol/docs/sdk#test) |
|
|
84
|
+
| The player's avatar, 2D and 3D | `p2.avatar()`, `p2.items.list()` | [travel#avatar](https://playertwo.lol/docs/sdk/travel#avatar) |
|
|
85
|
+
| Travel with the party | `p2.travel.to(slug, { params, place })`, `.home()`, `.links()` | [travel#travel](https://playertwo.lol/docs/sdk/travel#travel) |
|
|
86
|
+
|
|
87
|
+
Multiplayer, through `p2.rooms`:
|
|
88
|
+
|
|
89
|
+
| Feature | Calls | Docs |
|
|
90
|
+
| --- | --- | --- |
|
|
91
|
+
| Matches, private codes, parties | `p2.rooms.join({ mode, size, teams, skill, together, code, room })`, `.create()`, `.party()` | [rooms-join](https://playertwo.lol/docs/sdk#rooms-join) |
|
|
92
|
+
| Messages and shared state | `room.send(type, data, { to, fast })`, `room.on("message:<type>")`, `room.set`, `room.get`, `room.state` | [rooms-talk](https://playertwo.lol/docs/sdk#rooms-talk) |
|
|
93
|
+
| Smooth movement | `room.sync(object, options)` | [rooms-sync](https://playertwo.lol/docs/sdk#rooms-sync) |
|
|
94
|
+
| Ping, stats, the room's clock | `room.ping()`, `room.stats()`, `room.now()` | [rooms-fast](https://playertwo.lol/docs/sdk#rooms-fast) |
|
|
95
|
+
| Your server code (`room.js`) | see below | [rooms-scripted](https://playertwo.lol/docs/sdk#rooms-scripted) |
|
|
96
|
+
| Input-run rooms (client prediction, corrected by the server's state) | `room.inputs({ state, input, step })` | [rooms-inputs](https://playertwo.lol/docs/sdk#rooms-inputs) |
|
|
97
|
+
| Corrections and lag-compensated hits | `onSync`, `room.correct`, `room.past` (room.js); `sync.seen(id)` | [rooms-corrections](https://playertwo.lol/docs/sdk#rooms-corrections) |
|
|
98
|
+
| Server-moved objects | `room.objects()` (page), `room.objects.set` (room.js) | [rooms-objects](https://playertwo.lol/docs/sdk#rooms-objects) |
|
|
99
|
+
| Physics engines in WebAssembly | a `room/` folder | [rooms-engines](https://playertwo.lol/docs/sdk#rooms-engines) |
|
|
100
|
+
| Teams and party matches | `{ teams, together }`, `room.team(id, n)` | [rooms-teams](https://playertwo.lol/docs/sdk#rooms-teams) |
|
|
101
|
+
| Matching by skill (Elo by mode) | `{ skill: true }`, `room.result(places)` | [rooms-matching](https://playertwo.lol/docs/sdk#rooms-matching) |
|
|
102
|
+
| Ranked boards and server-given trophies | `room.score`, `room.trophy` (room.js) | [rooms-ranked](https://playertwo.lol/docs/sdk#rooms-ranked) |
|
|
103
|
+
| Watching and replays | `p2.rooms.live()`, `.watch({ room })`, `.replays()`, `.replay(id)`, `room.record()` | [rooms-watch](https://playertwo.lol/docs/sdk#rooms-watch) |
|
|
104
|
+
| Worlds of up to 256 an area | `p2.rooms.world(name, { area })` | [rooms-worlds](https://playertwo.lol/docs/sdk#rooms-worlds) |
|
|
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
|
+
| 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
|
+
|
|
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:
|
|
110
|
+
https://playertwo.lol/docs/sdk#rooms-limits.
|
|
111
|
+
|
|
112
|
+
## A room's server: `playertwo-sdk/room`
|
|
113
|
+
|
|
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
|
|
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.
|
|
118
|
+
|
|
119
|
+
Plain JavaScript with JSDoc types (it is pushed as it is):
|
|
39
120
|
|
|
40
121
|
```js
|
|
41
122
|
// @ts-check
|
|
@@ -50,7 +131,7 @@ export function onJoin(room, player) {
|
|
|
50
131
|
}
|
|
51
132
|
```
|
|
52
133
|
|
|
53
|
-
|
|
134
|
+
Bundled from TypeScript into one file, `defineRoom` types every hook at once:
|
|
54
135
|
|
|
55
136
|
```ts
|
|
56
137
|
import { defineRoom } from "playertwo-sdk/room";
|
|
@@ -62,7 +143,79 @@ export const { tickRate, onCreate, onJoin, onLeave, onMessage, onSync, onTick }
|
|
|
62
143
|
});
|
|
63
144
|
```
|
|
64
145
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
146
|
+
Hooks: `onCreate`, `onStart`, `onJoin`, `onLeave`, `onMessage`, `onSync`, `onTick`. Everything `room` has:
|
|
147
|
+
[`room.d.ts`](./room.d.ts).
|
|
148
|
+
|
|
149
|
+
## Building without Player Two
|
|
150
|
+
|
|
151
|
+
On localhost, a stand-in answers every call from memory, and two tabs are two players. If your dev server serves
|
|
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
|
+
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.
|
|
155
|
+
|
|
156
|
+
On Player Two you, your team and your playtesters play in test mode (`p2.test` is true): every call works, nothing is
|
|
157
|
+
paid, and what you earn is kept apart. Docs: https://playertwo.lol/docs/sdk#test.
|
|
158
|
+
|
|
159
|
+
Using the script tag and only want the types of the global `PlayerTwo`? Add `"types": ["playertwo-sdk"]` to your
|
|
160
|
+
`tsconfig.json`, or `/// <reference types="playertwo-sdk" />` at the top of a file.
|
|
161
|
+
|
|
162
|
+
## In-game purchases
|
|
163
|
+
|
|
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
|
|
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,
|
|
169
|
+
keys at https://playertwo.lol/.well-known/p2-keys.json) and your studio's webhooks a `purchase` event. Docs:
|
|
170
|
+
https://playertwo.lol/docs/sdk#purchases.
|
|
171
|
+
|
|
172
|
+
## Your game's own server
|
|
173
|
+
|
|
174
|
+
A game key (`p2g_...`, made in your studio) lets your server check a session or a signed identity from
|
|
175
|
+
`p2.identity()`, give server-only trophies, post to trusted leaderboards, read add-ons, make and check charges, use up
|
|
176
|
+
consumables and report matches, under `https://playertwo.lol/api/v1/sdk/server/...`. Docs:
|
|
177
|
+
https://playertwo.lol/docs/sdk#server and https://playertwo.lol/docs/sdk/connect (a game played on its own site).
|
|
178
|
+
|
|
179
|
+
## Putting it on Player Two
|
|
180
|
+
|
|
181
|
+
A whole game to start from: `npm create playertwo-game@latest my-game` (a small multiplayer Three.js game with rooms
|
|
182
|
+
and `room.js`, see [create-playertwo-game](https://www.npmjs.com/package/create-playertwo-game)).
|
|
183
|
+
|
|
184
|
+
1. Submit the game at https://playertwo.lol/submit (that gives it its address, `your-game`).
|
|
185
|
+
2. Make an agent key in your studio, under Agents.
|
|
186
|
+
3. Push the build:
|
|
187
|
+
|
|
188
|
+
```
|
|
189
|
+
curl -fsSLO https://playertwo.lol/cli/p2.mjs
|
|
190
|
+
P2_AGENT_KEY=p2_agent_... node p2.mjs push dist --game your-game --version 1.0.0
|
|
191
|
+
```
|
|
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.
|
|
195
|
+
|
|
196
|
+
## For AI agents: MCP and the agent API
|
|
197
|
+
|
|
198
|
+
Player Two runs an MCP server (Streamable HTTP) at `https://playertwo.lol/api/mcp`:
|
|
199
|
+
|
|
200
|
+
```
|
|
201
|
+
claude mcp add --transport http player-two https://playertwo.lol/api/mcp
|
|
202
|
+
claude mcp add --transport http player-two https://playertwo.lol/api/mcp --header "Authorization: Bearer p2_agent_..."
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
The first line is enough for the public tools, which need no key: `get_submission_guide` and `check_game`, and
|
|
206
|
+
`search_games`, `list_games`, `get_game_facts`, `get_sdk_docs` and `where_to_publish`. Tools that change a game
|
|
207
|
+
(submit it, edit its page, upload media and web builds, define trophies, leaderboards and products, roll back builds,
|
|
208
|
+
post updates, read its rooms) need the player's agent key, made in their studio on playertwo.lol under Agents, or no
|
|
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
|
|
211
|
+
`lol.playertwo/mcp`; its server card is at https://playertwo.lol/.well-known/mcp.json.
|
|
212
|
+
|
|
213
|
+
- The agent API: `GET https://playertwo.lol/api/v1/agent/guide` explains every field; submit with
|
|
214
|
+
`POST https://playertwo.lol/api/v1/agent/games` `{ "draft": { ... }, "publish": true }`.
|
|
215
|
+
- OpenAPI 3.1 spec: https://playertwo.lol/openapi.json
|
|
216
|
+
- For language models: https://playertwo.lol/llms.txt
|
|
217
|
+
- Docs: https://playertwo.lol/docs#agents
|
|
218
|
+
|
|
219
|
+
## License
|
|
220
|
+
|
|
221
|
+
MIT. Copyright (c) 2026 Player Two.
|
package/index.d.ts
CHANGED
|
@@ -398,7 +398,11 @@ export interface Voice {
|
|
|
398
398
|
readonly who: readonly string[];
|
|
399
399
|
/** Your microphone to everyone else in voice, and theirs to you (the browser asks for the microphone first):
|
|
400
400
|
resolves once you're in. Fails with "no-mic" (not allowed), "voice-full" (24 in voice already) or "no-voice". */
|
|
401
|
-
join(options?: {
|
|
401
|
+
join(options?: {
|
|
402
|
+
muted?: boolean;
|
|
403
|
+
/** a microphone your page has already, sent instead of asking the browser for one (stopped when you leave) */
|
|
404
|
+
mic?: MediaStream;
|
|
405
|
+
}): Promise<void>;
|
|
402
406
|
/** Out of voice: your microphone let go, and no one heard. */
|
|
403
407
|
leave(): void;
|
|
404
408
|
/** Your microphone off (true) or on (false), or the other way: says whether it is off. */
|
|
@@ -408,6 +412,10 @@ export interface Voice {
|
|
|
408
412
|
volume(id: string, volume: number): void;
|
|
409
413
|
/** Whether a player (or you) is speaking now. */
|
|
410
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;
|
|
411
419
|
}
|
|
412
420
|
|
|
413
421
|
export interface SendOptions {
|
|
@@ -767,12 +775,14 @@ declare global {
|
|
|
767
775
|
|
|
768
776
|
/** Where the SDK is loaded from when the page doesn't have it. */
|
|
769
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[];
|
|
770
780
|
|
|
771
|
-
/** window.PlayerTwo, loading the script from `src
|
|
781
|
+
/** window.PlayerTwo, loading the script from `src`, else from each of SDK_URLS in turn, if the page doesn't have it. */
|
|
772
782
|
export function load(src?: string): Promise<PlayerTwoGlobal>;
|
|
773
783
|
|
|
774
784
|
/** PlayerTwo.init(options), loading the SDK first if the page doesn't have it. */
|
|
775
785
|
export function init(options?: InitOptions): Promise<P2>;
|
|
776
786
|
|
|
777
|
-
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[] };
|
|
778
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
|
-
|
|
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
|
-
|
|
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 =
|
|
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
|
|
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 ${
|
|
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,8 +1,40 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "playertwo-sdk",
|
|
3
|
-
"version": "0.2.
|
|
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.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"playertwo",
|
|
7
|
+
"player-two",
|
|
8
|
+
"game-sdk",
|
|
9
|
+
"gamedev",
|
|
10
|
+
"html5-games",
|
|
11
|
+
"browser-games",
|
|
12
|
+
"web-games",
|
|
13
|
+
"multiplayer",
|
|
14
|
+
"rooms",
|
|
15
|
+
"netcode",
|
|
16
|
+
"matchmaking",
|
|
17
|
+
"authoritative-server",
|
|
18
|
+
"leaderboards",
|
|
19
|
+
"achievements",
|
|
20
|
+
"trophies",
|
|
21
|
+
"cloud-saves",
|
|
22
|
+
"voice-chat",
|
|
23
|
+
"in-app-purchases",
|
|
24
|
+
"typescript",
|
|
25
|
+
"threejs"
|
|
26
|
+
],
|
|
27
|
+
"homepage": "https://playertwo.lol/docs/sdk",
|
|
28
|
+
"bugs": {
|
|
29
|
+
"url": "https://github.com/TheDudeCommits/playertwo-sdk/issues"
|
|
30
|
+
},
|
|
31
|
+
"repository": {
|
|
32
|
+
"type": "git",
|
|
33
|
+
"url": "git+https://github.com/TheDudeCommits/playertwo-sdk.git",
|
|
34
|
+
"directory": "packages/sdk"
|
|
35
|
+
},
|
|
4
36
|
"license": "MIT",
|
|
5
|
-
"
|
|
37
|
+
"author": "Player Two <hello@playertwo.lol>",
|
|
6
38
|
"type": "module",
|
|
7
39
|
"main": "./index.mjs",
|
|
8
40
|
"module": "./index.mjs",
|
|
@@ -25,14 +57,5 @@
|
|
|
25
57
|
"room.d.ts",
|
|
26
58
|
"README.md"
|
|
27
59
|
],
|
|
28
|
-
"sideEffects": false
|
|
29
|
-
"keywords": [
|
|
30
|
-
"playertwo",
|
|
31
|
-
"game",
|
|
32
|
-
"multiplayer",
|
|
33
|
-
"rooms",
|
|
34
|
-
"threejs",
|
|
35
|
-
"sdk"
|
|
36
|
-
],
|
|
37
|
-
"homepage": "https://playertwo.lol/docs/sdk"
|
|
60
|
+
"sideEffects": false
|
|
38
61
|
}
|