@antha/multiplayer-core 0.17.0 → 0.18.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.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/multiplayer-api/multiplayer-controller.d.ts +7 -7
- package/dist/multiplayer-api/multiplayer-controller.js +3 -3
- package/dist/multiplayer-player-id.d.ts +53 -0
- package/dist/multiplayer-player-id.js +45 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export * from './multiplayer-api/multiplayer-client.js';
|
|
|
4
4
|
export * from './multiplayer-api/multiplayer-controller.js';
|
|
5
5
|
export * from './multiplayer-api/multiplayer-socket-messages.js';
|
|
6
6
|
export * from './multiplayer-id.js';
|
|
7
|
+
export * from './multiplayer-player-id.js';
|
|
7
8
|
export * from './room-handler-server/mock-room-handler-server-api-client.js';
|
|
8
9
|
export * from './room-handler-server/multiplayer-room-handler.js';
|
|
9
10
|
export * from './webrtc/web-rtc-communication.js';
|
package/dist/index.js
CHANGED
|
@@ -4,6 +4,7 @@ export * from './multiplayer-api/multiplayer-client.js';
|
|
|
4
4
|
export * from './multiplayer-api/multiplayer-controller.js';
|
|
5
5
|
export * from './multiplayer-api/multiplayer-socket-messages.js';
|
|
6
6
|
export * from './multiplayer-id.js';
|
|
7
|
+
export * from './multiplayer-player-id.js';
|
|
7
8
|
export * from './room-handler-server/mock-room-handler-server-api-client.js';
|
|
8
9
|
export * from './room-handler-server/multiplayer-room-handler.js';
|
|
9
10
|
export * from './webrtc/web-rtc-communication.js';
|
|
@@ -195,7 +195,7 @@ export declare class MultiplayerControllerRoomListEvent extends MultiplayerContr
|
|
|
195
195
|
* @category Internal
|
|
196
196
|
*/
|
|
197
197
|
export type MultiplayerControllerRoomListListener = (rooms: Readonly<MultiplayerClientRooms>) => MaybePromise<void>;
|
|
198
|
-
declare const
|
|
198
|
+
declare const MultiplayerControllerClientStatusEvent_base: (new (eventInitDict: {
|
|
199
199
|
bubbles?: boolean;
|
|
200
200
|
cancelable?: boolean;
|
|
201
201
|
composed?: boolean;
|
|
@@ -250,7 +250,7 @@ declare const MultiplayerControllerClientEvent_base: (new (eventInitDict: {
|
|
|
250
250
|
newMember: ClientId;
|
|
251
251
|
lostHost: ClientId;
|
|
252
252
|
lostMember: ClientId;
|
|
253
|
-
}, "newHost" | "newMember" | "lostHost" | "lostMember">>, "multiplayer-controller-client">) & Pick<{
|
|
253
|
+
}, "newHost" | "newMember" | "lostHost" | "lostMember">>, "multiplayer-controller-client-status">) & Pick<{
|
|
254
254
|
new (type: string, eventInitDict?: EventInit): Event;
|
|
255
255
|
prototype: Event;
|
|
256
256
|
readonly NONE: 0;
|
|
@@ -282,7 +282,7 @@ declare const MultiplayerControllerClientEvent_base: (new (eventInitDict: {
|
|
|
282
282
|
newMember: ClientId;
|
|
283
283
|
lostHost: ClientId;
|
|
284
284
|
lostMember: ClientId;
|
|
285
|
-
}, "newHost" | "newMember" | "lostHost" | "lostMember">>, "multiplayer-controller-client">, "type">;
|
|
285
|
+
}, "newHost" | "newMember" | "lostHost" | "lostMember">>, "multiplayer-controller-client-status">, "type">;
|
|
286
286
|
/**
|
|
287
287
|
* This is fired in the following situations:
|
|
288
288
|
*
|
|
@@ -293,7 +293,7 @@ declare const MultiplayerControllerClientEvent_base: (new (eventInitDict: {
|
|
|
293
293
|
*
|
|
294
294
|
* @category Events
|
|
295
295
|
*/
|
|
296
|
-
export declare class
|
|
296
|
+
export declare class MultiplayerControllerClientStatusEvent extends MultiplayerControllerClientStatusEvent_base {
|
|
297
297
|
}
|
|
298
298
|
declare const MultiplayerControllerConnectionEvent_base: (new (eventInitDict: {
|
|
299
299
|
bubbles?: boolean;
|
|
@@ -320,7 +320,7 @@ export declare class MultiplayerControllerConnectionEvent extends MultiplayerCon
|
|
|
320
320
|
*
|
|
321
321
|
* @category Internal
|
|
322
322
|
*/
|
|
323
|
-
export type AllMultiplayerRoomControllerEvents<Message extends JsonCompatibleValue> = MultiplayerControllerMessageEvent<Message> | MultiplayerControllerRoomListEvent |
|
|
323
|
+
export type AllMultiplayerRoomControllerEvents<Message extends JsonCompatibleValue> = MultiplayerControllerMessageEvent<Message> | MultiplayerControllerRoomListEvent | MultiplayerControllerClientStatusEvent | MultiplayerControllerConnectionEvent;
|
|
324
324
|
/**
|
|
325
325
|
* A generic multiplayer room controller. It manages API connectivity, room discovery, WebRTC
|
|
326
326
|
* signaling, and generic room messages. It does not impose a game-state synchronization strategy.
|
|
@@ -333,14 +333,14 @@ export declare class MultiplayerRoomController<Message extends JsonCompatibleVal
|
|
|
333
333
|
static readonly events: {
|
|
334
334
|
MultiplayerControllerMessageEvent: typeof MultiplayerControllerMessageEvent;
|
|
335
335
|
MultiplayerControllerRoomListEvent: typeof MultiplayerControllerRoomListEvent;
|
|
336
|
-
|
|
336
|
+
MultiplayerControllerClientStatusEvent: typeof MultiplayerControllerClientStatusEvent;
|
|
337
337
|
MultiplayerControllerConnectionEvent: typeof MultiplayerControllerConnectionEvent;
|
|
338
338
|
};
|
|
339
339
|
/** All events emitted by this controller. */
|
|
340
340
|
readonly events: {
|
|
341
341
|
MultiplayerControllerMessageEvent: typeof MultiplayerControllerMessageEvent;
|
|
342
342
|
MultiplayerControllerRoomListEvent: typeof MultiplayerControllerRoomListEvent;
|
|
343
|
-
|
|
343
|
+
MultiplayerControllerClientStatusEvent: typeof MultiplayerControllerClientStatusEvent;
|
|
344
344
|
MultiplayerControllerConnectionEvent: typeof MultiplayerControllerConnectionEvent;
|
|
345
345
|
};
|
|
346
346
|
static readonly knownErrors: {
|
|
@@ -60,7 +60,7 @@ export class MultiplayerControllerRoomListEvent extends defineTypedCustomEvent()
|
|
|
60
60
|
*
|
|
61
61
|
* @category Events
|
|
62
62
|
*/
|
|
63
|
-
export class
|
|
63
|
+
export class MultiplayerControllerClientStatusEvent extends defineTypedCustomEvent()('multiplayer-controller-client-status') {
|
|
64
64
|
}
|
|
65
65
|
/**
|
|
66
66
|
* Fires when the controller's connection state is updated.
|
|
@@ -81,7 +81,7 @@ export class MultiplayerRoomController extends ListenTarget {
|
|
|
81
81
|
static events = {
|
|
82
82
|
MultiplayerControllerMessageEvent,
|
|
83
83
|
MultiplayerControllerRoomListEvent,
|
|
84
|
-
|
|
84
|
+
MultiplayerControllerClientStatusEvent,
|
|
85
85
|
MultiplayerControllerConnectionEvent,
|
|
86
86
|
};
|
|
87
87
|
/** All events emitted by this controller. */
|
|
@@ -242,7 +242,7 @@ export class MultiplayerRoomController extends ListenTarget {
|
|
|
242
242
|
this.dispatch(new MultiplayerControllerMessageEvent(event.sourceClientId, event.detail));
|
|
243
243
|
});
|
|
244
244
|
currentConnection.listen(WebrtcMultiplayerConnectionUpdateEvent, (event) => {
|
|
245
|
-
this.dispatch(new
|
|
245
|
+
this.dispatch(new MultiplayerControllerClientStatusEvent({
|
|
246
246
|
detail: event.detail,
|
|
247
247
|
}));
|
|
248
248
|
});
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { type Branded } from '@augment-vir/common';
|
|
2
|
+
import { type ClientId } from './multiplayer-id.js';
|
|
3
|
+
/**
|
|
4
|
+
* Separator for client id and player position in {@link MultiplayerPlayerId}.
|
|
5
|
+
*
|
|
6
|
+
* @category Internal
|
|
7
|
+
*/
|
|
8
|
+
export declare const multiplayerPlayerIdSeparator = ":";
|
|
9
|
+
/**
|
|
10
|
+
* Raw, unbranded multiplayer id string for {@link MultiplayerPlayerId}.
|
|
11
|
+
*
|
|
12
|
+
* @category Internal
|
|
13
|
+
*/
|
|
14
|
+
export type RawMultiplayerIdString = `${string}${typeof multiplayerPlayerIdSeparator}${string}`;
|
|
15
|
+
/**
|
|
16
|
+
* Identifies one player slot belonging to a multiplayer client.
|
|
17
|
+
*
|
|
18
|
+
* @category Internal
|
|
19
|
+
*/
|
|
20
|
+
export type MultiplayerPlayerId = Branded<RawMultiplayerIdString, 'multiplayer-player-id'>;
|
|
21
|
+
/**
|
|
22
|
+
* Checks only that a value is a string; it does not validate the encoded client id or player
|
|
23
|
+
* position.
|
|
24
|
+
*
|
|
25
|
+
* @category Internal
|
|
26
|
+
*/
|
|
27
|
+
export declare const multiplayerPlayerIdShape: import("object-shape-tester").Shape<import("@sinclair/typebox").TUnsafe<MultiplayerPlayerId>>;
|
|
28
|
+
/**
|
|
29
|
+
* The client and local slot encoded in a {@link MultiplayerPlayerId}.
|
|
30
|
+
*
|
|
31
|
+
* @category Internal
|
|
32
|
+
*/
|
|
33
|
+
export type MultiplayerPlayerIdParts = {
|
|
34
|
+
clientId: ClientId;
|
|
35
|
+
playerPosition: string;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Combines a peer id and its local player slot into a stable multiplayer player id.
|
|
39
|
+
*
|
|
40
|
+
* @category Util
|
|
41
|
+
*/
|
|
42
|
+
export declare function createMultiplayerPlayerId({ clientId, playerPosition, }: Readonly<{
|
|
43
|
+
clientId: ClientId;
|
|
44
|
+
playerPosition: string;
|
|
45
|
+
}>): NoInfer<MultiplayerPlayerId>;
|
|
46
|
+
/**
|
|
47
|
+
* Splits a multiplayer player id back into its peer id and local player slot.
|
|
48
|
+
*
|
|
49
|
+
* @category Util
|
|
50
|
+
*/
|
|
51
|
+
export declare function extractMultiplayerPlayerIdParts({ playerId, }: Readonly<{
|
|
52
|
+
playerId: MultiplayerPlayerId;
|
|
53
|
+
}>): MultiplayerPlayerIdParts;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { assert } from '@augment-vir/assert';
|
|
2
|
+
import { applyBrand } from '@augment-vir/common';
|
|
3
|
+
import { assertWrapValidShape, typedStringShape } from 'object-shape-tester';
|
|
4
|
+
import { multiplayerIdShapes } from './multiplayer-id.js';
|
|
5
|
+
/**
|
|
6
|
+
* Separator for client id and player position in {@link MultiplayerPlayerId}.
|
|
7
|
+
*
|
|
8
|
+
* @category Internal
|
|
9
|
+
*/
|
|
10
|
+
export const multiplayerPlayerIdSeparator = ':';
|
|
11
|
+
/**
|
|
12
|
+
* Checks only that a value is a string; it does not validate the encoded client id or player
|
|
13
|
+
* position.
|
|
14
|
+
*
|
|
15
|
+
* @category Internal
|
|
16
|
+
*/
|
|
17
|
+
export const multiplayerPlayerIdShape = typedStringShape();
|
|
18
|
+
/**
|
|
19
|
+
* Combines a peer id and its local player slot into a stable multiplayer player id.
|
|
20
|
+
*
|
|
21
|
+
* @category Util
|
|
22
|
+
*/
|
|
23
|
+
export function createMultiplayerPlayerId({ clientId, playerPosition, }) {
|
|
24
|
+
const validatedClientId = assertWrapValidShape(clientId, multiplayerIdShapes.client());
|
|
25
|
+
const playerId = `${validatedClientId}${multiplayerPlayerIdSeparator}${playerPosition}`;
|
|
26
|
+
assert.isNotIn(multiplayerPlayerIdSeparator, validatedClientId, 'Invalid client id.');
|
|
27
|
+
assert.isNotIn(multiplayerPlayerIdSeparator, playerPosition, 'Invalid client id.');
|
|
28
|
+
assert.isNotEmpty(playerPosition, 'Invalid player position.');
|
|
29
|
+
return applyBrand(playerId);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Splits a multiplayer player id back into its peer id and local player slot.
|
|
33
|
+
*
|
|
34
|
+
* @category Util
|
|
35
|
+
*/
|
|
36
|
+
export function extractMultiplayerPlayerIdParts({ playerId, }) {
|
|
37
|
+
const [clientId, playerPosition, ...extraParts] = playerId.split(multiplayerPlayerIdSeparator);
|
|
38
|
+
assert.isTruthy(clientId, 'Invalid multiplayer id.');
|
|
39
|
+
assert.isTruthy(playerPosition, 'Invalid multiplayer id.');
|
|
40
|
+
assert.isEmpty(extraParts, 'Invalid multiplayer id.');
|
|
41
|
+
return {
|
|
42
|
+
clientId: assertWrapValidShape(clientId, multiplayerIdShapes.client()),
|
|
43
|
+
playerPosition,
|
|
44
|
+
};
|
|
45
|
+
}
|