-
Notifications
You must be signed in to change notification settings - Fork 2
Server
Boilerplate for creating and wrapping a server socket listener (TCP or Websocket) under a common interface.
Socket specific functions need to be overridden/implemented.
• new Server(serverOptions)
| Name | Type |
|---|---|
serverOptions |
ServerOptions |
• clients: Client[]
• eventHandlers: Object
▪ [key: string]: Function[]
• isClosed: boolean
• serverOptions: ServerOptions
▸ Protected addClient(client): void
Performs all operations involved in registering a new client connection.
| Name | Type |
|---|---|
client |
Client |
void
▸ close(): void
Close listener and all accepted socket clients.
void
▸ listen(): void
Listens for connections and yields connected client sockets.
void
▸ Private on(event, fn): void
Internal event implementation.
| Name | Type |
|---|---|
event |
string |
fn |
Function |
void
▸ onClose(fn): void
Event handler triggered when server has closed together with all its client sockets.
| Name | Type | Description |
|---|---|---|
fn |
Function |
callback |
void
▸ onConnection(fn): void
Event handler triggered when client has connected.
A Client object is passed as argument to fn() of the instance type this.SocketClass.
| Name | Type | Description |
|---|---|---|
fn |
Function |
callback |
void
▸ onError(fn): void
Event handler triggered when a server error occurs.
An error object is passed as argument to fn().
| Name | Type | Description |
|---|---|---|
fn |
Function |
callback |
void
▸ Private removeClient(client): void
Performs all operations involved in removing an existing client registration.
| Name | Type |
|---|---|
client |
Client |
void
▸ Protected serverClose(): void
Close the server. Override as necessary.
void
▸ Protected serverClosed(): void
Internal close event implementation.
void
▸ Protected serverCreate(): void
Create the server socket.
void
▸ Protected serverError(err): void
Internal error event implementation.
| Name | Type |
|---|---|
err |
any |
void
▸ Protected serverListen(): void
Initiate the server listener.
void
▸ Private triggerEvent(event, data?): void
Internal event trigger implementation.
| Name | Type |
|---|---|
event |
string |
data? |
any |
void