@4players/odin-foundation
Version:
A set of classes defining a standard protocol for messaging and user data built on top of the Odin protocol.
129 lines (128 loc) • 3.79 kB
TypeScript
import { IUserData } from "./datastructures";
/** RPC method declaration - RPC functions need to be declared in the bot class with this type and registered with the registerRPCMethod method */
export type OdinRPCRequestHandler = (senderPeerId: number, args: any) => Promise<any>;
export type OdinRPCResponseHandler = (response: any) => void;
/**
* These classes are used to hold data locally within the app. They are not sent over the network. Use models described
* in `datastructures.ts` for network transfer. Instances of these classes are created from the datastructures. For example
* a chat message is created from a `IMessageTransferFormat` object which is sent over the network. The same applies to
* IUser instances. They are created in PeerJoined messages using the data from the peerUserData field.
*/
/**
* @summary A user in the room
* This is the class that holds user information locally within the app. `data` holds all data that is shared with others.
*/
export interface IUser {
/**
* @summary The user's unique ID
* @deprecated Use data.id instead
*/
id: string;
/**
* The user's peer ID (i.e. current peer in the room).
*/
peerId: number;
/**
* The user's name
* @deprecated Use data.name instead
*/
name: string;
/**
* The user's avatar URL
* @deprecated Use data.avatar instead
*/
avatar?: string;
/**
* The user's status
* @deprecated Use data.status instead
*/
status: 'online' | 'away' | 'dnd';
/**
* Whether the user has muted their output
* @deprecated Use data.outputMuted instead
*/
outputMuted: number;
/**
* Whether the user has muted their input
* @deprecated Use data.inputMuted instead
*/
inputMuted: number;
/**
* The user's renderer
* @deprecated Use data.renderer instead
*/
renderer?: string;
/**
* The user's platform (i.e. Windows, Linux, Mac, etc.)
* @deprecated Use data.platform instead
*/
platform?: string;
/**
* The user's revision
* @deprecated Use data.revision instead
*/
revision?: string;
/**
* The user's version
* @deprecated Use data.version instead
*/
version?: string;
/**
* The user's build number
* @deprecated Use data.buildNo instead
*/
buildNo?: number;
/**
* The user's data. This is the data which is shared as part of the peer user data with other users and should be
* used instead of the deprecated properties.
*/
data?: IUserData;
}
/**
* @summary A chat message
* This class stores a chat message locally within the app.
* @see IMessageTransfer is used to send messages to other users.
*/
export interface IChatMessage {
/**
* The ID of the user who sent the message
*/
fromId: string;
/**
* The avatar of the user who sent the message
* We store this here so that we can display the avatar even if the user leaves the room
*/
fromAvatar: string;
/**
* The name of the user who sent the message
*/
fromName: string;
/**
* The ID of the user who the message is directed to
*/
targetId?: number;
/**
* The name of the user who the message is directed to
*/
targetName?: string;
/**
* The kind of message
*/
kind: 'poke' | 'message';
/**
* The text of the message
*/
text: string;
/**
* The URLs in the message (if any) used for link previews
*/
urls: string[];
/**
* The time the message was sent
*/
time: Date;
/**
* Whether the message is private, i.e. if it only should be shown to the sender and the target
*/
isPrivate?: boolean;
}