Socket
socket module built with socket.io
#
Installation#
Optionskey | 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
#
SocketControllerwill 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
#
HooksonInitialized
- 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
#
MiddlewareMiddleware can be used before socket connect
#
SocketProviderholds 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