@ksaa-nlp/gamehub-react-native-sdk 0.0.0-stage → 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/README.md +315 -2
- package/SPEC.md +294 -0
- package/dist/src/answers.d.ts +5 -0
- package/dist/src/answers.d.ts.map +1 -0
- package/dist/src/answers.js +32 -0
- package/dist/src/answers.js.map +1 -0
- package/dist/src/api-client.d.ts +7 -0
- package/dist/src/api-client.d.ts.map +1 -0
- package/dist/src/api-client.js +123 -0
- package/dist/src/api-client.js.map +1 -0
- package/dist/src/config.d.ts +15 -0
- package/dist/src/config.d.ts.map +1 -0
- package/dist/src/config.js +45 -0
- package/dist/src/config.js.map +1 -0
- package/dist/src/constants.d.ts +6 -0
- package/dist/src/constants.d.ts.map +1 -0
- package/dist/src/constants.js +6 -0
- package/dist/src/constants.js.map +1 -0
- package/dist/src/content.d.ts +7 -0
- package/dist/src/content.d.ts.map +1 -0
- package/dist/src/content.js +70 -0
- package/dist/src/content.js.map +1 -0
- package/dist/src/host-events.d.ts +7 -0
- package/dist/src/host-events.d.ts.map +1 -0
- package/dist/src/host-events.js +20 -0
- package/dist/src/host-events.js.map +1 -0
- package/dist/src/identity.d.ts +10 -0
- package/dist/src/identity.d.ts.map +1 -0
- package/dist/src/identity.js +27 -0
- package/dist/src/identity.js.map +1 -0
- package/dist/src/index.d.ts +6 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +75 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/launch.d.ts +16 -0
- package/dist/src/launch.d.ts.map +1 -0
- package/dist/src/launch.js +115 -0
- package/dist/src/launch.js.map +1 -0
- package/dist/src/loading.d.ts +8 -0
- package/dist/src/loading.d.ts.map +1 -0
- package/dist/src/loading.js +96 -0
- package/dist/src/loading.js.map +1 -0
- package/dist/src/lobby-request.d.ts +4 -0
- package/dist/src/lobby-request.d.ts.map +1 -0
- package/dist/src/lobby-request.js +46 -0
- package/dist/src/lobby-request.js.map +1 -0
- package/dist/src/lobby.d.ts +34 -0
- package/dist/src/lobby.d.ts.map +1 -0
- package/dist/src/lobby.js +311 -0
- package/dist/src/lobby.js.map +1 -0
- package/dist/src/match-context.d.ts +10 -0
- package/dist/src/match-context.d.ts.map +1 -0
- package/dist/src/match-context.js +41 -0
- package/dist/src/match-context.js.map +1 -0
- package/dist/src/multiplayer-client.d.ts +27 -0
- package/dist/src/multiplayer-client.d.ts.map +1 -0
- package/dist/src/multiplayer-client.js +163 -0
- package/dist/src/multiplayer-client.js.map +1 -0
- package/dist/src/multiplayer-react.d.ts +4 -0
- package/dist/src/multiplayer-react.d.ts.map +1 -0
- package/dist/src/multiplayer-react.js +8 -0
- package/dist/src/multiplayer-react.js.map +1 -0
- package/dist/src/multiplayer-storage.d.ts +22 -0
- package/dist/src/multiplayer-storage.d.ts.map +1 -0
- package/dist/src/multiplayer-storage.js +65 -0
- package/dist/src/multiplayer-storage.js.map +1 -0
- package/dist/src/multiplayer-types.d.ts +56 -0
- package/dist/src/multiplayer-types.d.ts.map +1 -0
- package/dist/src/multiplayer-types.js +2 -0
- package/dist/src/multiplayer-types.js.map +1 -0
- package/dist/src/multiplayer.d.ts +5 -0
- package/dist/src/multiplayer.d.ts.map +1 -0
- package/dist/src/multiplayer.js +4 -0
- package/dist/src/multiplayer.js.map +1 -0
- package/dist/src/react.d.ts +12 -0
- package/dist/src/react.d.ts.map +1 -0
- package/dist/src/react.js +24 -0
- package/dist/src/react.js.map +1 -0
- package/dist/src/score.d.ts +9 -0
- package/dist/src/score.d.ts.map +1 -0
- package/dist/src/score.js +168 -0
- package/dist/src/score.js.map +1 -0
- package/dist/src/session-view.d.ts +4 -0
- package/dist/src/session-view.d.ts.map +1 -0
- package/dist/src/session-view.js +276 -0
- package/dist/src/session-view.js.map +1 -0
- package/dist/src/session.d.ts +10 -0
- package/dist/src/session.d.ts.map +1 -0
- package/dist/src/session.js +221 -0
- package/dist/src/session.js.map +1 -0
- package/dist/src/settings.d.ts +4 -0
- package/dist/src/settings.d.ts.map +1 -0
- package/dist/src/settings.js +40 -0
- package/dist/src/settings.js.map +1 -0
- package/dist/src/types.d.ts +137 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +2 -0
- package/dist/src/types.js.map +1 -0
- package/dist/src/utils.d.ts +5 -0
- package/dist/src/utils.d.ts.map +1 -0
- package/dist/src/utils.js +16 -0
- package/dist/src/utils.js.map +1 -0
- package/dist/vendor/colyseus-schemas/clock.d.ts +15 -0
- package/dist/vendor/colyseus-schemas/clock.js +67 -0
- package/dist/vendor/colyseus-schemas/common.d.ts +35 -0
- package/dist/vendor/colyseus-schemas/common.js +15 -0
- package/dist/vendor/colyseus-schemas/multiplayer.d.ts +8 -0
- package/dist/vendor/colyseus-schemas/multiplayer.js +26 -0
- package/dist/vendor/colyseus-schemas/ugc.d.ts +53 -0
- package/dist/vendor/colyseus-schemas/ugc.js +124 -0
- package/dist/vendor/gamehub-multiplayer-contracts/index.d.ts +200 -0
- package/dist/vendor/gamehub-multiplayer-contracts/index.js +289 -0
- package/dist/vendor/loading.d.ts +6 -0
- package/dist/vendor/loading.d.ts.map +1 -0
- package/dist/vendor/loading.js +2 -0
- package/dist/vendor/loading.js.map +1 -0
- package/dist/vendor/match.d.ts +37 -0
- package/dist/vendor/match.d.ts.map +1 -0
- package/dist/vendor/match.js +2 -0
- package/dist/vendor/match.js.map +1 -0
- package/dist/vendor/multiplayer-client.d.ts +52 -0
- package/dist/vendor/multiplayer-client.d.ts.map +1 -0
- package/dist/vendor/multiplayer-client.js +286 -0
- package/dist/vendor/multiplayer-client.js.map +1 -0
- package/dist/vendor/multiplayer-session.d.ts +82 -0
- package/dist/vendor/multiplayer-session.d.ts.map +1 -0
- package/dist/vendor/multiplayer-session.js +2 -0
- package/dist/vendor/multiplayer-session.js.map +1 -0
- package/dist/vendor/question.d.ts +35 -0
- package/dist/vendor/question.d.ts.map +1 -0
- package/dist/vendor/question.js +20 -0
- package/dist/vendor/question.js.map +1 -0
- package/dist/vendor/session.d.ts +174 -0
- package/dist/vendor/session.d.ts.map +1 -0
- package/dist/vendor/session.js +2 -0
- package/dist/vendor/session.js.map +1 -0
- package/dist/vendor/word.d.ts +147 -0
- package/dist/vendor/word.d.ts.map +1 -0
- package/dist/vendor/word.js +15 -0
- package/dist/vendor/word.js.map +1 -0
- package/package.json +90 -4
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A single member belonging to a match participant (team player).
|
|
3
|
+
*/
|
|
4
|
+
export interface MatchParticipantMember {
|
|
5
|
+
leaguePlayerId: string;
|
|
6
|
+
fullname?: string;
|
|
7
|
+
avatar?: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* A participant (individual or team) in a league match.
|
|
11
|
+
*/
|
|
12
|
+
export interface MatchParticipant {
|
|
13
|
+
participantId: string;
|
|
14
|
+
name?: string;
|
|
15
|
+
members?: MatchParticipantMember[];
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The full context for a league match this game is being played in.
|
|
19
|
+
*/
|
|
20
|
+
export interface MatchContext {
|
|
21
|
+
id: string;
|
|
22
|
+
leagueId: string;
|
|
23
|
+
gameId: string;
|
|
24
|
+
participant1: MatchParticipant;
|
|
25
|
+
participant2: MatchParticipant;
|
|
26
|
+
status: string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Payload submitted via `submitMatchResult`.
|
|
30
|
+
*/
|
|
31
|
+
export interface MatchResultPayload {
|
|
32
|
+
winnerId?: string;
|
|
33
|
+
reason?: string;
|
|
34
|
+
scores?: Record<string, number>;
|
|
35
|
+
details?: Record<string, any>;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=match.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"match.d.ts","sourceRoot":"","sources":["../../vendor/match.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,cAAc,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,aAAa,EAAE,MAAM,CAAC;IACtB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,sBAAsB,EAAE,CAAC;CACpC;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,gBAAgB,CAAC;IAC/B,YAAY,EAAE,gBAAgB,CAAC;IAC/B,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC/B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"match.js","sourceRoot":"","sources":["../../vendor/match.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { MultiplayerState } from '#colyseus-schemas/multiplayer';
|
|
2
|
+
import { type LaunchReference, type MultiplayerError } from '#multiplayer-contracts';
|
|
3
|
+
export type ConnectionStatus = 'disconnected' | 'connecting' | 'loading' | 'playing' | 'reconnecting' | 'finishing' | 'completed' | 'failed';
|
|
4
|
+
export interface LaunchHost {
|
|
5
|
+
requestMultiplayerLaunch(): Promise<unknown>;
|
|
6
|
+
/** Optional presentation integration; no browser globals in the shared core. */
|
|
7
|
+
setLoading?(state: 'loading' | 'waiting-for-players' | 'reconnecting' | 'failed' | null, launch: LaunchReference): void;
|
|
8
|
+
}
|
|
9
|
+
export interface TokenStorage {
|
|
10
|
+
getItem(key: string): string | null;
|
|
11
|
+
setItem(key: string, value: string): void;
|
|
12
|
+
removeItem(key: string): void;
|
|
13
|
+
}
|
|
14
|
+
export interface MultiplayerSnapshot {
|
|
15
|
+
status: ConnectionStatus;
|
|
16
|
+
error: MultiplayerError | null;
|
|
17
|
+
storageAvailable: boolean;
|
|
18
|
+
state: MultiplayerState | null;
|
|
19
|
+
}
|
|
20
|
+
/** Game-owned socket. One adapter per active document/round; no credentials go to parent pages. */
|
|
21
|
+
export declare class MultiplayerClient {
|
|
22
|
+
private readonly host;
|
|
23
|
+
readonly launch: LaunchReference;
|
|
24
|
+
private readonly storage?;
|
|
25
|
+
private readonly makeClient;
|
|
26
|
+
private room;
|
|
27
|
+
private operation;
|
|
28
|
+
private generation;
|
|
29
|
+
private disposed;
|
|
30
|
+
private recoverUntil;
|
|
31
|
+
private cancelRetry;
|
|
32
|
+
private unsubscribers;
|
|
33
|
+
private listeners;
|
|
34
|
+
private token;
|
|
35
|
+
private endpoint;
|
|
36
|
+
private clockNow;
|
|
37
|
+
private snapshot;
|
|
38
|
+
private readonly storageKey;
|
|
39
|
+
constructor(host: LaunchHost, launch: LaunchReference, storage?: TokenStorage | undefined, makeClient?: (endpoint: string) => import("@colyseus/sdk").ColyseusSDK<any, any>);
|
|
40
|
+
getSnapshot(): MultiplayerSnapshot;
|
|
41
|
+
subscribe(listener: (state: MultiplayerSnapshot) => void): () => void;
|
|
42
|
+
serverNow(): number;
|
|
43
|
+
connect(): Promise<void>;
|
|
44
|
+
private join;
|
|
45
|
+
send<T>(type: string, payload: T): boolean;
|
|
46
|
+
leave(): Promise<void>;
|
|
47
|
+
private detach;
|
|
48
|
+
private remember;
|
|
49
|
+
private clearToken;
|
|
50
|
+
private update;
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=multiplayer-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
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AA8B;IAC/C,OAAO,CAAC,UAAU,CAAK;IACvB,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,YAAY,CAAK;IACzB,OAAO,CAAC,WAAW,CAA6B;IAChD,OAAO,CAAC,aAAa,CAAsB;IAC3C,OAAO,CAAC,SAAS,CAAmD;IACpE,OAAO,CAAC,KAAK,CAAuB;IACpC,OAAO,CAAC,QAAQ,CAAuB;IACvC,OAAO,CAAC,QAAQ,CAAoB;IACpC,OAAO,CAAC,QAAQ,CAKd;IACF,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;gBAEjB,IAAI,EAAE,UAAU,EACxB,MAAM,EAAE,eAAe,EACf,OAAO,CAAC,EAAE,YAAY,YAAA,EACtB,UAAU,IAAI,UAAU,MAAM,kDAAyB;IAY1E,WAAW,IAAI,mBAAmB;IAGlC,SAAS,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,mBAAmB,KAAK,IAAI,GAAG,MAAM,IAAI;IAKrE,SAAS,IAAI,MAAM;IAGnB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;YAmCV,IAAI;IA2IlB,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,GAAG,OAAO;IAWpC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAa5B,OAAO,CAAC,MAAM;IAGd,OAAO,CAAC,QAAQ;IAehB,OAAO,CAAC,UAAU;IAQlB,OAAO,CAAC,MAAM;CAwBf"}
|
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
import { Client } from '@colyseus/sdk';
|
|
2
|
+
import { attachServerClock } from '#colyseus-schemas/clock';
|
|
3
|
+
import { MultiplayerState } from '#colyseus-schemas/multiplayer';
|
|
4
|
+
import { isLaunchOutcome, normalizeError, RECOVERY_GRACE_MS, } from '#multiplayer-contracts';
|
|
5
|
+
/** Game-owned socket. One adapter per active document/round; no credentials go to parent pages. */
|
|
6
|
+
export class MultiplayerClient {
|
|
7
|
+
constructor(host, launch, storage, makeClient = (endpoint) => new Client(endpoint)) {
|
|
8
|
+
this.host = host;
|
|
9
|
+
this.launch = launch;
|
|
10
|
+
this.storage = storage;
|
|
11
|
+
this.makeClient = makeClient;
|
|
12
|
+
this.room = null;
|
|
13
|
+
this.operation = null;
|
|
14
|
+
this.generation = 0;
|
|
15
|
+
this.disposed = false;
|
|
16
|
+
this.recoverUntil = 0;
|
|
17
|
+
this.cancelRetry = null;
|
|
18
|
+
this.unsubscribers = [];
|
|
19
|
+
this.listeners = new Set();
|
|
20
|
+
this.token = null;
|
|
21
|
+
this.endpoint = null;
|
|
22
|
+
this.clockNow = () => Date.now();
|
|
23
|
+
this.snapshot = {
|
|
24
|
+
status: 'disconnected',
|
|
25
|
+
error: null,
|
|
26
|
+
storageAvailable: true,
|
|
27
|
+
state: null,
|
|
28
|
+
};
|
|
29
|
+
this.storageKey = [
|
|
30
|
+
// Also the SDK Usage Report's implementation marker; keep the literal.
|
|
31
|
+
'gamehub.mp.v2',
|
|
32
|
+
launch.hostInstanceId,
|
|
33
|
+
launch.multiplayerSessionId,
|
|
34
|
+
launch.roundId,
|
|
35
|
+
launch.seatId,
|
|
36
|
+
].join(':');
|
|
37
|
+
if (!storage)
|
|
38
|
+
this.snapshot.storageAvailable = false;
|
|
39
|
+
}
|
|
40
|
+
getSnapshot() {
|
|
41
|
+
return this.snapshot;
|
|
42
|
+
}
|
|
43
|
+
subscribe(listener) {
|
|
44
|
+
this.listeners.add(listener);
|
|
45
|
+
listener(this.snapshot);
|
|
46
|
+
return () => this.listeners.delete(listener);
|
|
47
|
+
}
|
|
48
|
+
serverNow() {
|
|
49
|
+
return this.clockNow();
|
|
50
|
+
}
|
|
51
|
+
connect() {
|
|
52
|
+
if (this.disposed || this.snapshot.status === 'completed')
|
|
53
|
+
return Promise.resolve();
|
|
54
|
+
if (this.operation)
|
|
55
|
+
return this.operation;
|
|
56
|
+
if (this.room)
|
|
57
|
+
return Promise.resolve();
|
|
58
|
+
const generation = this.generation;
|
|
59
|
+
const operation = (async () => {
|
|
60
|
+
do {
|
|
61
|
+
await this.join(generation);
|
|
62
|
+
if (generation !== this.generation ||
|
|
63
|
+
this.snapshot.status !== 'failed' ||
|
|
64
|
+
!this.snapshot.error?.retryable ||
|
|
65
|
+
Date.now() >= this.recoverUntil)
|
|
66
|
+
break;
|
|
67
|
+
this.update({ status: 'reconnecting' });
|
|
68
|
+
await new Promise((resolve) => {
|
|
69
|
+
const timer = setTimeout(() => {
|
|
70
|
+
this.cancelRetry = null;
|
|
71
|
+
resolve();
|
|
72
|
+
}, 1000);
|
|
73
|
+
this.cancelRetry = () => {
|
|
74
|
+
clearTimeout(timer);
|
|
75
|
+
this.cancelRetry = null;
|
|
76
|
+
resolve();
|
|
77
|
+
};
|
|
78
|
+
});
|
|
79
|
+
} while (generation === this.generation && !this.disposed);
|
|
80
|
+
})().finally(() => {
|
|
81
|
+
if (this.operation === operation)
|
|
82
|
+
this.operation = null;
|
|
83
|
+
});
|
|
84
|
+
this.operation = operation;
|
|
85
|
+
return operation;
|
|
86
|
+
}
|
|
87
|
+
async join(generation) {
|
|
88
|
+
this.update({
|
|
89
|
+
status: this.token ? 'reconnecting' : 'connecting',
|
|
90
|
+
error: null,
|
|
91
|
+
});
|
|
92
|
+
try {
|
|
93
|
+
let room = null;
|
|
94
|
+
if (!this.token) {
|
|
95
|
+
try {
|
|
96
|
+
const raw = this.storage?.getItem(this.storageKey);
|
|
97
|
+
const saved = raw ? JSON.parse(raw) : null;
|
|
98
|
+
if (saved &&
|
|
99
|
+
typeof saved.token === 'string' &&
|
|
100
|
+
typeof saved.endpoint === 'string' &&
|
|
101
|
+
/^wss?:\/\//.test(saved.endpoint) &&
|
|
102
|
+
saved.expiresAt > Date.now()) {
|
|
103
|
+
this.token = saved.token;
|
|
104
|
+
this.endpoint = saved.endpoint;
|
|
105
|
+
this.recoverUntil =
|
|
106
|
+
Date.now() + (this.launch.recoveryGraceMs ?? RECOVERY_GRACE_MS);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
this.update({ storageAvailable: false });
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
if (this.token && this.endpoint) {
|
|
114
|
+
try {
|
|
115
|
+
room = await this.makeClient(this.endpoint).reconnect(this.token, MultiplayerState);
|
|
116
|
+
}
|
|
117
|
+
catch (error) {
|
|
118
|
+
if (!normalizeError(error).retryable)
|
|
119
|
+
this.clearToken();
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
if (generation !== this.generation) {
|
|
123
|
+
await room?.leave();
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
if (!room) {
|
|
127
|
+
const result = await this.host.requestMultiplayerLaunch();
|
|
128
|
+
if (generation !== this.generation)
|
|
129
|
+
return;
|
|
130
|
+
if (!isLaunchOutcome(result))
|
|
131
|
+
throw new Error('Invalid launch response');
|
|
132
|
+
const outcome = result;
|
|
133
|
+
if (outcome.status !== 'reserved') {
|
|
134
|
+
this.update({ status: 'failed', error: outcome.error });
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
if ([
|
|
138
|
+
'roundId',
|
|
139
|
+
'attemptId',
|
|
140
|
+
'seatId',
|
|
141
|
+
'multiplayerSessionId',
|
|
142
|
+
'hostInstanceId',
|
|
143
|
+
].some((k) => outcome.launch[k] !==
|
|
144
|
+
this.launch[k]))
|
|
145
|
+
throw new Error('Stale launch response');
|
|
146
|
+
this.endpoint = outcome.wsEndpoint;
|
|
147
|
+
room = await this.makeClient(outcome.wsEndpoint).consumeSeatReservation(outcome.reservation, MultiplayerState);
|
|
148
|
+
}
|
|
149
|
+
if (generation !== this.generation) {
|
|
150
|
+
await room.leave();
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
this.room = room;
|
|
154
|
+
// Recovery is owned here, not by a second SDK reconnect loop.
|
|
155
|
+
room.reconnection.enabled = false;
|
|
156
|
+
this.clockNow = attachServerClock(room);
|
|
157
|
+
this.remember(room);
|
|
158
|
+
const sync = () => {
|
|
159
|
+
if (generation !== this.generation)
|
|
160
|
+
return;
|
|
161
|
+
const phase = room.state?.roundPhase;
|
|
162
|
+
const status = phase === 'playing'
|
|
163
|
+
? 'playing'
|
|
164
|
+
: phase === 'completed'
|
|
165
|
+
? 'completed'
|
|
166
|
+
: phase === 'finishing'
|
|
167
|
+
? 'finishing'
|
|
168
|
+
: 'loading';
|
|
169
|
+
this.update({ state: room.state, status });
|
|
170
|
+
if (status === 'completed')
|
|
171
|
+
this.clearToken();
|
|
172
|
+
};
|
|
173
|
+
room.onStateChange(sync);
|
|
174
|
+
this.unsubscribers.push(() => room.onStateChange.remove(sync));
|
|
175
|
+
this.unsubscribers.push(room.onMessage('mp:status', (message) => {
|
|
176
|
+
if (message.phase === 'finishing')
|
|
177
|
+
this.update({ status: 'finishing' });
|
|
178
|
+
if (message.phase === 'completed') {
|
|
179
|
+
this.clearToken();
|
|
180
|
+
this.update({ status: 'completed' });
|
|
181
|
+
}
|
|
182
|
+
}));
|
|
183
|
+
this.unsubscribers.push(room.onMessage('error', (error) => this.update({ error: normalizeError(error) })));
|
|
184
|
+
const onLeave = (code) => {
|
|
185
|
+
this.room = null;
|
|
186
|
+
this.detach();
|
|
187
|
+
if (generation !== this.generation || this.disposed)
|
|
188
|
+
return;
|
|
189
|
+
if (this.snapshot.status === 'completed')
|
|
190
|
+
return;
|
|
191
|
+
if (code >= 4200 || code === 1000) {
|
|
192
|
+
this.clearToken();
|
|
193
|
+
this.update({ status: 'failed', error: normalizeError({ code }) });
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
this.recoverUntil =
|
|
197
|
+
Date.now() + (this.launch.recoveryGraceMs ?? RECOVERY_GRACE_MS);
|
|
198
|
+
this.update({ status: 'reconnecting' });
|
|
199
|
+
queueMicrotask(() => {
|
|
200
|
+
void this.connect();
|
|
201
|
+
});
|
|
202
|
+
};
|
|
203
|
+
room.onLeave(onLeave);
|
|
204
|
+
this.unsubscribers.push(() => room.onLeave.remove(onLeave));
|
|
205
|
+
sync();
|
|
206
|
+
room.send('mp:ready');
|
|
207
|
+
}
|
|
208
|
+
catch (error) {
|
|
209
|
+
if (generation === this.generation)
|
|
210
|
+
this.update({ status: 'failed', error: normalizeError(error) });
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
send(type, payload) {
|
|
214
|
+
if (this.snapshot.status !== 'playing' ||
|
|
215
|
+
!this.room ||
|
|
216
|
+
type.startsWith('mp:') ||
|
|
217
|
+
type.startsWith('clock:'))
|
|
218
|
+
return false;
|
|
219
|
+
this.room.send('mp:action', { type, payload });
|
|
220
|
+
return true;
|
|
221
|
+
}
|
|
222
|
+
async leave() {
|
|
223
|
+
++this.generation;
|
|
224
|
+
this.disposed = true;
|
|
225
|
+
this.cancelRetry?.();
|
|
226
|
+
this.clearToken();
|
|
227
|
+
const room = this.room;
|
|
228
|
+
this.room = null;
|
|
229
|
+
// Clock cleanup receives onLeave before removing the adapter's own listeners.
|
|
230
|
+
if (room)
|
|
231
|
+
await room.leave();
|
|
232
|
+
this.detach();
|
|
233
|
+
this.update({ status: 'disconnected', state: null });
|
|
234
|
+
this.listeners.clear();
|
|
235
|
+
}
|
|
236
|
+
detach() {
|
|
237
|
+
for (const off of this.unsubscribers.splice(0))
|
|
238
|
+
off();
|
|
239
|
+
}
|
|
240
|
+
remember(room) {
|
|
241
|
+
this.token = room.reconnectionToken;
|
|
242
|
+
try {
|
|
243
|
+
this.storage?.setItem(this.storageKey, JSON.stringify({
|
|
244
|
+
token: this.token,
|
|
245
|
+
endpoint: this.endpoint,
|
|
246
|
+
expiresAt: Date.now() + 86400000,
|
|
247
|
+
}));
|
|
248
|
+
}
|
|
249
|
+
catch {
|
|
250
|
+
this.update({ storageAvailable: false });
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
clearToken() {
|
|
254
|
+
this.token = null;
|
|
255
|
+
try {
|
|
256
|
+
this.storage?.removeItem(this.storageKey);
|
|
257
|
+
}
|
|
258
|
+
catch {
|
|
259
|
+
this.update({ storageAvailable: false });
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
update(change) {
|
|
263
|
+
const previousStatus = this.snapshot.status;
|
|
264
|
+
this.snapshot = { ...this.snapshot, ...change };
|
|
265
|
+
if (this.snapshot.status !== previousStatus) {
|
|
266
|
+
const status = this.snapshot.status;
|
|
267
|
+
try {
|
|
268
|
+
this.host.setLoading?.(status === 'connecting' || status === 'finishing'
|
|
269
|
+
? 'loading'
|
|
270
|
+
: status === 'loading'
|
|
271
|
+
? 'waiting-for-players'
|
|
272
|
+
: status === 'reconnecting'
|
|
273
|
+
? 'reconnecting'
|
|
274
|
+
: status === 'failed'
|
|
275
|
+
? 'failed'
|
|
276
|
+
: null, this.launch);
|
|
277
|
+
}
|
|
278
|
+
catch {
|
|
279
|
+
// Optional host presentation cannot interrupt the socket lifecycle.
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
for (const listener of this.listeners)
|
|
283
|
+
listener(this.snapshot);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
//# sourceMappingURL=multiplayer-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"multiplayer-client.js","sourceRoot":"","sources":["../../vendor/multiplayer-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAa,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,EACL,eAAe,EACf,cAAc,EACd,iBAAiB,GAIlB,MAAM,wBAAwB,CAAC;AA6BhC,mGAAmG;AACnG,MAAM,OAAO,iBAAiB;IAmB5B,YACmB,IAAgB,EACxB,MAAuB,EACf,OAAsB,EACtB,aAAa,CAAC,QAAgB,EAAE,EAAE,CAAC,IAAI,MAAM,CAAC,QAAQ,CAAC;QAHvD,SAAI,GAAJ,IAA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SeatType, SessionPhase } from '#multiplayer-contracts';
|
|
2
|
+
/** Host-controlled lobby operations. No account, session or engine overrides. */
|
|
3
|
+
export type MultiplayerSessionRequest = {
|
|
4
|
+
operation: 'create';
|
|
5
|
+
type: SeatType;
|
|
6
|
+
passcode?: string;
|
|
7
|
+
} | {
|
|
8
|
+
operation: 'join';
|
|
9
|
+
roomCode: string;
|
|
10
|
+
displayName: string;
|
|
11
|
+
type: SeatType;
|
|
12
|
+
passcode?: string;
|
|
13
|
+
} | {
|
|
14
|
+
operation: 'ready';
|
|
15
|
+
ready: boolean;
|
|
16
|
+
} | {
|
|
17
|
+
operation: 'remove-bot';
|
|
18
|
+
seatId: string;
|
|
19
|
+
} | {
|
|
20
|
+
operation: 'add-bot';
|
|
21
|
+
level?: BotLevel;
|
|
22
|
+
} | {
|
|
23
|
+
operation: 'read' | 'start' | 'leave' | 'rematch';
|
|
24
|
+
};
|
|
25
|
+
export interface MultiplayerSessionError {
|
|
26
|
+
code: string;
|
|
27
|
+
message: string;
|
|
28
|
+
retryable: boolean;
|
|
29
|
+
}
|
|
30
|
+
export interface MultiplayerLobbySession {
|
|
31
|
+
multiplayerSessionId: string;
|
|
32
|
+
gameSlug: string;
|
|
33
|
+
roomCode: string;
|
|
34
|
+
invitationUrl?: string;
|
|
35
|
+
spectatorInvitationUrl?: string;
|
|
36
|
+
phase: SessionPhase;
|
|
37
|
+
revision: number;
|
|
38
|
+
hostSeatId: string;
|
|
39
|
+
ownSeatId: string;
|
|
40
|
+
rematchAllowed: boolean;
|
|
41
|
+
playerPolicy: {
|
|
42
|
+
minPlayers: number;
|
|
43
|
+
maxPlayers: number;
|
|
44
|
+
minHumanPlayers: number;
|
|
45
|
+
maxBots: number;
|
|
46
|
+
maxSpectators: number;
|
|
47
|
+
};
|
|
48
|
+
seats: {
|
|
49
|
+
seatId: string;
|
|
50
|
+
displayName: string;
|
|
51
|
+
kind: ParticipantKind;
|
|
52
|
+
/** Present on bot seats only. */
|
|
53
|
+
botLevel?: BotLevel;
|
|
54
|
+
type: SeatType;
|
|
55
|
+
ready: boolean;
|
|
56
|
+
online: boolean;
|
|
57
|
+
}[];
|
|
58
|
+
round: {
|
|
59
|
+
roundId: string;
|
|
60
|
+
phase: string;
|
|
61
|
+
reason: string | null;
|
|
62
|
+
} | null;
|
|
63
|
+
}
|
|
64
|
+
export interface MultiplayerLobbyState {
|
|
65
|
+
session: MultiplayerLobbySession | null;
|
|
66
|
+
busy: boolean;
|
|
67
|
+
error: MultiplayerSessionError | null;
|
|
68
|
+
disconnected: boolean;
|
|
69
|
+
}
|
|
70
|
+
export type MultiplayerSessionResult = {
|
|
71
|
+
success: true;
|
|
72
|
+
data: MultiplayerLobbyState;
|
|
73
|
+
} | {
|
|
74
|
+
success: false;
|
|
75
|
+
error: MultiplayerSessionError;
|
|
76
|
+
};
|
|
77
|
+
export interface MultiplayerEntry {
|
|
78
|
+
action: 'create' | 'join';
|
|
79
|
+
roomCode?: string;
|
|
80
|
+
type?: SeatType;
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=multiplayer-session.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"multiplayer-session.d.ts","sourceRoot":"","sources":["../../vendor/multiplayer-session.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,QAAQ,EACR,eAAe,EACf,QAAQ,EACR,YAAY,EACb,MAAM,wBAAwB,CAAC;AAChC,iFAAiF;AACjF,MAAM,MAAM,yBAAyB,GACjC;IAAE,SAAS,EAAE,QAAQ,CAAC;IAAC,IAAI,EAAE,QAAQ,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,GAC1D;IACE,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,QAAQ,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,GACD;IAAE,SAAS,EAAE,OAAO,C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AAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,GAAG,IAAI,CAAC;CACzE;AACD,MAAM,WAAW,qBAAqB;IACpC,OAAO,EAAE,uBAAuB,GAAG,IAAI,CAAC;IACxC,IAAI,EAAE,OAAO,CAAC;IACd,KAAK,EAAE,uBAAuB,GAAG,IAAI,CAAC;IACtC,YAAY,EAAE,OAAO,CAAC;CACvB;AACD,MAAM,MAAM,wBAAwB,GAChC;IAAE,OAAO,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,qBAAqB,CAAA;CAAE,GAC9C;IAAE,OAAO,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,uBAAuB,CAAA;CAAE,CAAC;AACvD,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,QAAQ,GAAG,MAAM,CAAC;IAC1B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,QAAQ,CAAC;CACjB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"multiplayer-session.js","sourceRoot":"","sources":["../../vendor/multiplayer-session.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canonical question shape used everywhere in the gamehub stack:
|
|
3
|
+
*
|
|
4
|
+
* - Browser-side: returned by `sdk.getQuestions()` (the SDK normalizes
|
|
5
|
+
* `answer` to a string at the API boundary so consumers never see a
|
|
6
|
+
* numeric value).
|
|
7
|
+
* - Server-side: passed into UGC bundles via `CreateOptions.questions`
|
|
8
|
+
* when a `questionPackId` was supplied at room creation.
|
|
9
|
+
*
|
|
10
|
+
* Mirrors the gamehub Mongoose `Question` model
|
|
11
|
+
* (`packages/gamehub/src/models/Question.ts`), minus persistence-only
|
|
12
|
+
* fields (`_id`, `gameId`, `status`, timestamps).
|
|
13
|
+
*
|
|
14
|
+
* Single source of truth — older `QuestionData` (colyseus-schemas) and
|
|
15
|
+
* `ServerQuestion` (gamehub-sdk/server) types have been removed; any
|
|
16
|
+
* consumer that needs the shape imports `Question` from here (or from
|
|
17
|
+
* one of the re-exports under `@ksaa-nlp/gamehub-sdk` / `/server`).
|
|
18
|
+
*/
|
|
19
|
+
export type QuestionDifficulty = 'easy' | 'medium' | 'hard';
|
|
20
|
+
export interface Question {
|
|
21
|
+
id: string;
|
|
22
|
+
/** Free-form classification (e.g. 'mcq', 'true-false'). */
|
|
23
|
+
type?: string;
|
|
24
|
+
prompt: string;
|
|
25
|
+
choices: string[];
|
|
26
|
+
/** Always a string. The browser SDK coerces numeric API responses on
|
|
27
|
+
* receipt; server-side loaders do the same. */
|
|
28
|
+
answer: string;
|
|
29
|
+
explanation?: string;
|
|
30
|
+
difficulty?: QuestionDifficulty;
|
|
31
|
+
category?: string;
|
|
32
|
+
/** Defaults to 0 in scoring code when omitted. */
|
|
33
|
+
points?: number;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=question.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"question.d.ts","sourceRoot":"","sources":["../../vendor/question.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,MAAM,MAAM,kBAAkB,GAAG,MAAM,GAAG,QAAQ,GAAG,MAAM,CAAC;AAE5D,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,2DAA2D;IAC3D,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB;oDACgD;IAChD,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,kBAAkB,CAAC;IAChC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,kDAAkD;IAClD,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canonical question shape used everywhere in the gamehub stack:
|
|
3
|
+
*
|
|
4
|
+
* - Browser-side: returned by `sdk.getQuestions()` (the SDK normalizes
|
|
5
|
+
* `answer` to a string at the API boundary so consumers never see a
|
|
6
|
+
* numeric value).
|
|
7
|
+
* - Server-side: passed into UGC bundles via `CreateOptions.questions`
|
|
8
|
+
* when a `questionPackId` was supplied at room creation.
|
|
9
|
+
*
|
|
10
|
+
* Mirrors the gamehub Mongoose `Question` model
|
|
11
|
+
* (`packages/gamehub/src/models/Question.ts`), minus persistence-only
|
|
12
|
+
* fields (`_id`, `gameId`, `status`, timestamps).
|
|
13
|
+
*
|
|
14
|
+
* Single source of truth — older `QuestionData` (colyseus-schemas) and
|
|
15
|
+
* `ServerQuestion` (gamehub-sdk/server) types have been removed; any
|
|
16
|
+
* consumer that needs the shape imports `Question` from here (or from
|
|
17
|
+
* one of the re-exports under `@ksaa-nlp/gamehub-sdk` / `/server`).
|
|
18
|
+
*/
|
|
19
|
+
export {};
|
|
20
|
+
//# sourceMappingURL=question.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"question.js","sourceRoot":"","sources":["../../vendor/question.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG"}
|