Add DESIRED_NAME Message
This commit is contained in:
parent
ecb486b8c1
commit
a618eda732
1 changed files with 19 additions and 0 deletions
|
@ -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;
|
||||||
|
}
|
||||||
|
|
Reference in a new issue