@antha/multiplayer-p2p-authoritative-host 0.0.4 → 0.0.5
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.
|
@@ -206,12 +206,13 @@ export declare class P2pAuthoritativeHostMultiplayerController<Input extends Jso
|
|
|
206
206
|
isConnected(): boolean;
|
|
207
207
|
/** Cleanup everything. */
|
|
208
208
|
destroy(): void;
|
|
209
|
-
/**
|
|
210
|
-
* Join or create a room.
|
|
211
|
-
*
|
|
212
|
-
* @throws `Error` if this controller is already connected to a room.
|
|
213
|
-
*/
|
|
209
|
+
/** Join or create a room. */
|
|
214
210
|
joinOrCreateRoom(room: Readonly<RoomInput>): Promise<void>;
|
|
211
|
+
/** Join through the core room controller while preserving the wrapper connection on failure. */
|
|
212
|
+
protected joinRoom({ previousRoomConnection, room, }: Readonly<{
|
|
213
|
+
previousRoomConnection: MultiplayerRoomConnection<P2pAuthoritativeHostMessage<Input, State>> | undefined;
|
|
214
|
+
room: Readonly<RoomInput>;
|
|
215
|
+
}>): Promise<MultiplayerRoomConnection<P2pAuthoritativeHostMessage<Input, State>>>;
|
|
215
216
|
/** Leave the current room or single player connection. */
|
|
216
217
|
leaveRoom(): void;
|
|
217
218
|
/** Forward core room-controller events into this state-sync controller. */
|
|
@@ -189,24 +189,29 @@ export class P2pAuthoritativeHostMultiplayerController extends ListenTarget {
|
|
|
189
189
|
this.roomController.destroy();
|
|
190
190
|
super.destroy();
|
|
191
191
|
}
|
|
192
|
-
/**
|
|
193
|
-
* Join or create a room.
|
|
194
|
-
*
|
|
195
|
-
* @throws `Error` if this controller is already connected to a room.
|
|
196
|
-
*/
|
|
192
|
+
/** Join or create a room. */
|
|
197
193
|
async joinOrCreateRoom(room) {
|
|
198
|
-
if (this.
|
|
194
|
+
if (this.singleplayer) {
|
|
199
195
|
throw new Error('Cannot join room: connection already established.');
|
|
200
196
|
}
|
|
197
|
+
const previousRoomConnection = this.roomConnection;
|
|
198
|
+
const roomConnection = await this.joinRoom({
|
|
199
|
+
previousRoomConnection,
|
|
200
|
+
room,
|
|
201
|
+
});
|
|
202
|
+
this.attachMultiplayerRoomConnection(roomConnection);
|
|
203
|
+
}
|
|
204
|
+
/** Join through the core room controller while preserving the wrapper connection on failure. */
|
|
205
|
+
async joinRoom({ previousRoomConnection, room, }) {
|
|
201
206
|
try {
|
|
202
207
|
await this.roomController.joinOrCreateRoom(room);
|
|
203
208
|
if (!this.roomController.currentConnection) {
|
|
204
209
|
throw new Error('Cannot start p2p-authoritative-host multiplayer: room connection is missing.');
|
|
205
210
|
}
|
|
206
|
-
this.
|
|
211
|
+
return this.roomController.currentConnection;
|
|
207
212
|
}
|
|
208
213
|
catch (error) {
|
|
209
|
-
this.roomConnection =
|
|
214
|
+
this.roomConnection = previousRoomConnection;
|
|
210
215
|
throw error;
|
|
211
216
|
}
|
|
212
217
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antha/multiplayer-p2p-authoritative-host",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"description": "P2P authoritative-host multiplayer strategy for the Antha engine.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vir",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"istanbul-smart-text-reporter": "^1.1.5"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
|
-
"@antha/multiplayer-core": "^0.0.
|
|
51
|
+
"@antha/multiplayer-core": "^0.0.5"
|
|
52
52
|
},
|
|
53
53
|
"engines": {
|
|
54
54
|
"node": ">=22"
|