Socket
socket module built with socket.io
Installation#
Options#
| key | Description | Type | Default |
|---|---|---|---|
id | SocketProvider injection id | string | socketProvider |
auto | true to auto initialize socket listen events | boolean | true |
redis | redis connection for sockets sync | string | null |
socket | socket options | object | {"transports": ["websocket"]} |
in config/modules/all.ts
SocketController#
will be created on socket new connection and holds the socket instance.
must be inherited from SocketController and defined using @socket.
you can define custom namespace using @socket("someNamespace") default to /.
you subscribe to socket events using @action('someEvent') the return object from the action will be passed to socket callback id exists
promises also supported.
socket client
Hooks#
onInitialized- called when socket initializedonDisconnected- called when socket disconnectedonConnected- called when socket connected
socket#
get socket(): socketIo.Socket#
getter return socket instance
id#
get id(): string#
getter return socket id
send#
send(event: string, data: any)#
emit socket event
Middleware#
Middleware can be used before socket connect
SocketProvider#
holds all the socket controllers. can send messages to all sockets and namespaces
sendToAll#
sendToAll(event: string, data: any)#
event message to all clients
sendToNamespace#
sendToNamespace(namespace: string, event: string, data: any)#
event message to all clients in a namespace
clients#
get clients(): Map<string, SocketController>#
getter Map of all sockets by id