@4players/odin-foundation
Version:
A set of classes defining a standard protocol for messaging and user data built on top of the Odin protocol.
111 lines (110 loc) • 2.92 kB
TypeScript
/**
* @summary Interface for user data shared with other users over the network
*/
export interface IUserData {
/**
* The user's ID. It must be unique within the domain of the app.
*/
id?: string;
/**
* The user's name
*/
name?: string;
/**
* The user's avatar URL
*/
avatar?: string;
/**
* The user's status
*/
status?: 'online' | 'away' | 'dnd';
/**
* Whether the user is typing
*/
typing?: boolean;
/**
* Whether the user has muted their output
*/
outputMuted?: number;
/**
* Whether the user has muted their input
*/
inputMuted?: number;
/**
* The user's renderer
*/
renderer?: string;
/**
* The user's platform (i.e. Windows, Linux, Mac, etc.)
*/
platform?: string;
/**
* The user's revision
*/
revision?: string;
/**
* The user's version
*/
version?: string;
/**
* The user's build number
*/
buildNo?: number;
}
/**
* @summary Interface for message payloads
* We support three kinds of messages: pokes, messages, and RPCs. They are sent over the same interface but with different
* payloads. This is the message payload, which is the same for all three kinds of text messages.
*/
export interface IMessagePayload {
text: string;
}
/**
* @summary Interface for poke payloads
* We support three kinds of messages: pokes, messages, and RPCs. They are sent over the same interface but with different
* payloads. This is the poke payload that is basically a text message but triggers a prominent notification.
*/
export interface IPokePayload {
text: string;
}
/**
* @summary Interface for RPC payloads
* RPC payloads are used to trigger functions on client or server side.
*/
export interface IRPCPayload {
/**
* The name of the function to call
*/
method: string;
/**
* The ID of the request. This is used to match the response to the request.
*/
requestId?: string;
/**
* The ID of the response. It's the request ID of the request that triggered this response.
*/
responseId?: string;
/**
* The arguments to pass to the function
*/
args?: any;
}
/**
* @summary Interface for message transfer format
* We support three kinds of messages: pokes, messages, and RPCs. They are sent over the same interface but with different
* types of payloads. This is the actual data that is sent over the network.
*/
export interface IMessageTransferFormat {
/**
* The kind of message
*/
kind: 'poke' | 'message' | 'rpc';
/**
* The payload of the message. Type must match the kind of message.
*/
payload: IPokePayload | IMessagePayload | IRPCPayload;
/**
* Whether the message is private. Private messages are not sent to other users.
*/
isPrivate?: boolean;
}