Add DESIRED_NAME Message

This commit is contained in:
Tobias Berger 2022-01-21 14:32:47 +01:00
parent ecb486b8c1
commit a618eda732

View file

@ -5,6 +5,7 @@ export enum MessageType {
TYPING = 4, TYPING = 4,
CURRENTLY_TYPING = 5, CURRENTLY_TYPING = 5,
CONNECTED_USERS = 6, CONNECTED_USERS = 6,
DESIRED_NAME = 7,
} }
export type ServerMessage = { export type ServerMessage = {
@ -175,3 +176,21 @@ export function isConnectedUsersMessage(
return true; return true;
} }
export type DesiredNameMessage = ServerMessage & {
type: MessageType.DESIRED_NAME;
desiredName: string;
};
export function isDesiredNameMessage(obj: unknown): obj is DesiredNameMessage {
if (!isServerMessage(obj, MessageType.DESIRED_NAME)) {
return false;
}
if (
!Object.hasOwnProperty.call(obj, "desiredName") ||
typeof (obj as ServerMessage & { desiredName: unknown }).desiredName !==
"string"
) {
return false;
}
return true;
}