@antha/multiplayer-p2p-authoritative-host 0.14.1 → 0.15.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/antha-multiplayer-p2p-authoritative-host.mod.d.ts +1 -1
- package/dist/antha-multiplayer-p2p-authoritative-host.mod.js +4 -4
- package/dist/p2p-authoritative-host-multiplayer-controller.d.ts +12 -12
- package/dist/p2p-authoritative-host-multiplayer-controller.js +9 -9
- package/package.json +5 -5
|
@@ -9,7 +9,7 @@ import { P2pAuthoritativeHostMultiplayerController, type P2pAuthoritativeHostMul
|
|
|
9
9
|
export type AnthaMultiplayerP2pAuthoritativeHostState<Input extends JsonCompatibleValue = any, MultiplayerGameState extends JsonCompatibleValue = any> = {
|
|
10
10
|
/** P2p-authoritative-host controller state. */
|
|
11
11
|
multiplayerP2pAuthoritativeHost: {
|
|
12
|
-
/**
|
|
12
|
+
/** Multiplayer controller used to drive singleplayer or multiplayer state sync. */
|
|
13
13
|
multiplayerController: P2pAuthoritativeHostMultiplayerController<Input, MultiplayerGameState>;
|
|
14
14
|
/** Current backend API and room connection state. */
|
|
15
15
|
connectionState: ApiAndRoomConnectionState;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { defineAnthaMod } from '@antha/engine';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { MultiplayerControllerConnectionEvent, emptyApiAndRoomConnectionState, } from '@antha/multiplayer-core';
|
|
3
|
+
import { MultiplayerControllerStateEvent, P2pAuthoritativeHostMultiplayerController, } from './p2p-authoritative-host-multiplayer-controller.js';
|
|
4
4
|
/**
|
|
5
5
|
* Create the engine mod that owns p2p-authoritative-host multiplayer state.
|
|
6
6
|
*
|
|
@@ -12,13 +12,13 @@ export function createAnthaMultiplayerP2pAuthoritativeHostMod(options) {
|
|
|
12
12
|
execute({ state }) {
|
|
13
13
|
if (!state.multiplayerP2pAuthoritativeHost) {
|
|
14
14
|
state.multiplayerP2pAuthoritativeHost = createP2pAuthoritativeHostState(options);
|
|
15
|
-
state.multiplayerP2pAuthoritativeHost.multiplayerController.listen(
|
|
15
|
+
state.multiplayerP2pAuthoritativeHost.multiplayerController.listen(MultiplayerControllerConnectionEvent, ({ detail: newConnectionState }) => {
|
|
16
16
|
if (!state.multiplayerP2pAuthoritativeHost) {
|
|
17
17
|
return;
|
|
18
18
|
}
|
|
19
19
|
state.multiplayerP2pAuthoritativeHost.connectionState = newConnectionState;
|
|
20
20
|
});
|
|
21
|
-
state.multiplayerP2pAuthoritativeHost.multiplayerController.listen((
|
|
21
|
+
state.multiplayerP2pAuthoritativeHost.multiplayerController.listen((MultiplayerControllerStateEvent), ({ detail }) => {
|
|
22
22
|
if (!state.multiplayerP2pAuthoritativeHost) {
|
|
23
23
|
return;
|
|
24
24
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type ApiAndRoomConnectionState, type ClientId,
|
|
1
|
+
import { type ApiAndRoomConnectionState, type ClientId, MultiplayerControllerClientEvent, MultiplayerControllerConnectionEvent, MultiplayerControllerRoomListEvent, type MultiplayerControllerRoomListListener, type MultiplayerInitParams, type MultiplayerRoomConnection, MultiplayerRoomController, type RoomInput, RoomRejectionError, type SocketMessageId } from '@antha/multiplayer-core';
|
|
2
2
|
import { type JsonCompatibleValue, type MaybePromise, type PartialWithUndefined } from '@augment-vir/common';
|
|
3
3
|
import { ListenTarget, type RemoveListenerCallback, type TypedCustomEventInit } from 'typed-event-target';
|
|
4
4
|
/**
|
|
@@ -24,7 +24,7 @@ export type P2pAuthoritativeHostStateSnapshot<MultiplayerGameState extends JsonC
|
|
|
24
24
|
stateSyncId: SocketMessageId;
|
|
25
25
|
}>;
|
|
26
26
|
/**
|
|
27
|
-
* Data received from {@link
|
|
27
|
+
* Data received from {@link MultiplayerControllerStateEvent}.
|
|
28
28
|
*
|
|
29
29
|
* @category Internal
|
|
30
30
|
*/
|
|
@@ -91,27 +91,27 @@ export type P2pAuthoritativeHostMultiplayerControllerParams<Input extends JsonCo
|
|
|
91
91
|
*
|
|
92
92
|
* @default accept all connections
|
|
93
93
|
*/
|
|
94
|
-
acceptConnection?: ((connectingClientId: ClientId,
|
|
94
|
+
acceptConnection?: ((connectingClientId: ClientId, multiplayerController: P2pAuthoritativeHostMultiplayerController<Input, MultiplayerGameState>) => MaybePromise<boolean>) | undefined;
|
|
95
95
|
}>;
|
|
96
|
-
declare const
|
|
96
|
+
declare const MultiplayerControllerStateEvent_base: (new (eventInitDict: {
|
|
97
97
|
bubbles?: boolean;
|
|
98
98
|
cancelable?: boolean;
|
|
99
99
|
composed?: boolean;
|
|
100
100
|
detail: any;
|
|
101
|
-
}) => import("typed-event-target").TypedCustomEvent<any, "controller-state">) & Pick<{
|
|
101
|
+
}) => import("typed-event-target").TypedCustomEvent<any, "multiplayer-controller-state">) & Pick<{
|
|
102
102
|
new (type: string, eventInitDict?: EventInit): Event;
|
|
103
103
|
prototype: Event;
|
|
104
104
|
readonly NONE: 0;
|
|
105
105
|
readonly CAPTURING_PHASE: 1;
|
|
106
106
|
readonly AT_TARGET: 2;
|
|
107
107
|
readonly BUBBLING_PHASE: 3;
|
|
108
|
-
}, "prototype" | "NONE" | "CAPTURING_PHASE" | "AT_TARGET" | "BUBBLING_PHASE"> & Pick<import("typed-event-target").TypedCustomEvent<any, "controller-state">, "type">;
|
|
108
|
+
}, "prototype" | "NONE" | "CAPTURING_PHASE" | "AT_TARGET" | "BUBBLING_PHASE"> & Pick<import("typed-event-target").TypedCustomEvent<any, "multiplayer-controller-state">, "type">;
|
|
109
109
|
/**
|
|
110
110
|
* This is fired whenever the local authoritative-host state view updates.
|
|
111
111
|
*
|
|
112
112
|
* @category Events
|
|
113
113
|
*/
|
|
114
|
-
export declare class
|
|
114
|
+
export declare class MultiplayerControllerStateEvent<MultiplayerGameState extends JsonCompatibleValue, Input extends JsonCompatibleValue = any> extends MultiplayerControllerStateEvent_base {
|
|
115
115
|
detail: Readonly<StateEventDetail<Input, MultiplayerGameState>>;
|
|
116
116
|
constructor(eventInitDict: TypedCustomEventInit<Readonly<StateEventDetail<Input, MultiplayerGameState>>>);
|
|
117
117
|
}
|
|
@@ -120,7 +120,7 @@ export declare class ControllerStateEvent<MultiplayerGameState extends JsonCompa
|
|
|
120
120
|
*
|
|
121
121
|
* @category Internal
|
|
122
122
|
*/
|
|
123
|
-
export type AllP2pAuthoritativeHostMultiplayerControllerEvents<Input extends JsonCompatibleValue, MultiplayerGameState extends JsonCompatibleValue> =
|
|
123
|
+
export type AllP2pAuthoritativeHostMultiplayerControllerEvents<Input extends JsonCompatibleValue, MultiplayerGameState extends JsonCompatibleValue> = MultiplayerControllerStateEvent<MultiplayerGameState, Input> | MultiplayerControllerRoomListEvent | MultiplayerControllerClientEvent | MultiplayerControllerConnectionEvent;
|
|
124
124
|
/**
|
|
125
125
|
* An all-in-one controller for singleplayer or p2p-authoritative-host multiplayer game state.
|
|
126
126
|
*
|
|
@@ -130,11 +130,11 @@ export declare class P2pAuthoritativeHostMultiplayerController<Input extends Jso
|
|
|
130
130
|
protected readonly params: P2pAuthoritativeHostMultiplayerControllerParams<Input, MultiplayerGameState>;
|
|
131
131
|
/** All events emitted by this controller. */
|
|
132
132
|
static readonly events: {
|
|
133
|
-
|
|
133
|
+
MultiplayerControllerStateEvent: typeof MultiplayerControllerStateEvent;
|
|
134
134
|
};
|
|
135
135
|
/** All events emitted by this controller. */
|
|
136
136
|
readonly events: {
|
|
137
|
-
|
|
137
|
+
MultiplayerControllerStateEvent: typeof MultiplayerControllerStateEvent;
|
|
138
138
|
};
|
|
139
139
|
static readonly knownErrors: {
|
|
140
140
|
RoomRejectionError: typeof RoomRejectionError;
|
|
@@ -160,9 +160,9 @@ export declare class P2pAuthoritativeHostMultiplayerController<Input extends Jso
|
|
|
160
160
|
*
|
|
161
161
|
* If a callback is provided, it is called each time the room list is updated.
|
|
162
162
|
*/
|
|
163
|
-
startRoomUpdates(callback:
|
|
163
|
+
startRoomUpdates(callback: MultiplayerControllerRoomListListener): RemoveListenerCallback;
|
|
164
164
|
startRoomUpdates(callback?: undefined): undefined;
|
|
165
|
-
startRoomUpdates(callback?:
|
|
165
|
+
startRoomUpdates(callback?: MultiplayerControllerRoomListListener | undefined): RemoveListenerCallback | undefined;
|
|
166
166
|
/** Turn off room list updates and remove callbacks added via `startRoomUpdates`. */
|
|
167
167
|
stopRoomUpdates(): void;
|
|
168
168
|
/** Currently joined room id. If a room has not been joined yet, this will be empty. */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createMultiplayerId, emptyApiAndRoomConnectionState, MultiplayerConnectionState, MultiplayerControllerClientEvent, MultiplayerControllerConnectionEvent, MultiplayerControllerMessageEvent, MultiplayerControllerRoomListEvent, MultiplayerRoomController, RoomRejectionError, } from '@antha/multiplayer-core';
|
|
2
2
|
import { assertWrap, waitUntil } from '@augment-vir/assert';
|
|
3
3
|
import { defineTypedCustomEvent, ListenTarget, } from 'typed-event-target';
|
|
4
4
|
/**
|
|
@@ -17,7 +17,7 @@ export var P2pAuthoritativeHostMessageType;
|
|
|
17
17
|
*
|
|
18
18
|
* @category Events
|
|
19
19
|
*/
|
|
20
|
-
export class
|
|
20
|
+
export class MultiplayerControllerStateEvent extends defineTypedCustomEvent()('multiplayer-controller-state') {
|
|
21
21
|
constructor(eventInitDict) {
|
|
22
22
|
super(eventInitDict);
|
|
23
23
|
}
|
|
@@ -31,7 +31,7 @@ export class P2pAuthoritativeHostMultiplayerController extends ListenTarget {
|
|
|
31
31
|
params;
|
|
32
32
|
/** All events emitted by this controller. */
|
|
33
33
|
static events = {
|
|
34
|
-
|
|
34
|
+
MultiplayerControllerStateEvent,
|
|
35
35
|
};
|
|
36
36
|
/** All events emitted by this controller. */
|
|
37
37
|
events = P2pAuthoritativeHostMultiplayerController.events;
|
|
@@ -146,7 +146,7 @@ export class P2pAuthoritativeHostMultiplayerController extends ListenTarget {
|
|
|
146
146
|
}
|
|
147
147
|
this.singleplayer = true;
|
|
148
148
|
this.dispatchState(this.createStateEventDetail());
|
|
149
|
-
this.dispatch(new
|
|
149
|
+
this.dispatch(new MultiplayerControllerConnectionEvent({
|
|
150
150
|
detail: {
|
|
151
151
|
...emptyApiAndRoomConnectionState,
|
|
152
152
|
api: MultiplayerConnectionState.Connected,
|
|
@@ -220,16 +220,16 @@ export class P2pAuthoritativeHostMultiplayerController extends ListenTarget {
|
|
|
220
220
|
}
|
|
221
221
|
/** Forward core room-controller events into this state-sync controller. */
|
|
222
222
|
listenToRoomController() {
|
|
223
|
-
this.roomController.listen(
|
|
223
|
+
this.roomController.listen(MultiplayerControllerRoomListEvent, (event) => {
|
|
224
224
|
this.dispatch(event);
|
|
225
225
|
});
|
|
226
|
-
this.roomController.listen(
|
|
226
|
+
this.roomController.listen(MultiplayerControllerConnectionEvent, (event) => {
|
|
227
227
|
this.dispatch(event);
|
|
228
228
|
});
|
|
229
|
-
this.roomController.listen(
|
|
229
|
+
this.roomController.listen(MultiplayerControllerClientEvent, (event) => {
|
|
230
230
|
this.dispatch(event);
|
|
231
231
|
});
|
|
232
|
-
this.roomController.listen((
|
|
232
|
+
this.roomController.listen((MultiplayerControllerMessageEvent), (event) => {
|
|
233
233
|
this.handleReceivedMessage(event.sourceClientId, event.detail);
|
|
234
234
|
});
|
|
235
235
|
}
|
|
@@ -345,7 +345,7 @@ export class P2pAuthoritativeHostMultiplayerController extends ListenTarget {
|
|
|
345
345
|
}
|
|
346
346
|
/** Dispatch the typed state event to local listeners. */
|
|
347
347
|
dispatchState(detail) {
|
|
348
|
-
this.dispatch(new
|
|
348
|
+
this.dispatch(new MultiplayerControllerStateEvent({
|
|
349
349
|
detail,
|
|
350
350
|
}));
|
|
351
351
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antha/multiplayer-p2p-authoritative-host",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.0",
|
|
4
4
|
"description": "P2P authoritative-host multiplayer strategy for the Antha engine.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vir",
|
|
@@ -36,19 +36,19 @@
|
|
|
36
36
|
"test:docs": "virmator docs check"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@augment-vir/assert": "^32.
|
|
40
|
-
"@augment-vir/common": "^32.
|
|
39
|
+
"@augment-vir/assert": "^32.3.0",
|
|
40
|
+
"@augment-vir/common": "^32.3.0",
|
|
41
41
|
"typed-event-target": "^4.3.3"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@augment-vir/test": "^32.
|
|
44
|
+
"@augment-vir/test": "^32.3.0",
|
|
45
45
|
"@web/dev-server-esbuild": "^2.0.0",
|
|
46
46
|
"@web/test-runner": "^1.0.0",
|
|
47
47
|
"@web/test-runner-playwright": "^1.0.0",
|
|
48
48
|
"istanbul-smart-text-reporter": "^1.1.5"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
|
-
"@antha/multiplayer-core": "^0.
|
|
51
|
+
"@antha/multiplayer-core": "^0.15.0"
|
|
52
52
|
},
|
|
53
53
|
"engines": {
|
|
54
54
|
"node": ">=22"
|