Constructor
new ChatService(optionsopt, hooksopt)
Crates an object and starts a new service instance. The chat-service.ChatService#close
method MUST be called before
the node process exits.
Examples
let ChatService = require('chat-service')
let service = new ChatService(options, hooks)
let owner = 'admin'
let whitelistOnly = true
let whitelist = [ 'user' ]
let state = { owner, whitelistOnly, whitelist }
chatService.addRoom('someRoom', state).then(fn)
let room = 'someRoom'
let msg = { textMessage: 'some message' }
let context = {
userName: 'system',
bypassPermissions: true
}
chatService.execUserCommand(context, 'roomMessage', room, msg)
.then(fn)
let room = 'someRoom'
let context = {
userName: 'user',
id: id // socket id
}
chatService.execUserCommand(context, 'roomJoin', room)
.then(fn) // real sockets will get a notification
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
options |
chat-service.config.options |
<optional> |
Service configuration options. |
hooks |
chat-service.hooks.HooksInterface |
<optional> |
Service customisation hooks. |
Fires:
Extends
- EventEmitter
Members
(static, readonly) ChatServiceError :Class
ChatService errors constructor. This errors are intended to be returned to clients as a part of a normal service functioning (something like 403 errors). Can be also used to create custom errors subclasses.
Type:
- Class
(readonly) clusterBus :EventEmitter
Cluster communication via an adapter. Emits messages to all services nodes, including the sender node.
Type:
- EventEmitter
(readonly) instanceUID :string
Service instance UID.
Type:
- string
(readonly) transport :chat-service.TransportInterface
Transport object.
Type:
Methods
checkArguments(name, …args, cbopt) → {Promise.<undefined>}
Exposes an internal arguments validation method, it is run automatically by all client request (command) handlers.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
name |
string | Command name. |
|
args |
* |
<repeatable> |
Command arguments. |
cb |
callback |
<optional> |
Optional callback. |
Returns:
Promise that resolves without any data if validation is successful, otherwise a promise is rejected.
- Type
- Promise.<undefined>
close(cbopt) → {Promise.<undefined>}
Closes server.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
cb |
callback |
<optional> |
Optional callback. |
Returns:
Promise that resolves without any data.
- Type
- Promise.<undefined>
Events
closed
Service is closed, state and transport are closed.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
error |
Error |
<optional> |
If was closed due to an error. |
lockTimeExceeded
Properties:
Name | Type | Attributes | Description |
---|---|---|---|
lockInfo.userName |
string |
<optional> |
User name. |
lockInfo.roomName |
string |
<optional> |
Room name. |
Lock was hold longer than a lock ttl.
Parameters:
Name | Type | Description |
---|---|---|
id |
string | Lock id. |
lockInfo |
Object | Lock resource details. |
ready
Service is ready, state and transport are up.
storeConsistencyFailure
Properties:
Name | Type | Attributes | Description |
---|---|---|---|
operationInfo.userName |
string | User name. |
|
operationInfo.opType |
string | Operation type. |
|
operationInfo.roomName |
string |
<optional> |
Room name. |
operationInfo.id |
string |
<optional> |
Socket id. |
State store failed to be updated to reflect an user's connection or presence state.
Parameters:
Name | Type | Description |
---|---|---|
error |
Error | Error. |
operationInfo |
Object | Operation details. |
transportConsistencyFailure
Properties:
Name | Type | Attributes | Description |
---|---|---|---|
operationInfo.userName |
string | User name. |
|
operationInfo.opType |
string | Operation type. |
|
operationInfo.roomName |
string |
<optional> |
Room name. |
operationInfo.id |
string |
<optional> |
Socket id. |
Failed to teardown a transport connection.
Parameters:
Name | Type | Description |
---|---|---|
error |
Error | Error. |
operationInfo |
Object | Operation details. |