@bluebottle_gg/league-broadcast-client 0.3.0 → 0.3.1
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.d.ts +4 -4
- package/dist/index.js +69 -24
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -2447,12 +2447,12 @@ declare class LeagueBroadcastClient {
|
|
|
2447
2447
|
onIngameStateUpdate(handler: (state: ingameFrontendData) => void): () => void;
|
|
2448
2448
|
/** Register a handler for in-game status changes (running, paused, out of game). */
|
|
2449
2449
|
onIngameStatusChange(handler: (status: GameState$1, isTestingEnv: boolean) => void): () => void;
|
|
2450
|
-
/** Register handlers for in-game events (kills, objectives, etc.). */
|
|
2451
|
-
onIngameEvents(handlers: IngameEventHandlers): void;
|
|
2450
|
+
/** Register handlers for in-game events (kills, objectives, etc.). Returns an unsubscribe function. */
|
|
2451
|
+
onIngameEvents(handlers: IngameEventHandlers): () => void;
|
|
2452
2452
|
/** Register a handler for champ-select state updates. */
|
|
2453
2453
|
onChampSelectUpdate(handler: (state: champSelectStateData) => void): () => void;
|
|
2454
|
-
/** Register handlers for champ-select lifecycle and action events. */
|
|
2455
|
-
onChampSelectEvents(handlers: ChampSelectEventHandlers): void;
|
|
2454
|
+
/** Register handlers for champ-select lifecycle and action events. Returns an unsubscribe function. */
|
|
2455
|
+
onChampSelectEvents(handlers: ChampSelectEventHandlers): () => void;
|
|
2456
2456
|
/** Register a handler for in-game connection. */
|
|
2457
2457
|
onIngameConnect(handler: () => void): () => void;
|
|
2458
2458
|
/** Register a handler for in-game disconnection. */
|
package/dist/index.js
CHANGED
|
@@ -1180,10 +1180,22 @@ var LeagueBroadcastClient = class {
|
|
|
1180
1180
|
// -- In-game event handlers -------------------------------------------------
|
|
1181
1181
|
this.stateUpdateHandlers = /* @__PURE__ */ new Set();
|
|
1182
1182
|
this.gameStatusHandlers = /* @__PURE__ */ new Set();
|
|
1183
|
-
this.ingameEventHandlers = {
|
|
1183
|
+
this.ingameEventHandlers = {
|
|
1184
|
+
onPlayerEvent: /* @__PURE__ */ new Set(),
|
|
1185
|
+
onTeamEvent: /* @__PURE__ */ new Set(),
|
|
1186
|
+
onObjectiveEvent: /* @__PURE__ */ new Set(),
|
|
1187
|
+
onFirstTowerEvent: /* @__PURE__ */ new Set(),
|
|
1188
|
+
onAnnouncementEvent: /* @__PURE__ */ new Set(),
|
|
1189
|
+
onKillFeedEvent: /* @__PURE__ */ new Set()
|
|
1190
|
+
};
|
|
1184
1191
|
// -- Pre-game event handlers ------------------------------------------------
|
|
1185
1192
|
this.champSelectUpdateHandlers = /* @__PURE__ */ new Set();
|
|
1186
|
-
this.champSelectEventHandlers = {
|
|
1193
|
+
this.champSelectEventHandlers = {
|
|
1194
|
+
onAction: /* @__PURE__ */ new Set(),
|
|
1195
|
+
onChampSelectStart: /* @__PURE__ */ new Set(),
|
|
1196
|
+
onChampSelectEnd: /* @__PURE__ */ new Set(),
|
|
1197
|
+
onRouteUpdate: /* @__PURE__ */ new Set()
|
|
1198
|
+
};
|
|
1187
1199
|
this.config = {
|
|
1188
1200
|
host: config.host,
|
|
1189
1201
|
port: config.port ?? 58869,
|
|
@@ -1201,10 +1213,12 @@ var LeagueBroadcastClient = class {
|
|
|
1201
1213
|
this.gameData = new ingameFrontendData();
|
|
1202
1214
|
this.ingameStore = new GameStateStore(this.gameData, this.gameState);
|
|
1203
1215
|
this.setupIngameMessageHandler();
|
|
1216
|
+
this.ingameWs.onDisconnect(() => this.endGame());
|
|
1204
1217
|
this.preGameWs = new WebSocketManager();
|
|
1205
1218
|
this.champSelectData = new champSelectStateData();
|
|
1206
1219
|
this.preGameStore = new ChampSelectStateStore(this.champSelectData);
|
|
1207
1220
|
this.setupPreGameMessageHandler();
|
|
1221
|
+
this.preGameWs.onDisconnect(() => this.endChampSelect());
|
|
1208
1222
|
if (this.config.autoConnect) {
|
|
1209
1223
|
this.connect();
|
|
1210
1224
|
}
|
|
@@ -1297,9 +1311,23 @@ var LeagueBroadcastClient = class {
|
|
|
1297
1311
|
this.gameStatusHandlers.add(handler);
|
|
1298
1312
|
return () => this.gameStatusHandlers.delete(handler);
|
|
1299
1313
|
}
|
|
1300
|
-
/** Register handlers for in-game events (kills, objectives, etc.). */
|
|
1314
|
+
/** Register handlers for in-game events (kills, objectives, etc.). Returns an unsubscribe function. */
|
|
1301
1315
|
onIngameEvents(handlers) {
|
|
1302
|
-
|
|
1316
|
+
const entries = Object.entries(handlers);
|
|
1317
|
+
for (const [key, handler] of entries) {
|
|
1318
|
+
if (handler) {
|
|
1319
|
+
this.ingameEventHandlers[key].add(handler);
|
|
1320
|
+
}
|
|
1321
|
+
}
|
|
1322
|
+
return () => {
|
|
1323
|
+
for (const [key, handler] of entries) {
|
|
1324
|
+
if (handler) {
|
|
1325
|
+
this.ingameEventHandlers[key].delete(
|
|
1326
|
+
handler
|
|
1327
|
+
);
|
|
1328
|
+
}
|
|
1329
|
+
}
|
|
1330
|
+
};
|
|
1303
1331
|
}
|
|
1304
1332
|
// ===========================================================================
|
|
1305
1333
|
// Pre-game event handlers
|
|
@@ -1309,11 +1337,24 @@ var LeagueBroadcastClient = class {
|
|
|
1309
1337
|
this.champSelectUpdateHandlers.add(handler);
|
|
1310
1338
|
return () => this.champSelectUpdateHandlers.delete(handler);
|
|
1311
1339
|
}
|
|
1312
|
-
/** Register handlers for champ-select lifecycle and action events. */
|
|
1340
|
+
/** Register handlers for champ-select lifecycle and action events. Returns an unsubscribe function. */
|
|
1313
1341
|
onChampSelectEvents(handlers) {
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1342
|
+
const entries = Object.entries(handlers);
|
|
1343
|
+
for (const [key, handler] of entries) {
|
|
1344
|
+
if (handler) {
|
|
1345
|
+
this.champSelectEventHandlers[key].add(
|
|
1346
|
+
handler
|
|
1347
|
+
);
|
|
1348
|
+
}
|
|
1349
|
+
}
|
|
1350
|
+
return () => {
|
|
1351
|
+
for (const [key, handler] of entries) {
|
|
1352
|
+
if (handler) {
|
|
1353
|
+
this.champSelectEventHandlers[key].delete(
|
|
1354
|
+
handler
|
|
1355
|
+
);
|
|
1356
|
+
}
|
|
1357
|
+
}
|
|
1317
1358
|
};
|
|
1318
1359
|
}
|
|
1319
1360
|
// ===========================================================================
|
|
@@ -1485,32 +1526,34 @@ var LeagueBroadcastClient = class {
|
|
|
1485
1526
|
}
|
|
1486
1527
|
handleGameEvents(events) {
|
|
1487
1528
|
if (!events) return;
|
|
1488
|
-
if (events.player
|
|
1529
|
+
if (events.player) {
|
|
1489
1530
|
events.player.forEach(
|
|
1490
|
-
(event) => this.ingameEventHandlers.onPlayerEvent(event)
|
|
1531
|
+
(event) => this.ingameEventHandlers.onPlayerEvent.forEach((h) => h(event))
|
|
1491
1532
|
);
|
|
1492
1533
|
}
|
|
1493
|
-
if (events.team
|
|
1534
|
+
if (events.team) {
|
|
1494
1535
|
events.team.forEach(
|
|
1495
|
-
(event) => this.ingameEventHandlers.onTeamEvent(event)
|
|
1536
|
+
(event) => this.ingameEventHandlers.onTeamEvent.forEach((h) => h(event))
|
|
1496
1537
|
);
|
|
1497
1538
|
}
|
|
1498
|
-
if (events.objective
|
|
1539
|
+
if (events.objective) {
|
|
1499
1540
|
events.objective.forEach(
|
|
1500
|
-
(event) => this.ingameEventHandlers.onObjectiveEvent(event)
|
|
1541
|
+
(event) => this.ingameEventHandlers.onObjectiveEvent.forEach((h) => h(event))
|
|
1501
1542
|
);
|
|
1502
1543
|
}
|
|
1503
|
-
if (events.firstTower !== void 0
|
|
1504
|
-
this.ingameEventHandlers.onFirstTowerEvent(
|
|
1544
|
+
if (events.firstTower !== void 0) {
|
|
1545
|
+
this.ingameEventHandlers.onFirstTowerEvent.forEach(
|
|
1546
|
+
(h) => h(events.firstTower)
|
|
1547
|
+
);
|
|
1505
1548
|
}
|
|
1506
|
-
if (events.announcements
|
|
1549
|
+
if (events.announcements) {
|
|
1507
1550
|
events.announcements.forEach(
|
|
1508
|
-
(event) => this.ingameEventHandlers.onAnnouncementEvent(event)
|
|
1551
|
+
(event) => this.ingameEventHandlers.onAnnouncementEvent.forEach((h) => h(event))
|
|
1509
1552
|
);
|
|
1510
1553
|
}
|
|
1511
|
-
if (events.killFeed
|
|
1554
|
+
if (events.killFeed) {
|
|
1512
1555
|
events.killFeed.forEach(
|
|
1513
|
-
(event) => this.ingameEventHandlers.onKillFeedEvent(event)
|
|
1556
|
+
(event) => this.ingameEventHandlers.onKillFeedEvent.forEach((h) => h(event))
|
|
1514
1557
|
);
|
|
1515
1558
|
}
|
|
1516
1559
|
}
|
|
@@ -1557,7 +1600,7 @@ var LeagueBroadcastClient = class {
|
|
|
1557
1600
|
this.champSelectData = structuralShare(this.champSelectData, nextData);
|
|
1558
1601
|
if (nextData.isActive && !this.champSelectWasActive) {
|
|
1559
1602
|
this.champSelectWasActive = true;
|
|
1560
|
-
this.champSelectEventHandlers.onChampSelectStart
|
|
1603
|
+
this.champSelectEventHandlers.onChampSelectStart.forEach((h) => h());
|
|
1561
1604
|
} else if (!nextData.isActive && this.champSelectWasActive) {
|
|
1562
1605
|
this.champSelectWasActive = false;
|
|
1563
1606
|
this.endChampSelect();
|
|
@@ -1569,16 +1612,18 @@ var LeagueBroadcastClient = class {
|
|
|
1569
1612
|
);
|
|
1570
1613
|
}
|
|
1571
1614
|
handleChampSelectAction(action) {
|
|
1572
|
-
this.champSelectEventHandlers.onAction
|
|
1615
|
+
this.champSelectEventHandlers.onAction.forEach(
|
|
1616
|
+
(h) => h(action)
|
|
1617
|
+
);
|
|
1573
1618
|
}
|
|
1574
1619
|
handleRouteUpdate(uri) {
|
|
1575
|
-
this.champSelectEventHandlers.onRouteUpdate
|
|
1620
|
+
this.champSelectEventHandlers.onRouteUpdate.forEach((h) => h(uri));
|
|
1576
1621
|
}
|
|
1577
1622
|
endChampSelect() {
|
|
1578
1623
|
console.log("[LeagueBroadcastClient] Champ select ended, resetting data");
|
|
1579
1624
|
this.champSelectData = new champSelectStateData();
|
|
1580
1625
|
this.preGameStore._reset(this.champSelectData);
|
|
1581
|
-
this.champSelectEventHandlers.onChampSelectEnd
|
|
1626
|
+
this.champSelectEventHandlers.onChampSelectEnd.forEach((h) => h());
|
|
1582
1627
|
this.champSelectUpdateHandlers.forEach(
|
|
1583
1628
|
(handler) => handler(this.champSelectData)
|
|
1584
1629
|
);
|