Add missing methods of SCServerSocket. (#32589)

Also updates and fixes some properties missing in SCServer.
This commit is contained in:
Daniel Rose
2019-01-29 19:51:16 +01:00
committed by Ryan Cavanaugh
parent 180f90a377
commit cc2043909f
2 changed files with 58 additions and 4 deletions

View File

@@ -3,7 +3,7 @@ import { Secret } from "jsonwebtoken";
import { ServerOptions } from "https";
import { IncomingMessage, Server } from "http";
import { SCAuthEngine } from "sc-auth";
import { SCExchange } from "sc-broker-cluster";
import { SCExchange, Client } from "sc-broker-cluster";
import WebSocket = require("ws");
import SCServerSocket = require("./scserversocket");
@@ -18,6 +18,7 @@ declare class SCServer extends EventEmitter {
readonly MIDDLEWARE_EMIT: "emit";
options: SCServer.SCServerOptions;
brokerEngine: Client;
exchange: SCExchange;
clients: {
@@ -58,7 +59,10 @@ declare class SCServer extends EventEmitter {
removeMiddleware(type: "emit", middlewareFn: (req: SCServer.EmitRequest, next: SCServer.nextMiddlewareFunction) => void): void;
setAuthEngine(authEngine: SCAuthEngine): void;
auth: SCAuthEngine;
setCodecEngine(codecEngine: SCServer.SCCodecEngine): void;
codec: SCServer.SCCodecEngine;
close(cb?: (err?: Error) => void): void;
@@ -348,7 +352,7 @@ declare namespace SCServer {
interface SCCodecEngine {
decode: (input: any) => any;
ncode: (object: any) => any;
encode: (object: any) => any;
}
interface VerifyHandshakeInfo {

View File

@@ -29,15 +29,65 @@ declare class SCServerSocket extends Emitter {
constructor(id: string, server: SCServer, socket: WebSocket);
on(event: "error", listener: (error: Error) => void): this;
on(event: "message" | "raw", listener: (message: WebSocket.Data) => void): this;
on(event: "connectAbort" | "disconnect" | "close", listener: (code: number, data?: any) => void): this;
on(event: "authStateChange", listener: (stateChangeData: SCServerSocket.StateChangeData) => void): this;
on(event: "authenticate", listener: (authToken?: SCServer.AuthToken) => void): this;
on(event: "deauthenticate", listener: (oldToken?: SCServer.AuthToken) => void): this;
getState(): "connecting" | "open" | "closed";
getBytesReceived(): number;
disconnect(code?: number, data?: any): void;
destroy(code?: number, data?: any): void;
terminate(): void;
send(data: any, options: { mask?: boolean; binary?: boolean; compress?: boolean; fin?: boolean }): void;
decode(message: any): any;
encode(object: any): any;
sendObjectBatch(object: any): void;
sendObjectSingle(object: any): void;
sendObject(object: any, options?: { batch?: boolean }): void;
emit(event: string, ...args: any[]): boolean;
emit(event: string, data: any, callback?: SCServerSocket.EmitCallback, options?: SCServerSocket.EmitOptions): void;
triggerAuthenticationEvents(oldState: "authenticated" | "unauthenticated"): void;
getAuthToken(): SCServer.AuthToken;
setAuthToken(data: SCServer.AuthToken, options?: SignOptions): void;
deauthenticate(): void;
setAuthToken(data: SCServer.AuthToken, options?: SignOptions, callback?: SCServerSocket.EmitCallback): void;
deauthenticateSelf(): void;
deauthenticate(callback?: SCServerSocket.EmitCallback): void;
kickOut(channel?: string, message?: string, callback?: () => void): void;
subscriptions(): string[];
isSubscribed(channel?: string): boolean;
}
export = SCServerSocket;
declare namespace SCServerSocket {
type EmitCallback = (err: Error, eventObject: EventObject) => void;
interface EventObject {
event: string;
data?: any;
cid?: number;
}
interface EmitOptions {
useCache?: boolean;
stringifiedData?: string;
}
interface StateChangeData {
oldState: "authenticated" | "unauthenticated";
newState: "authenticated" | "unauthenticated";
authToken?: SCServer.AuthToken;
}
}