connectbase-client 0.8.1 → 0.9.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/connect-base.umd.js +3 -3
- package/dist/index.d.mts +149 -3
- package/dist/index.d.ts +149 -3
- package/dist/index.js +177 -0
- package/dist/index.mjs +177 -0
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -6222,6 +6222,183 @@ var GameAPI = class {
|
|
|
6222
6222
|
expiresAt: inv.expires_at
|
|
6223
6223
|
}));
|
|
6224
6224
|
}
|
|
6225
|
+
// --- Party API ---
|
|
6226
|
+
async createParty(playerId, maxSize) {
|
|
6227
|
+
const id = this.appId || "";
|
|
6228
|
+
const response = await fetch(`${this.gameServerUrl}/v1/game/${id}/parties`, {
|
|
6229
|
+
method: "POST",
|
|
6230
|
+
headers: { ...this.getHeaders(), "Content-Type": "application/json" },
|
|
6231
|
+
body: JSON.stringify({ player_id: playerId, max_size: maxSize || 4 })
|
|
6232
|
+
});
|
|
6233
|
+
if (!response.ok) throw new Error(`Failed to create party: ${response.statusText}`);
|
|
6234
|
+
return response.json();
|
|
6235
|
+
}
|
|
6236
|
+
async joinParty(partyId, playerId) {
|
|
6237
|
+
const id = this.appId || "";
|
|
6238
|
+
const response = await fetch(`${this.gameServerUrl}/v1/game/${id}/parties/${partyId}/join`, {
|
|
6239
|
+
method: "POST",
|
|
6240
|
+
headers: { ...this.getHeaders(), "Content-Type": "application/json" },
|
|
6241
|
+
body: JSON.stringify({ player_id: playerId })
|
|
6242
|
+
});
|
|
6243
|
+
if (!response.ok) throw new Error(`Failed to join party: ${response.statusText}`);
|
|
6244
|
+
return response.json();
|
|
6245
|
+
}
|
|
6246
|
+
async leaveParty(partyId, playerId) {
|
|
6247
|
+
const id = this.appId || "";
|
|
6248
|
+
const response = await fetch(`${this.gameServerUrl}/v1/game/${id}/parties/${partyId}/leave`, {
|
|
6249
|
+
method: "POST",
|
|
6250
|
+
headers: { ...this.getHeaders(), "Content-Type": "application/json" },
|
|
6251
|
+
body: JSON.stringify({ player_id: playerId })
|
|
6252
|
+
});
|
|
6253
|
+
if (!response.ok) throw new Error(`Failed to leave party: ${response.statusText}`);
|
|
6254
|
+
}
|
|
6255
|
+
async kickFromParty(partyId, playerId) {
|
|
6256
|
+
const id = this.appId || "";
|
|
6257
|
+
const response = await fetch(`${this.gameServerUrl}/v1/game/${id}/parties/${partyId}/kick/${playerId}`, {
|
|
6258
|
+
method: "POST",
|
|
6259
|
+
headers: this.getHeaders()
|
|
6260
|
+
});
|
|
6261
|
+
if (!response.ok) throw new Error(`Failed to kick from party: ${response.statusText}`);
|
|
6262
|
+
}
|
|
6263
|
+
async inviteToParty(partyId, inviterId, inviteeId) {
|
|
6264
|
+
const id = this.appId || "";
|
|
6265
|
+
const response = await fetch(`${this.gameServerUrl}/v1/game/${id}/parties/${partyId}/invite/${inviteeId}`, {
|
|
6266
|
+
method: "POST",
|
|
6267
|
+
headers: { ...this.getHeaders(), "Content-Type": "application/json" },
|
|
6268
|
+
body: JSON.stringify({ inviter_id: inviterId })
|
|
6269
|
+
});
|
|
6270
|
+
if (!response.ok) throw new Error(`Failed to invite to party: ${response.statusText}`);
|
|
6271
|
+
return response.json();
|
|
6272
|
+
}
|
|
6273
|
+
async sendPartyChat(partyId, playerId, message) {
|
|
6274
|
+
const id = this.appId || "";
|
|
6275
|
+
const response = await fetch(`${this.gameServerUrl}/v1/game/${id}/parties/${partyId}/chat`, {
|
|
6276
|
+
method: "POST",
|
|
6277
|
+
headers: { ...this.getHeaders(), "Content-Type": "application/json" },
|
|
6278
|
+
body: JSON.stringify({ player_id: playerId, message })
|
|
6279
|
+
});
|
|
6280
|
+
if (!response.ok) throw new Error(`Failed to send party chat: ${response.statusText}`);
|
|
6281
|
+
}
|
|
6282
|
+
// --- Spectator API ---
|
|
6283
|
+
async joinSpectator(roomId, playerId) {
|
|
6284
|
+
const id = this.appId || "";
|
|
6285
|
+
const response = await fetch(`${this.gameServerUrl}/v1/game/${id}/rooms/${roomId}/spectate`, {
|
|
6286
|
+
method: "POST",
|
|
6287
|
+
headers: { ...this.getHeaders(), "Content-Type": "application/json" },
|
|
6288
|
+
body: JSON.stringify({ player_id: playerId })
|
|
6289
|
+
});
|
|
6290
|
+
if (!response.ok) throw new Error(`Failed to join spectator: ${response.statusText}`);
|
|
6291
|
+
return response.json();
|
|
6292
|
+
}
|
|
6293
|
+
async leaveSpectator(roomId, spectatorId) {
|
|
6294
|
+
const id = this.appId || "";
|
|
6295
|
+
const response = await fetch(`${this.gameServerUrl}/v1/game/${id}/rooms/${roomId}/spectate/stop`, {
|
|
6296
|
+
method: "POST",
|
|
6297
|
+
headers: { ...this.getHeaders(), "Content-Type": "application/json" },
|
|
6298
|
+
body: JSON.stringify({ spectator_id: spectatorId })
|
|
6299
|
+
});
|
|
6300
|
+
if (!response.ok) throw new Error(`Failed to leave spectator: ${response.statusText}`);
|
|
6301
|
+
}
|
|
6302
|
+
async getSpectators(roomId) {
|
|
6303
|
+
const id = this.appId || "";
|
|
6304
|
+
const response = await fetch(`${this.gameServerUrl}/v1/game/${id}/rooms/${roomId}/spectators`, {
|
|
6305
|
+
headers: this.getHeaders()
|
|
6306
|
+
});
|
|
6307
|
+
if (!response.ok) throw new Error(`Failed to get spectators: ${response.statusText}`);
|
|
6308
|
+
const data = await response.json();
|
|
6309
|
+
return data.spectators || [];
|
|
6310
|
+
}
|
|
6311
|
+
// --- Ranking/Leaderboard API ---
|
|
6312
|
+
async getLeaderboard(top) {
|
|
6313
|
+
const id = this.appId || "";
|
|
6314
|
+
const limit = top || 100;
|
|
6315
|
+
const response = await fetch(`${this.gameServerUrl}/v1/game/${id}/ranking/leaderboard/top?limit=${limit}`, {
|
|
6316
|
+
headers: this.getHeaders()
|
|
6317
|
+
});
|
|
6318
|
+
if (!response.ok) throw new Error(`Failed to get leaderboard: ${response.statusText}`);
|
|
6319
|
+
const data = await response.json();
|
|
6320
|
+
return data.entries || [];
|
|
6321
|
+
}
|
|
6322
|
+
async getPlayerStats(playerId) {
|
|
6323
|
+
const id = this.appId || "";
|
|
6324
|
+
const response = await fetch(`${this.gameServerUrl}/v1/game/${id}/ranking/players/${playerId}/stats`, {
|
|
6325
|
+
headers: this.getHeaders()
|
|
6326
|
+
});
|
|
6327
|
+
if (!response.ok) throw new Error(`Failed to get player stats: ${response.statusText}`);
|
|
6328
|
+
return response.json();
|
|
6329
|
+
}
|
|
6330
|
+
async getPlayerRank(playerId) {
|
|
6331
|
+
const id = this.appId || "";
|
|
6332
|
+
const response = await fetch(`${this.gameServerUrl}/v1/game/${id}/ranking/players/${playerId}/rank`, {
|
|
6333
|
+
headers: this.getHeaders()
|
|
6334
|
+
});
|
|
6335
|
+
if (!response.ok) throw new Error(`Failed to get player rank: ${response.statusText}`);
|
|
6336
|
+
return response.json();
|
|
6337
|
+
}
|
|
6338
|
+
// --- Voice API ---
|
|
6339
|
+
async joinVoiceChannel(roomId, playerId) {
|
|
6340
|
+
const id = this.appId || "";
|
|
6341
|
+
const response = await fetch(`${this.gameServerUrl}/v1/game/${id}/voice/rooms/${roomId}/join`, {
|
|
6342
|
+
method: "POST",
|
|
6343
|
+
headers: { ...this.getHeaders(), "Content-Type": "application/json" },
|
|
6344
|
+
body: JSON.stringify({ player_id: playerId })
|
|
6345
|
+
});
|
|
6346
|
+
if (!response.ok) throw new Error(`Failed to join voice channel: ${response.statusText}`);
|
|
6347
|
+
return response.json();
|
|
6348
|
+
}
|
|
6349
|
+
async leaveVoiceChannel(roomId, playerId) {
|
|
6350
|
+
const id = this.appId || "";
|
|
6351
|
+
const response = await fetch(`${this.gameServerUrl}/v1/game/${id}/voice/rooms/${roomId}/leave`, {
|
|
6352
|
+
method: "POST",
|
|
6353
|
+
headers: { ...this.getHeaders(), "Content-Type": "application/json" },
|
|
6354
|
+
body: JSON.stringify({ player_id: playerId })
|
|
6355
|
+
});
|
|
6356
|
+
if (!response.ok) throw new Error(`Failed to leave voice channel: ${response.statusText}`);
|
|
6357
|
+
}
|
|
6358
|
+
async setMute(playerId, muted) {
|
|
6359
|
+
const id = this.appId || "";
|
|
6360
|
+
const response = await fetch(`${this.gameServerUrl}/v1/game/${id}/voice/mute`, {
|
|
6361
|
+
method: "POST",
|
|
6362
|
+
headers: { ...this.getHeaders(), "Content-Type": "application/json" },
|
|
6363
|
+
body: JSON.stringify({ player_id: playerId, muted })
|
|
6364
|
+
});
|
|
6365
|
+
if (!response.ok) throw new Error(`Failed to set mute: ${response.statusText}`);
|
|
6366
|
+
}
|
|
6367
|
+
// --- Replay API ---
|
|
6368
|
+
async listReplays(roomId) {
|
|
6369
|
+
const id = this.appId || "";
|
|
6370
|
+
let url = `${this.gameServerUrl}/v1/game/${id}/replays`;
|
|
6371
|
+
if (roomId) url += `?room_id=${roomId}`;
|
|
6372
|
+
const response = await fetch(url, { headers: this.getHeaders() });
|
|
6373
|
+
if (!response.ok) throw new Error(`Failed to list replays: ${response.statusText}`);
|
|
6374
|
+
const data = await response.json();
|
|
6375
|
+
return data.replays || [];
|
|
6376
|
+
}
|
|
6377
|
+
async getReplay(replayId) {
|
|
6378
|
+
const id = this.appId || "";
|
|
6379
|
+
const response = await fetch(`${this.gameServerUrl}/v1/game/${id}/replays/${replayId}`, {
|
|
6380
|
+
headers: this.getHeaders()
|
|
6381
|
+
});
|
|
6382
|
+
if (!response.ok) throw new Error(`Failed to get replay: ${response.statusText}`);
|
|
6383
|
+
return response.json();
|
|
6384
|
+
}
|
|
6385
|
+
async downloadReplay(replayId) {
|
|
6386
|
+
const id = this.appId || "";
|
|
6387
|
+
const response = await fetch(`${this.gameServerUrl}/v1/game/${id}/replays/${replayId}/download`, {
|
|
6388
|
+
headers: this.getHeaders()
|
|
6389
|
+
});
|
|
6390
|
+
if (!response.ok) throw new Error(`Failed to download replay: ${response.statusText}`);
|
|
6391
|
+
return response.arrayBuffer();
|
|
6392
|
+
}
|
|
6393
|
+
async getReplayHighlights(replayId) {
|
|
6394
|
+
const id = this.appId || "";
|
|
6395
|
+
const response = await fetch(`${this.gameServerUrl}/v1/game/${id}/replays/${replayId}/highlights`, {
|
|
6396
|
+
headers: this.getHeaders()
|
|
6397
|
+
});
|
|
6398
|
+
if (!response.ok) throw new Error(`Failed to get highlights: ${response.statusText}`);
|
|
6399
|
+
const data = await response.json();
|
|
6400
|
+
return data.highlights || [];
|
|
6401
|
+
}
|
|
6225
6402
|
getHeaders() {
|
|
6226
6403
|
const headers = {};
|
|
6227
6404
|
const apiKey = this.http.getApiKey();
|