@mml-io/3d-web-user-networking 0.21.6 → 0.23.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/build/DeltaNetComponentMapping.d.ts +58 -0
- package/build/UserData.d.ts +3 -2
- package/build/UserNetworkingClient.d.ts +40 -14
- package/build/UserNetworkingLogger.d.ts +15 -0
- package/build/UserNetworkingMessages.d.ts +14 -53
- package/build/UserNetworkingServer.d.ts +31 -20
- package/build/index.d.ts +5 -2
- package/build/index.js +1338 -391
- package/build/index.js.map +4 -4
- package/build/legacy/LegacyAdapter.d.ts +29 -0
- package/build/legacy/LegacyUserNetworkingCodec.d.ts +17 -0
- package/build/legacy/LegacyUserNetworkingMessages.d.ts +76 -0
- package/build/{UserNetworkingCodec.d.ts → types.d.ts} +7 -5
- package/package.json +15 -5
- package/build/ReconnectingWebSocket.d.ts +0 -27
- package/build/user-networking-settings.d.ts +0 -3
@@ -0,0 +1,58 @@
|
|
1
|
+
import { UserNetworkingClientUpdate } from "./types";
|
2
|
+
import { UserData } from "./UserData";
|
3
|
+
import { UserNetworkingLogger } from "./UserNetworkingLogger";
|
4
|
+
import { CharacterDescription } from "./UserNetworkingMessages";
|
5
|
+
export declare const COMPONENT_POSITION_X = 1;
|
6
|
+
export declare const COMPONENT_POSITION_Y = 2;
|
7
|
+
export declare const COMPONENT_POSITION_Z = 3;
|
8
|
+
export declare const COMPONENT_ROTATION_Y = 4;
|
9
|
+
export declare const COMPONENT_ROTATION_W = 5;
|
10
|
+
export declare const COMPONENT_STATE = 6;
|
11
|
+
export declare const STATE_INTERNAL_CONNECTION_ID = 0;
|
12
|
+
export declare const STATE_CHARACTER_DESCRIPTION = 1;
|
13
|
+
export declare const STATE_USERNAME = 2;
|
14
|
+
export declare const STATE_COLORS = 3;
|
15
|
+
export declare const rotationMultiplier = 360;
|
16
|
+
export declare const positionMultiplier = 100;
|
17
|
+
export declare class DeltaNetComponentMapping {
|
18
|
+
/**
|
19
|
+
* Convert UserNetworkingClientUpdate to deltanet components
|
20
|
+
*/
|
21
|
+
static toComponents(update: UserNetworkingClientUpdate): Map<number, bigint>;
|
22
|
+
/**
|
23
|
+
* Convert deltanet components back to UserNetworkingClientUpdate
|
24
|
+
*/
|
25
|
+
static fromComponents(components: Map<number, bigint>): UserNetworkingClientUpdate;
|
26
|
+
/**
|
27
|
+
* Encode character description and username to binary states
|
28
|
+
*/
|
29
|
+
static toStates(userIdentity: UserData): Map<number, Uint8Array>;
|
30
|
+
/**
|
31
|
+
* Encode username to binary state
|
32
|
+
*/
|
33
|
+
static toUsernameState(username: string): Map<number, Uint8Array>;
|
34
|
+
/**
|
35
|
+
* Encode character description to binary state
|
36
|
+
*/
|
37
|
+
static toCharacterDescriptionState(characterDescription: CharacterDescription): Map<number, Uint8Array>;
|
38
|
+
/**
|
39
|
+
* Encode colors to binary state
|
40
|
+
*/
|
41
|
+
static toColorsState(colors: Array<[number, number, number]>): Map<number, Uint8Array>;
|
42
|
+
/**
|
43
|
+
* Encode single state value
|
44
|
+
*/
|
45
|
+
static toSingleState(stateId: number, value: any): Map<number, Uint8Array>;
|
46
|
+
static encodeColors(colors: Array<[number, number, number]>): Uint8Array;
|
47
|
+
static decodeColors(colors: Uint8Array, logger: UserNetworkingLogger): Array<[number, number, number]>;
|
48
|
+
static fromUserStates(states: Map<number, Uint8Array>, logger: UserNetworkingLogger): UserData;
|
49
|
+
static userIdFromBytes(bytes: Uint8Array): number | null;
|
50
|
+
static usernameFromBytes(bytes: Uint8Array): string | null;
|
51
|
+
static characterDescriptionFromBytes(bytes: Uint8Array): CharacterDescription | null;
|
52
|
+
/**
|
53
|
+
* Decode binary states back to username and character description
|
54
|
+
*/
|
55
|
+
static fromStates(states: Map<number, Uint8Array>, logger: UserNetworkingLogger): {
|
56
|
+
userId: number | null;
|
57
|
+
} & UserData;
|
58
|
+
}
|
package/build/UserData.d.ts
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
import { CharacterDescription } from "./UserNetworkingMessages";
|
2
2
|
export type UserData = {
|
3
|
-
|
4
|
-
|
3
|
+
username: string | null;
|
4
|
+
characterDescription: CharacterDescription | null;
|
5
|
+
colors: Array<[number, number, number]> | null;
|
5
6
|
};
|
@@ -1,27 +1,53 @@
|
|
1
|
-
import {
|
2
|
-
import {
|
3
|
-
import {
|
1
|
+
import { UserNetworkingClientUpdate, WebsocketFactory, WebsocketStatus } from "./types";
|
2
|
+
import { UserData } from "./UserData";
|
3
|
+
import { UserNetworkingLogger } from "./UserNetworkingLogger";
|
4
|
+
import { CharacterDescription } from "./UserNetworkingMessages";
|
4
5
|
export type UserNetworkingClientConfig = {
|
5
6
|
url: string;
|
6
7
|
sessionToken: string;
|
7
8
|
websocketFactory: WebsocketFactory;
|
8
9
|
statusUpdateCallback: (status: WebsocketStatus) => void;
|
9
10
|
assignedIdentity: (clientId: number) => void;
|
10
|
-
clientUpdate: (id: number, update: null | UserNetworkingClientUpdate) => void;
|
11
|
-
clientProfileUpdated: (id: number, username: string, characterDescription: CharacterDescription) => void;
|
12
11
|
onServerError: (error: {
|
13
12
|
message: string;
|
14
|
-
errorType:
|
15
|
-
}) => void;
|
16
|
-
onServerBroadcast?: (broadcast: {
|
17
|
-
broadcastType: string;
|
18
|
-
payload: any;
|
13
|
+
errorType: string;
|
19
14
|
}) => void;
|
15
|
+
onCustomMessage?: (customType: number, contents: string) => void;
|
16
|
+
onUpdate(update: NetworkUpdate): void;
|
17
|
+
};
|
18
|
+
export type AddedUser = {
|
19
|
+
userState: UserData;
|
20
|
+
components: UserNetworkingClientUpdate;
|
21
|
+
};
|
22
|
+
export type UpdatedUser = {
|
23
|
+
userState?: Partial<UserData>;
|
24
|
+
components: UserNetworkingClientUpdate;
|
25
|
+
};
|
26
|
+
export type NetworkUpdate = {
|
27
|
+
removedUserIds: Set<number>;
|
28
|
+
addedUserIds: Map<number, AddedUser>;
|
29
|
+
updatedUsers: Map<number, UpdatedUser>;
|
20
30
|
};
|
21
|
-
export declare class UserNetworkingClient
|
31
|
+
export declare class UserNetworkingClient {
|
22
32
|
private config;
|
23
|
-
|
33
|
+
private logger;
|
34
|
+
private deltaNetClient;
|
35
|
+
private deltaNetState;
|
36
|
+
private userId;
|
37
|
+
private userIndex;
|
38
|
+
private userState;
|
39
|
+
private stableIdToUserId;
|
40
|
+
private userProfiles;
|
41
|
+
private isAuthenticated;
|
42
|
+
private pendingUpdate;
|
43
|
+
constructor(config: UserNetworkingClientConfig, initialUserState?: UserData, initialUpdate?: UserNetworkingClientUpdate, logger?: UserNetworkingLogger);
|
44
|
+
private reset;
|
45
|
+
private sendInitialAuthentication;
|
46
|
+
private processNetworkUpdate;
|
24
47
|
sendUpdate(update: UserNetworkingClientUpdate): void;
|
25
|
-
|
26
|
-
|
48
|
+
sendCustomMessage(customType: number, contents: string): void;
|
49
|
+
updateUsername(username: string): void;
|
50
|
+
updateCharacterDescription(characterDescription: CharacterDescription): void;
|
51
|
+
updateColors(colors: Array<[number, number, number]>): void;
|
52
|
+
stop(): void;
|
27
53
|
}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
export type UserNetworkingServerLogFunction = (...args: Array<any>) => void;
|
2
|
+
export type UserNetworkingLogger = {
|
3
|
+
trace: UserNetworkingServerLogFunction;
|
4
|
+
debug: UserNetworkingServerLogFunction;
|
5
|
+
info: UserNetworkingServerLogFunction;
|
6
|
+
warn: UserNetworkingServerLogFunction;
|
7
|
+
error: UserNetworkingServerLogFunction;
|
8
|
+
};
|
9
|
+
export declare class UserNetworkingConsoleLogger implements UserNetworkingLogger {
|
10
|
+
trace(...args: Array<any>): void;
|
11
|
+
debug(...args: Array<any>): void;
|
12
|
+
info(...args: Array<any>): void;
|
13
|
+
warn(...args: Array<any>): void;
|
14
|
+
error(...args: Array<any>): void;
|
15
|
+
}
|
@@ -1,16 +1,4 @@
|
|
1
|
-
|
2
|
-
export declare const USER_NETWORKING_IDENTITY_MESSAGE_TYPE = "identity";
|
3
|
-
export declare const USER_NETWORKING_USER_AUTHENTICATE_MESSAGE_TYPE = "user_auth";
|
4
|
-
export declare const USER_NETWORKING_USER_PROFILE_MESSAGE_TYPE = "user_profile";
|
5
|
-
export declare const USER_NETWORKING_USER_UPDATE_MESSAGE_TYPE = "user_update";
|
6
|
-
export declare const USER_NETWORKING_SERVER_BROADCAST_MESSAGE_TYPE = "broadcast";
|
7
|
-
export declare const USER_NETWORKING_SERVER_ERROR_MESSAGE_TYPE = "error";
|
8
|
-
export declare const USER_NETWORKING_PING_MESSAGE_TYPE = "ping";
|
9
|
-
export declare const USER_NETWORKING_PONG_MESSAGE_TYPE = "pong";
|
10
|
-
export type UserNetworkingIdentityMessage = {
|
11
|
-
type: typeof USER_NETWORKING_IDENTITY_MESSAGE_TYPE;
|
12
|
-
id: number;
|
13
|
-
};
|
1
|
+
import { DeltaNetServerError } from "@mml-io/delta-net-server";
|
14
2
|
export type CharacterDescription = {
|
15
3
|
meshFileUrl: string;
|
16
4
|
mmlCharacterString?: null;
|
@@ -24,49 +12,22 @@ export type CharacterDescription = {
|
|
24
12
|
mmlCharacterString?: null;
|
25
13
|
mmlCharacterUrl: string;
|
26
14
|
};
|
27
|
-
export
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
characterDescription: CharacterDescription;
|
32
|
-
};
|
33
|
-
export type UserNetworkingDisconnectedMessage = {
|
34
|
-
type: typeof USER_NETWORKING_DISCONNECTED_MESSAGE_TYPE;
|
35
|
-
id: number;
|
15
|
+
export declare class UserNetworkingServerError extends DeltaNetServerError {
|
16
|
+
}
|
17
|
+
export type ClientChatMessage = {
|
18
|
+
message: string;
|
36
19
|
};
|
37
|
-
export
|
38
|
-
|
39
|
-
export declare const USER_NETWORKING_SERVER_SHUTDOWN_ERROR_TYPE = "SERVER_SHUTDOWN";
|
40
|
-
export declare const USER_NETWORKING_UNKNOWN_ERROR = "UNKNOWN_ERROR";
|
41
|
-
export type UserNetworkingServerErrorType = typeof USER_NETWORKING_CONNECTION_LIMIT_REACHED_ERROR_TYPE | typeof USER_NETWORKING_AUTHENTICATION_FAILED_ERROR_TYPE | typeof USER_NETWORKING_SERVER_SHUTDOWN_ERROR_TYPE | typeof USER_NETWORKING_UNKNOWN_ERROR;
|
42
|
-
export type UserNetworkingServerError = {
|
43
|
-
type: typeof USER_NETWORKING_SERVER_ERROR_MESSAGE_TYPE;
|
44
|
-
errorType: UserNetworkingServerErrorType;
|
20
|
+
export type ServerChatMessage = {
|
21
|
+
fromUserId: number;
|
45
22
|
message: string;
|
46
23
|
};
|
47
|
-
export type
|
48
|
-
type: typeof USER_NETWORKING_SERVER_BROADCAST_MESSAGE_TYPE;
|
24
|
+
export type ServerBroadcastMessage = {
|
49
25
|
broadcastType: string;
|
50
26
|
payload: any;
|
51
27
|
};
|
52
|
-
export
|
53
|
-
|
54
|
-
|
55
|
-
export
|
56
|
-
export
|
57
|
-
|
58
|
-
};
|
59
|
-
export type UserIdentity = {
|
60
|
-
characterDescription: CharacterDescription | null;
|
61
|
-
username: string | null;
|
62
|
-
};
|
63
|
-
export type UserNetworkingAuthenticateMessage = {
|
64
|
-
type: typeof USER_NETWORKING_USER_AUTHENTICATE_MESSAGE_TYPE;
|
65
|
-
sessionToken: string;
|
66
|
-
userIdentity?: UserIdentity;
|
67
|
-
};
|
68
|
-
export type UserNetworkingUserUpdateMessage = {
|
69
|
-
type: typeof USER_NETWORKING_USER_UPDATE_MESSAGE_TYPE;
|
70
|
-
userIdentity: UserIdentity;
|
71
|
-
};
|
72
|
-
export type FromUserNetworkingClientMessage = UserNetworkingClientPongMessage | UserNetworkingAuthenticateMessage | UserNetworkingUserUpdateMessage;
|
28
|
+
export declare const SERVER_BROADCAST_MESSAGE_TYPE = 1;
|
29
|
+
export declare const FROM_CLIENT_CHAT_MESSAGE_TYPE = 2;
|
30
|
+
export declare const FROM_SERVER_CHAT_MESSAGE_TYPE = 3;
|
31
|
+
export declare function parseClientChatMessage(contents: string): ClientChatMessage | Error;
|
32
|
+
export declare function parseServerChatMessage(contents: string): ServerChatMessage | Error;
|
33
|
+
export declare function parseServerBroadcastMessage(contents: string): ServerBroadcastMessage | Error;
|
@@ -1,38 +1,49 @@
|
|
1
|
-
import
|
1
|
+
import { DeltaNetV01Connection } from "@mml-io/delta-net-server";
|
2
|
+
import { LegacyUserIdentity, LegacyCharacterDescription } from "./legacy/LegacyUserNetworkingMessages";
|
2
3
|
import { UserData } from "./UserData";
|
3
|
-
import {
|
4
|
-
import {
|
4
|
+
import { UserNetworkingLogger } from "./UserNetworkingLogger";
|
5
|
+
import { UserNetworkingServerError, CharacterDescription } from "./UserNetworkingMessages";
|
5
6
|
export type UserNetworkingServerClient = {
|
6
7
|
socket: WebSocket;
|
7
8
|
id: number;
|
8
9
|
lastPong: number;
|
9
|
-
update: UserNetworkingClientUpdate;
|
10
10
|
authenticatedUser: UserData | null;
|
11
|
+
deltaNetConnection: DeltaNetV01Connection | null;
|
11
12
|
};
|
12
13
|
export type UserNetworkingServerOptions = {
|
13
|
-
|
14
|
-
onClientConnect: (clientId: number, sessionToken: string, userIdentity?:
|
15
|
-
onClientUserIdentityUpdate: (clientId: number, userIdentity:
|
14
|
+
legacyAdapterEnabled?: boolean;
|
15
|
+
onClientConnect: (clientId: number, sessionToken: string, userIdentity?: UserData) => Promise<UserData | true | Error> | UserData | true | Error;
|
16
|
+
onClientUserIdentityUpdate: (clientId: number, userIdentity: UserData) => Promise<UserData | null | false | true | Error> | UserData | null | false | true | Error;
|
16
17
|
onClientDisconnect: (clientId: number) => void;
|
17
18
|
};
|
18
19
|
export declare class UserNetworkingServer {
|
19
20
|
private options;
|
20
|
-
private
|
21
|
+
private logger;
|
22
|
+
private deltaNetServer;
|
21
23
|
private authenticatedClientsById;
|
22
|
-
private
|
23
|
-
private
|
24
|
-
private
|
25
|
-
constructor(options: UserNetworkingServerOptions);
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
24
|
+
private tickInterval;
|
25
|
+
private legacyAdapter;
|
26
|
+
private updatedUserProfilesInTick;
|
27
|
+
constructor(options: UserNetworkingServerOptions, logger?: UserNetworkingLogger);
|
28
|
+
getCharacterDescription(connectionId: number): LegacyCharacterDescription;
|
29
|
+
getUsername(connectionId: number): string;
|
30
|
+
getLegacyClientId(): number;
|
31
|
+
hasCapacityForLegacyClient(): boolean;
|
32
|
+
onLegacyClientConnect(id: number, sessionToken: string, userIdentity: LegacyUserIdentity | undefined): Promise<UserData | true | Error> | UserData | true | Error;
|
33
|
+
setAuthenticatedLegacyClientConnection(clientId: number, webSocket: WebSocket, userData: UserData): void;
|
34
|
+
onLegacyClientDisconnect(id: number): void;
|
35
|
+
private handleStatesUpdate;
|
36
|
+
private handleJoiner;
|
37
|
+
private handleLeave;
|
38
|
+
private handleCustomMessage;
|
39
|
+
private handleDeltaNetAuthentication;
|
30
40
|
connectClient(socket: WebSocket): void;
|
31
|
-
|
32
|
-
private handleUserAuth;
|
41
|
+
broadcastMessage(broadcastType: number, broadcastPayload: string): void;
|
33
42
|
updateUserCharacter(clientId: number, userData: UserData): void;
|
43
|
+
updateUserUsername(clientId: number, username: string): void;
|
44
|
+
updateUserCharacterDescription(clientId: number, characterDescription: CharacterDescription): void;
|
45
|
+
updateUserColors(clientId: number, colors: Array<[number, number, number]>): void;
|
46
|
+
updateUserStates(clientId: number, updates: UserData): void;
|
34
47
|
private internalUpdateUser;
|
35
|
-
private handleUserUpdate;
|
36
|
-
private sendUpdates;
|
37
48
|
dispose(clientCloseError?: UserNetworkingServerError): void;
|
38
49
|
}
|
package/build/index.d.ts
CHANGED
@@ -1,6 +1,9 @@
|
|
1
|
-
export * from "./UserNetworkingCodec";
|
2
1
|
export * from "./UserNetworkingServer";
|
3
2
|
export * from "./UserNetworkingClient";
|
4
3
|
export * from "./UserData";
|
5
|
-
export * from "./
|
4
|
+
export * from "./types";
|
6
5
|
export * from "./UserNetworkingMessages";
|
6
|
+
export * from "./legacy/LegacyUserNetworkingMessages";
|
7
|
+
export * from "./DeltaNetComponentMapping";
|
8
|
+
export * from "./UserNetworkingLogger";
|
9
|
+
export { DeltaNetV01ServerErrors, deltaNetProtocolSubProtocol_v0_1, } from "@mml-io/delta-net-protocol";
|