@ksaa-nlp/gamehub-sdk 4.3.0 → 5.0.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.
Files changed (59) hide show
  1. package/README.md +75 -46
  2. package/SPEC.md +130 -59
  3. package/dist/gamehub-sdk.js +15 -30
  4. package/dist/gamehub-sdk.js.map +3 -3
  5. package/dist/src/bot-driver.d.ts +54 -0
  6. package/dist/src/bot-driver.d.ts.map +1 -0
  7. package/dist/src/bot-driver.js +104 -0
  8. package/dist/src/bot-driver.js.map +1 -0
  9. package/dist/src/bridge.d.ts.map +1 -1
  10. package/dist/src/bridge.js +0 -35
  11. package/dist/src/bridge.js.map +1 -1
  12. package/dist/src/constants.d.ts +1 -1
  13. package/dist/src/constants.js +1 -1
  14. package/dist/src/init.js +7 -7
  15. package/dist/src/init.js.map +1 -1
  16. package/dist/src/main.d.ts +1 -1
  17. package/dist/src/main.d.ts.map +1 -1
  18. package/dist/src/main.js +3 -4
  19. package/dist/src/main.js.map +1 -1
  20. package/dist/src/multiplayer-client.d.ts +50 -0
  21. package/dist/src/multiplayer-client.d.ts.map +1 -0
  22. package/dist/src/multiplayer-client.js +268 -0
  23. package/dist/src/multiplayer-client.js.map +1 -0
  24. package/dist/src/multiplayer-entry.d.ts +9 -0
  25. package/dist/src/multiplayer-entry.d.ts.map +1 -0
  26. package/dist/src/multiplayer-entry.js +9 -0
  27. package/dist/src/multiplayer-entry.js.map +1 -0
  28. package/dist/src/multiplayer-session.d.ts.map +1 -1
  29. package/dist/src/multiplayer-session.js +5 -1
  30. package/dist/src/multiplayer-session.js.map +1 -1
  31. package/dist/src/multiplayer.d.ts.map +1 -1
  32. package/dist/src/multiplayer.js +2 -1
  33. package/dist/src/multiplayer.js.map +1 -1
  34. package/dist/src/server-entry.d.ts +10 -4
  35. package/dist/src/server-entry.d.ts.map +1 -1
  36. package/dist/src/server-entry.js +7 -5
  37. package/dist/src/server-entry.js.map +1 -1
  38. package/dist/src/session.d.ts.map +1 -1
  39. package/dist/src/session.js +3 -2
  40. package/dist/src/session.js.map +1 -1
  41. package/dist/src/state.d.ts +1 -2
  42. package/dist/src/state.d.ts.map +1 -1
  43. package/dist/src/state.js +0 -1
  44. package/dist/src/state.js.map +1 -1
  45. package/dist/types/bootstrap.d.ts +6 -45
  46. package/dist/types/bootstrap.d.ts.map +1 -1
  47. package/dist/types/multiplayer-session.d.ts +13 -7
  48. package/dist/types/multiplayer-session.d.ts.map +1 -1
  49. package/dist/vendor/colyseus-schemas/clock.d.ts +15 -0
  50. package/dist/vendor/colyseus-schemas/clock.js +67 -0
  51. package/dist/vendor/colyseus-schemas/common.d.ts +17 -0
  52. package/dist/vendor/colyseus-schemas/common.js +12 -0
  53. package/dist/vendor/colyseus-schemas/multiplayer.d.ts +8 -0
  54. package/dist/vendor/colyseus-schemas/multiplayer.js +26 -0
  55. package/dist/vendor/colyseus-schemas/ugc.d.ts +53 -0
  56. package/dist/vendor/colyseus-schemas/ugc.js +124 -0
  57. package/dist/vendor/gamehub-multiplayer-contracts/index.d.ts +176 -0
  58. package/dist/vendor/gamehub-multiplayer-contracts/index.js +287 -0
  59. package/package.json +33 -3
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  (() => {
3
3
  // src/constants.ts
4
- var SDK_VERSION = "4.3.0";
4
+ var SDK_VERSION = "5.0.0";
5
5
  var MESSAGE_PREFIX = "GAMEHUB_SDK";
6
6
  var PARENT_REQUEST_TIMEOUT_MS = 2e3;
7
7
  var HOST_API_TIMEOUT_MS = 15e3;
@@ -32,7 +32,6 @@
32
32
  bootstrapTeamOneName: null,
33
33
  bootstrapTeamTwoName: null,
34
34
  bootstrapProfileId: null,
35
- bootstrapMultiplayer: null,
36
35
  bootstrapReceived: false,
37
36
  isInitialized: false,
38
37
  isAutoInitializing: false,
@@ -46,6 +45,12 @@
46
45
  matchContextPromise: null
47
46
  };
48
47
 
48
+ // dist/vendor/gamehub-multiplayer-contracts/index.js
49
+ var MULTIPLAYER_CAPABILITY = "multiplayer.launch.v2";
50
+ var MULTIPLAYER_LOBBY_CAPABILITY = "multiplayer.lobby.v2";
51
+ var BOT_LEVELS = ["easy", "medium", "hard"];
52
+ var isBotLevel = (value) => BOT_LEVELS.includes(value);
53
+
49
54
  // src/multiplayer-session.ts
50
55
  var listeners = /* @__PURE__ */ new Set();
51
56
  var empty = {
@@ -82,7 +87,7 @@
82
87
  ].every((n) => Number.isSafeInteger(n) && n >= 0 && n <= 256) || p.minPlayers < 1 || p.minHumanPlayers < 1 || p.maxPlayers < p.minPlayers || p.minHumanPlayers > p.maxPlayers || p.maxBots > p.maxPlayers - p.minHumanPlayers || p.maxSpectators > 16)
83
88
  return null;
84
89
  if (!s.seats.every(
85
- (seat) => seat && id(seat.seatId) && typeof seat.displayName === "string" && seat.displayName.length <= 80 && ["human", "bot"].includes(seat.kind) && ["player", "spectator"].includes(seat.type) && typeof seat.ready === "boolean" && typeof seat.online === "boolean"
90
+ (seat) => seat && id(seat.seatId) && typeof seat.displayName === "string" && seat.displayName.length <= 80 && ["human", "bot"].includes(seat.kind) && (seat.botLevel === void 0 || seat.kind === "bot" && isBotLevel(seat.botLevel)) && ["player", "spectator"].includes(seat.type) && typeof seat.ready === "boolean" && typeof seat.online === "boolean"
86
91
  ))
87
92
  return null;
88
93
  if (s.round !== null && (!s.round || !id(s.round.roundId) || ![
@@ -122,6 +127,7 @@
122
127
  seatId: seat.seatId,
123
128
  displayName: seat.displayName,
124
129
  kind: seat.kind,
130
+ ...seat.botLevel ? { botLevel: seat.botLevel } : {},
125
131
  type: seat.type,
126
132
  ready: seat.ready,
127
133
  online: seat.online
@@ -160,7 +166,7 @@
160
166
  };
161
167
  }
162
168
  async function requestMultiplayerSession(request) {
163
- if (!state.bootstrapCapabilities.includes("multiplayer.lobby.v2"))
169
+ if (!state.bootstrapCapabilities.includes(MULTIPLAYER_LOBBY_CAPABILITY))
164
170
  return {
165
171
  success: false,
166
172
  error: {
@@ -398,21 +404,6 @@
398
404
  const trimmed = value.trim();
399
405
  return trimmed ? trimmed : null;
400
406
  }
401
- function parseMultiplayer(value) {
402
- if (value === null) return null;
403
- if (!value || typeof value !== "object") return void 0;
404
- const { reservation, wsEndpoint, roomCode, role, connectionScope } = value;
405
- if (!reservation || typeof reservation !== "object" || typeof reservation.name !== "string" || typeof reservation.sessionId !== "string" || typeof reservation.roomId !== "string" || typeof wsEndpoint !== "string") {
406
- return void 0;
407
- }
408
- return {
409
- reservation,
410
- wsEndpoint: wsEndpoint.trim(),
411
- ...typeof roomCode === "string" && /^[A-Za-z0-9]{4,12}$/.test(roomCode) ? { roomCode: roomCode.toUpperCase() } : {},
412
- ...role === "host" || role === "player" || role === "spectator" ? { role } : {},
413
- ...typeof connectionScope === "string" && connectionScope.length > 0 && connectionScope.length <= 160 ? { connectionScope } : {}
414
- };
415
- }
416
407
  function mergeBootstrapConfig(config = {}) {
417
408
  if (!config || typeof config !== "object" || Array.isArray(config)) return;
418
409
  mergeSettings(config.settings);
@@ -474,10 +465,6 @@
474
465
  (k) => typeof launch[k] === "string" && /^[a-zA-Z0-9_-]{1,160}$/.test(String(launch[k]))
475
466
  ) && typeof launch.gameUrl === "string" && launch.gameUrl.startsWith("/games/") && launch.gameUrl.length < 2048 && ["server", "unverified"].includes(launch.scoreAuthority))
476
467
  state.bootstrapLaunch = { ...launch };
477
- const mp = parseMultiplayer(config.multiplayer);
478
- if (mp !== void 0) {
479
- state.bootstrapMultiplayer = mp;
480
- }
481
468
  }
482
469
  function snapshotBootstrap() {
483
470
  return {
@@ -496,7 +483,6 @@
496
483
  teamOneName: state.bootstrapTeamOneName,
497
484
  teamTwoName: state.bootstrapTeamTwoName,
498
485
  profileId: state.bootstrapProfileId,
499
- multiplayer: state.bootstrapMultiplayer,
500
486
  multiplayerLaunch: state.bootstrapLaunch,
501
487
  capabilities: state.bootstrapCapabilities
502
488
  };
@@ -838,7 +824,7 @@
838
824
  }
839
825
  }
840
826
  async function startSession() {
841
- if (state.bootstrapLaunch || state.bootstrapCapabilities.includes("multiplayer.lobby.v2"))
827
+ if (state.bootstrapLaunch || state.bootstrapCapabilities.includes(MULTIPLAYER_LOBBY_CAPABILITY))
842
828
  return { success: false, error: "Multiplayer rounds own their results" };
843
829
  if (state.sessionToken) return { success: true, token: state.sessionToken };
844
830
  if (state.sessionStartPromise) return await state.sessionStartPromise;
@@ -933,7 +919,7 @@
933
919
  }
934
920
  async function submitScore(score, meta = {}) {
935
921
  await ensureInitialized();
936
- if (state.bootstrapLaunch || state.bootstrapCapabilities.includes("multiplayer.lobby.v2"))
922
+ if (state.bootstrapLaunch || state.bootstrapCapabilities.includes(MULTIPLAYER_LOBBY_CAPABILITY))
937
923
  return failedResult(
938
924
  "FORBIDDEN",
939
925
  "Multiplayer rounds own their results",
@@ -1159,7 +1145,7 @@
1159
1145
  state.isAutoInitializing = false;
1160
1146
  return false;
1161
1147
  }
1162
- if (!state.authToken && !state.bootstrapLaunch && !state.bootstrapCapabilities.includes("multiplayer.lobby.v2")) {
1148
+ if (!state.authToken && !state.bootstrapLaunch && !state.bootstrapCapabilities.includes(MULTIPLAYER_LOBBY_CAPABILITY)) {
1163
1149
  state.authToken = await getAuthTokenFromParent();
1164
1150
  }
1165
1151
  state.isInitialized = true;
@@ -1202,7 +1188,7 @@
1202
1188
  state.bootstrapReceived = true;
1203
1189
  mergeBootstrapConfig(data.payload);
1204
1190
  }
1205
- if (type === MESSAGE_PREFIX + "_MULTIPLAYER_SESSION" && state.bootstrapCapabilities.includes("multiplayer.lobby.v2"))
1191
+ if (type === MESSAGE_PREFIX + "_MULTIPLAYER_SESSION" && state.bootstrapCapabilities.includes(MULTIPLAYER_LOBBY_CAPABILITY))
1206
1192
  acceptLobbyState(data.payload);
1207
1193
  if (type === MESSAGE_PREFIX + "_SET_AUTH") {
1208
1194
  state.authToken = data.token;
@@ -1225,7 +1211,7 @@
1225
1211
  // src/multiplayer.ts
1226
1212
  var pending = null;
1227
1213
  function requestMultiplayerLaunch() {
1228
- if (!state.bootstrapLaunch || !state.bootstrapCapabilities.includes("multiplayer.launch.v2"))
1214
+ if (!state.bootstrapLaunch || !state.bootstrapCapabilities.includes(MULTIPLAYER_CAPABILITY))
1229
1215
  return Promise.resolve({
1230
1216
  status: "terminal",
1231
1217
  error: {
@@ -1418,7 +1404,6 @@
1418
1404
  teamOneName: state.bootstrapTeamOneName,
1419
1405
  teamTwoName: state.bootstrapTeamTwoName,
1420
1406
  profileId: state.bootstrapProfileId,
1421
- multiplayer: state.bootstrapMultiplayer,
1422
1407
  multiplayerLaunch: state.bootstrapLaunch,
1423
1408
  capabilities: [...state.bootstrapCapabilities],
1424
1409
  isBootstrapped: state.bootstrapReceived