@game-vir/multiplayer
Version:
Client side definitions and types for @game-vir/multiplayer-server
218 lines (217 loc) • 10.7 kB
TypeScript
import { MultiplayerWebSocketMessageType } from '../webrtc/web-rtc-communication.js';
/**
* A shape definition for {@link ClientIdentification} when joining or creating a room.
*
* @category Internal
*/
export declare const clientIdShape: import("object-shape-tester").ShapeDefinition<{
/** This UUID is used to keep track of each client on the multiplayer server. */
clientId: import("object-shape-tester").CustomSpecifier<`${string}-${string}-${string}-${string}-${string}`>;
/**
* The id of the room that the user is communicating with. Set this either to to an existing
* room to join that room, or a new id to create a new room.
*/
roomId: import("object-shape-tester").CustomSpecifier<`${string}-${string}-${string}-${string}-${string}`>;
/** The name of the room to create or join. */
roomName: string;
}, false>;
/**
* Data included in each multiplayer server message that is used to identify the message client and
* the room they wish to join or host.
*
* @category Internal
*/
export type ClientIdentification = typeof clientIdShape.runtimeType;
/**
* Base shape definition for every message type.
*
* @category Internal
*/
export declare const baseMessageShape: import("object-shape-tester").ShapeDefinition<{
/**
* The id of the original message. If a message is ever a response to another message, the
* message id will remain the same throughout the chain.
*/
messageId: import("object-shape-tester").CustomSpecifier<`${string}-${string}-${string}-${string}-${string}`>;
}, false>;
/**
* ==========================================================
*
* # Message Shape Definitions
*
* ==========================================================
*/
/**
* Shape definition for "answer" messages.
*
* @category Internal
*/
export declare const answerMessageShape: import("object-shape-tester").ShapeDefinition<import("object-shape-tester").ShapeAnd<[import("object-shape-tester").ShapeDefinition<{
/** This UUID is used to keep track of each client on the multiplayer server. */
clientId: import("object-shape-tester").CustomSpecifier<`${string}-${string}-${string}-${string}-${string}`>;
/**
* The id of the room that the user is communicating with. Set this either to to an existing
* room to join that room, or a new id to create a new room.
*/
roomId: import("object-shape-tester").CustomSpecifier<`${string}-${string}-${string}-${string}-${string}`>;
/** The name of the room to create or join. */
roomName: string;
}, false>, import("object-shape-tester").ShapeDefinition<{
/**
* The id of the original message. If a message is ever a response to another message, the
* message id will remain the same throughout the chain.
*/
messageId: import("object-shape-tester").CustomSpecifier<`${string}-${string}-${string}-${string}-${string}`>;
}, false>, {
type: import("object-shape-tester").ShapeExact<readonly [MultiplayerWebSocketMessageType.Answer]>;
/**
* This data object matches the `RTCSessionDescriptionInit` type from the TS lib. This data
* should be passed into `RTCPeerConnection.setRemoteDescription` to accept a WebRTC
* answer.
*/
data: import("object-shape-tester").ShapeOr<[{
rejected: import("object-shape-tester").ShapeExact<readonly [true]>;
}, import("object-shape-tester").ShapeDefinition<{
type: import("object-shape-tester").ShapeExact<readonly [MultiplayerWebSocketMessageType.Answer]>;
sdp: string;
}, false>]>;
}]>, false>;
/**
* Shape definition for "host ping" messages.
*
* @category Internal
*/
export declare const hostPingMessageShape: import("object-shape-tester").ShapeDefinition<import("object-shape-tester").ShapeAnd<[import("object-shape-tester").ShapeDefinition<{
/** This UUID is used to keep track of each client on the multiplayer server. */
clientId: import("object-shape-tester").CustomSpecifier<`${string}-${string}-${string}-${string}-${string}`>;
/**
* The id of the room that the user is communicating with. Set this either to to an existing
* room to join that room, or a new id to create a new room.
*/
roomId: import("object-shape-tester").CustomSpecifier<`${string}-${string}-${string}-${string}-${string}`>;
/** The name of the room to create or join. */
roomName: string;
}, false>, import("object-shape-tester").ShapeDefinition<{
/**
* The id of the original message. If a message is ever a response to another message, the
* message id will remain the same throughout the chain.
*/
messageId: import("object-shape-tester").CustomSpecifier<`${string}-${string}-${string}-${string}-${string}`>;
}, false>, {
type: import("object-shape-tester").ShapeExact<readonly [MultiplayerWebSocketMessageType.HostPing]>;
/** This secret is used to verify that the sender is indeed the host of the current room. */
clientSecret: string;
clientCount: number;
roomPassword: string;
}]>, false>;
/**
* Shape definition for "offer" messages forwarded from the multiplayer server to the host.
*
* @category Internal
*/
export declare const forwardedOfferMessageShape: import("object-shape-tester").ShapeDefinition<import("object-shape-tester").ShapeAnd<[import("object-shape-tester").ShapeDefinition<{
/** This UUID is used to keep track of each client on the multiplayer server. */
clientId: import("object-shape-tester").CustomSpecifier<`${string}-${string}-${string}-${string}-${string}`>;
/**
* The id of the room that the user is communicating with. Set this either to to an existing
* room to join that room, or a new id to create a new room.
*/
roomId: import("object-shape-tester").CustomSpecifier<`${string}-${string}-${string}-${string}-${string}`>;
/** The name of the room to create or join. */
roomName: string;
}, false>, import("object-shape-tester").ShapeDefinition<{
/**
* The id of the original message. If a message is ever a response to another message, the
* message id will remain the same throughout the chain.
*/
messageId: import("object-shape-tester").CustomSpecifier<`${string}-${string}-${string}-${string}-${string}`>;
}, false>, {
type: import("object-shape-tester").ShapeExact<readonly [MultiplayerWebSocketMessageType.Offer]>;
/**
* This data object matches the `RTCSessionDescriptionInit` type from the TS lib. This data
* should be passed into `RTCPeerConnection.setRemoteDescription` when creating an offer.
*/
data: import("object-shape-tester").ShapeDefinition<{
type: import("object-shape-tester").ShapeExact<readonly [MultiplayerWebSocketMessageType.Offer]>;
sdp: string;
}, false>;
}]>, false>;
/**
* Shape definition for "offer" messages.
*
* @category Internal
*/
export declare const offerMessageShape: import("object-shape-tester").ShapeDefinition<import("object-shape-tester").ShapeAnd<[import("object-shape-tester").ShapeDefinition<import("object-shape-tester").ShapeAnd<[import("object-shape-tester").ShapeDefinition<{
/** This UUID is used to keep track of each client on the multiplayer server. */
clientId: import("object-shape-tester").CustomSpecifier<`${string}-${string}-${string}-${string}-${string}`>;
/**
* The id of the room that the user is communicating with. Set this either to to an existing
* room to join that room, or a new id to create a new room.
*/
roomId: import("object-shape-tester").CustomSpecifier<`${string}-${string}-${string}-${string}-${string}`>;
/** The name of the room to create or join. */
roomName: string;
}, false>, import("object-shape-tester").ShapeDefinition<{
/**
* The id of the original message. If a message is ever a response to another message, the
* message id will remain the same throughout the chain.
*/
messageId: import("object-shape-tester").CustomSpecifier<`${string}-${string}-${string}-${string}-${string}`>;
}, false>, {
type: import("object-shape-tester").ShapeExact<readonly [MultiplayerWebSocketMessageType.Offer]>;
/**
* This data object matches the `RTCSessionDescriptionInit` type from the TS lib. This data
* should be passed into `RTCPeerConnection.setRemoteDescription` when creating an offer.
*/
data: import("object-shape-tester").ShapeDefinition<{
type: import("object-shape-tester").ShapeExact<readonly [MultiplayerWebSocketMessageType.Offer]>;
sdp: string;
}, false>;
}]>, false>, import("object-shape-tester").ShapeDefinition<{
/**
* The id of the original message. If a message is ever a response to another message, the
* message id will remain the same throughout the chain.
*/
messageId: import("object-shape-tester").CustomSpecifier<`${string}-${string}-${string}-${string}-${string}`>;
}, false>, {
/**
* This secret is used to verify that a client is a host of a room. Do not share this with
* other clients.
*/
clientSecret: string;
/**
* Set this when joining a room with a password or when creating a room to set a room
* password.
*/
roomPassword: string;
}]>, false>;
/**
* Shape definition for "offer result" messages.
*
* @category Internal
*/
export declare const offerResultShape: import("object-shape-tester").ShapeDefinition<import("object-shape-tester").ShapeAnd<[import("object-shape-tester").ShapeDefinition<{
/**
* The id of the original message. If a message is ever a response to another message, the
* message id will remain the same throughout the chain.
*/
messageId: import("object-shape-tester").CustomSpecifier<`${string}-${string}-${string}-${string}-${string}`>;
}, false>, {
type: import("object-shape-tester").ShapeExact<readonly [MultiplayerWebSocketMessageType.OfferResult]>;
hostClientId: import("object-shape-tester").CustomSpecifier<`${string}-${string}-${string}-${string}-${string}`>;
}]>, false>;
/**
* Shape definition for error messages.
*
* @category Internal
*/
export declare const errorMessageShape: import("object-shape-tester").ShapeDefinition<import("object-shape-tester").ShapeAnd<[import("object-shape-tester").ShapeDefinition<{
/**
* The id of the original message. If a message is ever a response to another message, the
* message id will remain the same throughout the chain.
*/
messageId: import("object-shape-tester").CustomSpecifier<`${string}-${string}-${string}-${string}-${string}`>;
}, false>, {
type: import("object-shape-tester").ShapeExact<readonly [MultiplayerWebSocketMessageType.Error]>;
errorMessage: string;
}]>, false>;