@dice-plus/sdk 1.0.0 → 1.3.0
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.js +21 -2
- package/dist/types/sdk/src/index.d.ts +9 -3
- package/dist/types/src/embed/protocol.d.ts +41 -2
- package/dist/types/src/features/dice/types/DiceTypes.d.ts +0 -2
- package/dist/types/src/features/site-dice/siteDiceTypes.d.ts +8 -3
- package/dist/types/src/platform/relay/protocol.d.ts +48 -6
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -33,7 +33,16 @@ var RELAY_LIMITS = {
|
|
|
33
33
|
/** Wrong Passcodes for the room within 15 minutes before it refuses Passcode joins for 15 minutes. */
|
|
34
34
|
passcodeTriesPerRoom: 50,
|
|
35
35
|
passcodeRoomWindowMs: 900 * 1e3,
|
|
36
|
-
passcodeRoomLockMs: 900 * 1e3
|
|
36
|
+
passcodeRoomLockMs: 900 * 1e3,
|
|
37
|
+
/** Roll Links' roll requests, per socket: the burst, then one every two seconds. */
|
|
38
|
+
rollRequestBurst: 5,
|
|
39
|
+
rollRequestsPerSecond: .5,
|
|
40
|
+
/** A roll request as JSON, and its notation. */
|
|
41
|
+
maxRollRequestBytes: 4 * 1024,
|
|
42
|
+
maxNotationLength: 500,
|
|
43
|
+
rollIdLength: 64,
|
|
44
|
+
/** Roll Links linked to one player at once. */
|
|
45
|
+
rollLinksPerPlayer: 3
|
|
37
46
|
};
|
|
38
47
|
/** A Room Code: 8 Crockford base32 characters, stored upper case without the dash. */
|
|
39
48
|
var ROOM_CODE = /^[0-9A-HJKMNP-TV-Z]{8}$/;
|
|
@@ -60,7 +69,7 @@ function formatRoomCode(roomId) {
|
|
|
60
69
|
}
|
|
61
70
|
//#endregion
|
|
62
71
|
//#region src/index.ts
|
|
63
|
-
var SDK_VERSION = "1.
|
|
72
|
+
var SDK_VERSION = "1.3.0";
|
|
64
73
|
var DEFAULT_BASE_URL = "https://dice-plus.missinglinkdev.com";
|
|
65
74
|
/** Room Code and Passcode helpers, so a page never has to guess our formats. */
|
|
66
75
|
var rooms = {
|
|
@@ -89,6 +98,7 @@ var Embed = class {
|
|
|
89
98
|
this.onMessage = (event) => this.receive(event);
|
|
90
99
|
if (!options?.container) throw new Error(`${title} needs a container element.`);
|
|
91
100
|
this.apiKey = options.apiKey;
|
|
101
|
+
this.theme = options.theme;
|
|
92
102
|
const base = new URL(options.baseUrl ?? "https://dice-plus.missinglinkdev.com");
|
|
93
103
|
this.origin = base.origin;
|
|
94
104
|
let settle;
|
|
@@ -146,6 +156,11 @@ var Embed = class {
|
|
|
146
156
|
this.pending.clear();
|
|
147
157
|
this.listeners.clear();
|
|
148
158
|
}
|
|
159
|
+
/** Your site's colors for the embed's UI; null for ours. */
|
|
160
|
+
setTheme(theme) {
|
|
161
|
+
this.theme = theme ?? void 0;
|
|
162
|
+
return this.call("setTheme", theme);
|
|
163
|
+
}
|
|
149
164
|
/** The latest of an event, if it has come yet. */
|
|
150
165
|
last(name) {
|
|
151
166
|
return this.lastEvents.get(name);
|
|
@@ -185,6 +200,7 @@ var Embed = class {
|
|
|
185
200
|
protocol: 1,
|
|
186
201
|
sdkVersion: SDK_VERSION,
|
|
187
202
|
apiKey: this.apiKey,
|
|
203
|
+
...this.theme ? { theme: this.theme } : {},
|
|
188
204
|
...this.helloExtras()
|
|
189
205
|
});
|
|
190
206
|
}
|
|
@@ -318,6 +334,9 @@ var DicePlusTray = class extends Embed {
|
|
|
318
334
|
unlink(guestId) {
|
|
319
335
|
return this.invoke("unlink", guestId);
|
|
320
336
|
}
|
|
337
|
+
answerLink(guestId, allow) {
|
|
338
|
+
return this.invoke("answerLink", guestId, allow);
|
|
339
|
+
}
|
|
321
340
|
chooseNewPlayer() {
|
|
322
341
|
return this.invoke("chooseNewPlayer");
|
|
323
342
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { type BagEvents, type HelloMessage, type SiteDice, type TrayEvents, type TrayIdentity, type TrayMethods, type TraySettings, type UnauthorizedReason } from '../../src/embed/protocol';
|
|
1
|
+
import { type BagEvents, type EmbedTheme, type HelloMessage, type SiteDice, type TrayEvents, type TrayIdentity, type TrayMethods, type TraySettings, type UnauthorizedReason } from '../../src/embed/protocol';
|
|
2
2
|
import { normalizeRoomId } from '../../src/platform/relay/protocol';
|
|
3
3
|
import { formatRoomCode } from '../../src/platform/relay/roomCode';
|
|
4
4
|
export type * from '../../src/embed/protocol';
|
|
5
|
-
export declare const SDK_VERSION = "1.
|
|
5
|
+
export declare const SDK_VERSION = "1.3.0";
|
|
6
6
|
export declare const DEFAULT_BASE_URL = "https://dice-plus.missinglinkdev.com";
|
|
7
7
|
/** Room Code and Passcode helpers, so a page never has to guess our formats. */
|
|
8
8
|
export declare const rooms: {
|
|
@@ -24,10 +24,12 @@ interface EmbedOptions {
|
|
|
24
24
|
container: HTMLElement;
|
|
25
25
|
/** Where our embeds are served from. Leave out except to test against a development build. */
|
|
26
26
|
baseUrl?: string;
|
|
27
|
+
/** Your site's colors for the embed's UI. Dice keep their own look. */
|
|
28
|
+
theme?: EmbedTheme;
|
|
27
29
|
}
|
|
28
30
|
export interface DicePlusTrayOptions extends EmbedOptions {
|
|
29
31
|
settings?: TraySettings;
|
|
30
|
-
/** The player's name and
|
|
32
|
+
/** The player's name and color as others in the Room see them */
|
|
31
33
|
identity?: TrayIdentity;
|
|
32
34
|
/** Your site's look for dice the player's bag does not cover */
|
|
33
35
|
dice?: SiteDice;
|
|
@@ -66,6 +68,7 @@ declare abstract class Embed<Events extends CommonEvents> {
|
|
|
66
68
|
private isReady;
|
|
67
69
|
private destroyed;
|
|
68
70
|
private refused;
|
|
71
|
+
private theme;
|
|
69
72
|
private readonly onMessage;
|
|
70
73
|
protected constructor(options: EmbedOptions, path: string, title: string, style: Partial<CSSStyleDeclaration>);
|
|
71
74
|
/** Listen for an event. Returns an unsubscribe. */
|
|
@@ -73,6 +76,8 @@ declare abstract class Embed<Events extends CommonEvents> {
|
|
|
73
76
|
once<E extends keyof Events>(name: E, listener: Listener<Events[E]>): () => void;
|
|
74
77
|
/** Remove the embed and stop listening. */
|
|
75
78
|
destroy(): void;
|
|
79
|
+
/** Your site's colors for the embed's UI; null for ours. */
|
|
80
|
+
setTheme(theme: EmbedTheme | null): Promise<void>;
|
|
76
81
|
/** The latest of an event, if it has come yet. */
|
|
77
82
|
protected last<E extends keyof Events>(name: E): Events[E] | undefined;
|
|
78
83
|
/** What else this embed's hello carries. */
|
|
@@ -111,6 +116,7 @@ export declare class DicePlusTray extends Embed<DicePlusTrayEvents> {
|
|
|
111
116
|
requestLink(playerId: string): Promise<void>;
|
|
112
117
|
cancelLinkRequest(): Promise<void>;
|
|
113
118
|
unlink(guestId: string): Promise<void>;
|
|
119
|
+
answerLink(guestId: string, allow: boolean): Promise<void>;
|
|
114
120
|
chooseNewPlayer(): Promise<void>;
|
|
115
121
|
reconnect(): Promise<void>;
|
|
116
122
|
/** The latest of an event the tray repeats as state, if any yet. */
|
|
@@ -135,6 +135,22 @@ export interface TrayRollRequest {
|
|
|
135
135
|
/** Look for dice the player's bag does not cover */
|
|
136
136
|
dice?: SiteDice;
|
|
137
137
|
}
|
|
138
|
+
/**
|
|
139
|
+
* A site's colors for an embed's UI, all `#rrggbb` and optional. Anything
|
|
140
|
+
* left out is worked out from the rest. Dice never take these.
|
|
141
|
+
*/
|
|
142
|
+
export interface EmbedTheme {
|
|
143
|
+
/** Light or dark base; left out, it follows `background` */
|
|
144
|
+
mode?: 'light' | 'dark';
|
|
145
|
+
/** Buttons, the active tab, selected chips and links */
|
|
146
|
+
primary?: string;
|
|
147
|
+
/** The panel behind everything */
|
|
148
|
+
background?: string;
|
|
149
|
+
/** Cards, menus and dialogs; left out, a step off `background` */
|
|
150
|
+
surface?: string;
|
|
151
|
+
/** Text; left out, black or white to suit `mode` */
|
|
152
|
+
text?: string;
|
|
153
|
+
}
|
|
138
154
|
export interface HelloMessage {
|
|
139
155
|
tag: typeof EMBED_TAG;
|
|
140
156
|
type: 'hello';
|
|
@@ -144,6 +160,7 @@ export interface HelloMessage {
|
|
|
144
160
|
settings?: TraySettings;
|
|
145
161
|
identity?: TrayIdentity;
|
|
146
162
|
dice?: SiteDice;
|
|
163
|
+
theme?: EmbedTheme;
|
|
147
164
|
}
|
|
148
165
|
export type TrayMethods = {
|
|
149
166
|
roll: (request: TrayRollRequest) => {
|
|
@@ -152,6 +169,7 @@ export type TrayMethods = {
|
|
|
152
169
|
setSettings: (settings: TraySettings) => void;
|
|
153
170
|
setIdentity: (identity: TrayIdentity) => void;
|
|
154
171
|
setSiteDice: (dice: SiteDice | null) => void;
|
|
172
|
+
setTheme: (theme: EmbedTheme | null) => void;
|
|
155
173
|
getHistory: () => HistoryEntry[];
|
|
156
174
|
/** A new room with this browser as Host. In a room already, a new Room Code and Passcode: everyone else must rejoin */
|
|
157
175
|
createRoom: () => void;
|
|
@@ -166,6 +184,8 @@ export type TrayMethods = {
|
|
|
166
184
|
cancelLinkRequest: () => void;
|
|
167
185
|
/** End a link: this browser's own, or (the player or a GM) another's */
|
|
168
186
|
unlink: (guestId: string) => void;
|
|
187
|
+
/** This player's answer to one of `RoomState.linkAsks`. Unanswered, an ask lapses as a denial after 60 s */
|
|
188
|
+
answerLink: (guestId: string, allow: boolean) => void;
|
|
169
189
|
/** Join an OBR room as a new player, not as one of its players */
|
|
170
190
|
chooseNewPlayer: () => void;
|
|
171
191
|
/** Try the room again now after the connection gave up */
|
|
@@ -259,6 +279,23 @@ export interface RoomState {
|
|
|
259
279
|
};
|
|
260
280
|
/** Joined a home room as a new player rather than as one of its players */
|
|
261
281
|
asNewPlayer: boolean;
|
|
282
|
+
/**
|
|
283
|
+
* Others asking to roll as this player, oldest first: another screen of
|
|
284
|
+
* theirs, or the Dice+ browser extension. Show each with Allow and Deny
|
|
285
|
+
* (`answerLink`); unanswered, they lapse as a denial after 60 s.
|
|
286
|
+
*/
|
|
287
|
+
linkAsks: LinkAskState[];
|
|
288
|
+
}
|
|
289
|
+
export interface LinkAskState {
|
|
290
|
+
guest: {
|
|
291
|
+
id: string;
|
|
292
|
+
name: string;
|
|
293
|
+
color: string;
|
|
294
|
+
};
|
|
295
|
+
/** 'extension': the Dice+ browser extension; 'web': a browser on a Dice+ site */
|
|
296
|
+
platform: string;
|
|
297
|
+
/** Milliseconds since the epoch; it lapses 60 s later */
|
|
298
|
+
at: number;
|
|
262
299
|
}
|
|
263
300
|
export interface NoticeEvent {
|
|
264
301
|
message: string;
|
|
@@ -296,8 +333,10 @@ export interface PremiumState {
|
|
|
296
333
|
/** A paying patron: premium materials, shapes, fonts and unlimited dice */
|
|
297
334
|
isPremium: boolean;
|
|
298
335
|
}
|
|
299
|
-
/** The
|
|
300
|
-
export type BagMethods =
|
|
336
|
+
/** The player drives the bag; the site only sets its colors. */
|
|
337
|
+
export type BagMethods = {
|
|
338
|
+
setTheme: (theme: EmbedTheme | null) => void;
|
|
339
|
+
};
|
|
301
340
|
export type BagEvents = {
|
|
302
341
|
'premium-changed': PremiumState;
|
|
303
342
|
/** The player pressed the bag's close button; hide it if you show it as a dialog */
|
|
@@ -33,8 +33,6 @@ export declare const STYLE_COMPONENT_MAP: Partial<Record<DiceType, Partial<Recor
|
|
|
33
33
|
mesh: string;
|
|
34
34
|
collider: string;
|
|
35
35
|
}>>>>;
|
|
36
|
-
/** The die that is physically thrown: a d100 is two d10s, a Fudge die is a d6 marked −1, 0, +1. */
|
|
37
|
-
export declare function physicalDiceType(diceType: string): string;
|
|
38
36
|
export declare function getDiceVariant(diceType: DiceType): DiceVariant | undefined;
|
|
39
37
|
export declare function getDiceVariantSafe(diceType: DiceType): DiceVariant;
|
|
40
38
|
export declare function getComponentsForStyle(diceType: DiceType, style: DiceStyle): {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { DiceStyle, DiceType } from '../dice/types/DiceTypes';
|
|
2
2
|
/** One die's look, from the free fields of the standard material. Anything left out keeps our default. */
|
|
3
3
|
export interface StandardDiceStyle {
|
|
4
|
-
/** Body
|
|
4
|
+
/** Body color, `#rrggbb` */
|
|
5
5
|
color?: string;
|
|
6
|
-
/** Number
|
|
6
|
+
/** Number color, `#rrggbb` */
|
|
7
7
|
numberColor?: string;
|
|
8
8
|
/** Free fonts only: 'standard', 'norse' or 'aelfa' */
|
|
9
9
|
font?: string;
|
|
@@ -20,8 +20,13 @@ export interface StandardDiceStyle {
|
|
|
20
20
|
/** 0–1, how deep the numbers are engraved */
|
|
21
21
|
numberDepth?: number;
|
|
22
22
|
}
|
|
23
|
-
/** The look for a roll, or for the whole site: a default, and per die
|
|
23
|
+
/** The look for a roll, or for the whole site: a default, per die type, and per named die. */
|
|
24
24
|
export interface SiteDice {
|
|
25
25
|
default?: StandardDiceStyle;
|
|
26
26
|
byType?: Partial<Record<DiceType, StandardDiceStyle>>;
|
|
27
|
+
/**
|
|
28
|
+
* Dice the notation calls by name, as in `1d12{Hope}`, for players whose
|
|
29
|
+
* bag has no die of that name
|
|
30
|
+
*/
|
|
31
|
+
byName?: Record<string, StandardDiceStyle>;
|
|
27
32
|
}
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
export declare const RELAY_PROTOCOL = 1;
|
|
2
|
-
|
|
2
|
+
/** 'extension': a Roll Link (the Dice+ browser extension), which rolls on its linked player's tray. */
|
|
3
|
+
export type RelayPlatform = 'web' | 'obr' | 'embed' | 'foundry' | 'extension';
|
|
4
|
+
/** The `source` a Roll Link's roll requests carry, so its errors can find their way back. */
|
|
5
|
+
export declare const ROLL_LINK_SOURCE = "browser-extension";
|
|
6
|
+
/** The channel a Roll Link's roll request reaches its player's tray on: the external roll request. */
|
|
7
|
+
export declare const ROLL_LINK_REQUEST_CHANNEL = "dice-plus/roll-request";
|
|
3
8
|
/**
|
|
4
9
|
* 'web' rooms are temporary sessions created on the website; 'home' rooms
|
|
5
10
|
* belong to a dedicated client's own room (an OBR room, a Foundry world).
|
|
@@ -20,7 +25,7 @@ export interface RelayMember extends RelayPlayer {
|
|
|
20
25
|
gm: boolean;
|
|
21
26
|
/**
|
|
22
27
|
* A Linked Guest: the Home Group player it rolls as. Its messages come from
|
|
23
|
-
* that id, and its name,
|
|
28
|
+
* that id, and its name, color and GM Tag are that player's.
|
|
24
29
|
*/
|
|
25
30
|
linkedTo?: string;
|
|
26
31
|
}
|
|
@@ -36,8 +41,20 @@ export type LinkRefusal = 'denied'
|
|
|
36
41
|
| 'cooldown'
|
|
37
42
|
/** That player denied this connection too often. */
|
|
38
43
|
| 'blocked'
|
|
39
|
-
/**
|
|
40
|
-
| 'unavailable'
|
|
44
|
+
/** The Home Group and the Host cannot link, nor can anyone link to themselves. */
|
|
45
|
+
| 'unavailable'
|
|
46
|
+
/** That player already has as many Roll Links as the Relay allows. */
|
|
47
|
+
| 'full';
|
|
48
|
+
/** Why the Relay did not pass on a Roll Link's roll request. */
|
|
49
|
+
export type RollRefusal =
|
|
50
|
+
/** Not linked to a player. */
|
|
51
|
+
'unlinked'
|
|
52
|
+
/** The linked player has no connection that can roll. */
|
|
53
|
+
| 'unavailable'
|
|
54
|
+
/** Too many roll requests; wait a moment. */
|
|
55
|
+
| 'rateLimited'
|
|
56
|
+
/** Missing a roll id, the notation is too long, or the request is too large. */
|
|
57
|
+
| 'invalid';
|
|
41
58
|
/** Who a message is for. Absent: everyone. Otherwise GM-tagged members and/or these player ids. */
|
|
42
59
|
export interface Audience {
|
|
43
60
|
gm?: boolean;
|
|
@@ -86,7 +103,7 @@ export type ClientMessage = {
|
|
|
86
103
|
t: 'setPasscode';
|
|
87
104
|
passcode: string | null;
|
|
88
105
|
}
|
|
89
|
-
/** A Guest in
|
|
106
|
+
/** A Guest: ask this player (one in their own right, not a Linked Guest) to let it roll as them. */
|
|
90
107
|
| {
|
|
91
108
|
t: 'linkRequest';
|
|
92
109
|
player: string;
|
|
@@ -106,6 +123,15 @@ export type ClientMessage = {
|
|
|
106
123
|
| {
|
|
107
124
|
t: 'unlink';
|
|
108
125
|
guest: string;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* A Linked Guest with no tray of its own (a Roll Link): roll this on the
|
|
129
|
+
* linked player's tray. `data` is a dice-plus/roll-request; the Relay sets
|
|
130
|
+
* its player.
|
|
131
|
+
*/
|
|
132
|
+
| {
|
|
133
|
+
t: 'rollRequest';
|
|
134
|
+
data: unknown;
|
|
109
135
|
};
|
|
110
136
|
export interface RelayEnvelope {
|
|
111
137
|
from: string;
|
|
@@ -124,10 +150,11 @@ export type ServerMessage = {
|
|
|
124
150
|
} | ({
|
|
125
151
|
t: 'msg';
|
|
126
152
|
} & RelayEnvelope)
|
|
127
|
-
/** To the asked player's sockets: a Guest wants to roll as them. */
|
|
153
|
+
/** To the asked player's sockets: a Guest wants to roll as them, from this platform (absent from older relays). */
|
|
128
154
|
| {
|
|
129
155
|
t: 'linkAsk';
|
|
130
156
|
guest: RelayPlayer;
|
|
157
|
+
platform?: RelayPlatform;
|
|
131
158
|
}
|
|
132
159
|
/** To the asked player's sockets: the request is over (answered, cancelled, or the Guest left). */
|
|
133
160
|
| {
|
|
@@ -147,6 +174,12 @@ export type ServerMessage = {
|
|
|
147
174
|
/** To a Linked Guest: the link was ended. */
|
|
148
175
|
| {
|
|
149
176
|
t: 'unlinked';
|
|
177
|
+
}
|
|
178
|
+
/** To a Roll Link: its roll request went nowhere. */
|
|
179
|
+
| {
|
|
180
|
+
t: 'rollRefused';
|
|
181
|
+
rollId: string;
|
|
182
|
+
reason: RollRefusal;
|
|
150
183
|
};
|
|
151
184
|
/** WebSocket close codes the Relay uses; clients stop reconnecting on all but `replaced`. */
|
|
152
185
|
export declare const RELAY_CLOSE: {
|
|
@@ -191,6 +224,15 @@ export declare const RELAY_LIMITS: {
|
|
|
191
224
|
readonly passcodeTriesPerRoom: 50;
|
|
192
225
|
readonly passcodeRoomWindowMs: number;
|
|
193
226
|
readonly passcodeRoomLockMs: number;
|
|
227
|
+
/** Roll Links' roll requests, per socket: the burst, then one every two seconds. */
|
|
228
|
+
readonly rollRequestBurst: 5;
|
|
229
|
+
readonly rollRequestsPerSecond: 0.5;
|
|
230
|
+
/** A roll request as JSON, and its notation. */
|
|
231
|
+
readonly maxRollRequestBytes: number;
|
|
232
|
+
readonly maxNotationLength: 500;
|
|
233
|
+
readonly rollIdLength: 64;
|
|
234
|
+
/** Roll Links linked to one player at once. */
|
|
235
|
+
readonly rollLinksPerPlayer: 3;
|
|
194
236
|
};
|
|
195
237
|
export declare const ROOM_ID_PATTERN: RegExp;
|
|
196
238
|
/** A Passcode: six digits, leading zeros kept. */
|