Skip to content

i_en_app

huangjizhong edited this page Dec 1, 2021 · 3 revisions

Application Class

appName

appName: string

  • Application Name

base

readonly base: string

  • Root path

env

readonly env: string

  • Startup environment

serverId

readonly serverId: string

  • Server id

serverType

readonly serverType: string

  • Server type

serverInfo

readonly serverInfo: ServerInfo

  • The configuration of this server

routeConfig

readonly routeConfig: string[]

  • configuration:route.ts

masterConfig

readonly masterConfig: ServerInfo

  • configuration:master.ts

serversConfig

readonly serversConfig: { [serverType: string]: ServerInfo[] }

  • configuration:servers.ts

startTime

readonly startTime: number

  • Server start time

clientNum

readonly clientNum: number

  • The number of all socket connections (frontend server call)

start()

start(): void

  • Start the server

rpc()

rpc(serverId: string): Rpc

  • rpc call, callback form

rpcAwait()

rpcAwait(serverId: string, notify?: boolean): Rpc

  • rpc call,await form
  • notify indicates whether it is a notification message (default false)

setConfig()

setConfig(key: string, value: any): void

set()

set<T = any>(key: string | number, value: T): T

  • Set key-value pairs

get()

get<T = any>(key: string | number): T

  • Get key-value pairs

delete()

delete(key: string | number): void

  • Delete key-value pairs

getServersByType()

getServersByType(serverType: string): ServerInfo[]

  • Get a certain type of server

getServerById()

getServerById(serverId: string): ServerInfo

  • Get a server

route()

route(serverType: string, routeFunc: (session: Session) => string): void

  • Routing configuration (frontend server call)

getSession()

getSession(uid: number): Session

  • Get client session by uid(frontend server call)

getAllClients()

getAllClients(): { [uid: number]: I_clientSocket }

  • Get all clients of this server(frontend server call)

sendMsgByUid()

sendMsgByUid(cmd: number, msg: any, uids: number[]): void

  • Send a message to the client (frontend server call)

sendAll()

sendAll(cmd: number, msg: any): void

  • Send a message to all clients of this server (frontend server call)

sendMsgByUidSid()

sendMsgByUidSid(cmd: number, msg: any, uidsid: { "uid": number, "sid": string }[]): void

  • Send a message to the client (backend server call)

sendMsgByGroup()

sendMsgByGroup(cmd: number, msg: any, group: { [sid: string]: number[] }): void

  • Send a message to the client (backend server call)

configure()

configure(serverType: string, cb: () => void): void

  • Configure server execution function

on()

on(event: "onAddServer" | "onRemoveServer", cb: (serverInfo: ServerInfo) => void): void

  • Monitor events (add server, remove server)

server information

interface ServerInfo {
    /**
     * Server id
     */
    readonly "id": string;
    /**
     * host
     */
    readonly "host": string;
    /**
     * port
     */
    readonly "port": number;
    /**
     * Is it a frontend server
     */
    readonly "frontend": boolean;
    /**
     * clientPort
     */
    readonly "clientPort": number;
    /**
     * Server type [Note: Assigned by the framework]
     */
    readonly "serverType": string;

    [key: string]: any;
}