ziron-server
Version:
137 lines (136 loc) • 5.3 kB
TypeScript
import EventEmitter from "emitix";
import Server from "./Server";
import { Transport, InvokeListener, TransmitListener, ComplexTypesOption } from "ziron-engine";
import { SignOptions } from "jsonwebtoken";
import UpgradeRequest from "./http/UpgradeRequest";
import { Procedures } from "./Procedure";
import { Receivers } from "./Receiver";
import { CustomWebSocket } from "./CustomWebSocket";
type LocalEventEmitter = EventEmitter<{
'error': [Error];
'warning': [Error];
'disconnect': [number | undefined, any];
'authTokenChange': [object | null, object | null];
}>;
export default class Socket {
readonly id: string;
readonly open: boolean;
readonly signedAuthToken: string | null;
readonly authToken: any | null;
readonly authenticated: boolean;
private setAuth;
private readonly _emitter;
readonly once: LocalEventEmitter['once'];
readonly on: LocalEventEmitter['on'];
readonly off: LocalEventEmitter['off'];
private readonly _emit;
readonly procedures: Procedures;
/**
* @description
* Will be called whenever no corresponding Procedure was found.
* Can be overridden.
*/
onUnknownInvoke: InvokeListener;
readonly receivers: Receivers;
/**
* @description
* Will be called whenever no corresponding Receiver was found.
* Can be overridden.
*/
onUnknownTransmit: TransmitListener;
private readonly _server;
readonly upgradeRequest: UpgradeRequest;
/**
* @description
* The client's attachment to the upgrade request
* while doing the handshake.
*/
get handshakeAttachment(): any;
readonly remoteAddress: string;
/**
* @description
* Either 4 or 6.
*/
readonly remoteFamily: number;
readonly subscriptions: ReadonlyArray<string>;
private readonly _transport;
constructor(server: Server<any, any>, socket: CustomWebSocket);
readonly transmit: Transport['transmit'];
readonly invoke: Transport['invoke'];
readonly sendPackage: Transport['sendPackage'];
readonly flushBuffer: Transport['buffer']['flushBuffer'];
readonly getBufferSize: Transport['buffer']['getBufferSize'];
bufferedSendAmount(): number;
private _cork;
private _sendRaw;
private _clearListener;
private _blockSocketInteractions;
private _destroy;
isAuthTokenExpired(): boolean;
deauthenticate(): void;
authenticate(payload: Record<string, any>, options?: SignOptions): Promise<void>;
disconnect(code?: number, message?: string): void;
/**
* @description
*/
hasLowSendBackpressure(): boolean;
private _handleAuthenticateInvoke;
private _onInvoke;
private _onTransmit;
kickOut(channel: string, data?: any): void;
private _handleSubscribeInvoke;
private _handleUnsubscribeTransmit;
private _unsubscribeAll;
private _handleClientPublishInvoke;
private _handleClientPublishTransmit;
/**
* @description
* Publishes in a channel with this socket as a publisher.
* @param channel
* @param data
* @param processComplexTypes
*/
publish(channel: string, data?: any, { processComplexTypes }?: ComplexTypesOption): void;
/**
* @description
* Join a group.
* Let the socket join a group that follows the pub/sub mechanism.
* Instead of channels, groups can only be accessed and controlled from the server-side and
* messages are not shared across multiple server instances.
* Groups don't have their own special protocol and can be used to send a standard
* transmit optimized to multiple sockets of a group.
* Additionally, the group transmits support batching when not using the skipMember option.
* Internally prepareMultiTransmit is used to create the transmit packet,
* so binary data is supported.
* @param group
*/
join(group: string): boolean;
/**
* @description
* Returns if the socket has joined the group.
* Instead of channels, groups can only be accessed and controlled from the server-side and
* messages are not shared across multiple server instances.
* Groups don't have their own special protocol and can be used to send a standard
* transmit optimized to multiple sockets of a group.
* Additionally, the group transmits support batching when not using the skipMember option.
* Internally prepareMultiTransmit is used to create the transmit packet,
* so binary data is supported.
* @param group
*/
hasJoined(group: string): boolean;
/**
* @description
* Leaves a group.
* Let the socket leave a group that follows the pub/sub mechanism.
* Instead of channels, groups can only be accessed and controlled from the server-side and
* messages are not shared across multiple server instances.
* Groups don't have their own special protocol and can be used to send a standard
* transmit optimized to multiple sockets of a group.
* Additionally, the group transmits support batching when not using the skipMember option.
* Internally prepareMultiTransmit is used to create the transmit packet,
* so binary data is supported.
* @param group
*/
leave(group: string): boolean;
}
export {};