chatRoom

api. chatRoom

Source:
Properties:
Name Type Description
middleware Object

Dictionary of loaded middleware modules.

globalMiddleware Array

Array of global middleware modules.

messageChannel string

The redis pub/sub channel for chat communication.

keys Object

Stores the base keys for stats about the chat system (rooms & members).

Chat & Realtime Communication Methods

Extends

Methods

(async, static) add(room) → {Promise}

Source:
See:

Add a new chat room. Throws an error if the room already exists.

Parameters:
Name Type Description
room string

The name of the room

Returns:
Type
Promise

(async, static) addMember(connectionId, room) → {Promise.<Boolean>}

Source:
See:

Add a connection (via id) to a rooom. Throws errors if the room does not exist, or the connection is already in the room. Middleware errors also throw.

Parameters:
Name Type Description
connectionId string

An existing connection's ID

room srting

The name of the room.

Returns:
Type
Promise.<Boolean>

(static) addMiddleware(data)

Source:
See:

Add a middleware component to connection handling.

Parameters:
Name Type Description
data object

The middleware definition to add.

(async, static) broadcast(connection, room, message) → {Promise}

Source:

Send a message to all members of a chat room. This is used by the server.

Parameters:
Name Type Description
connection Object

The connection sending the message. If the message is coming from the sever, a proxy like {rooms ['thisRoom'], id: 0} would work.

room string

The name of the room.

message Object | Array | Stting

The message

Returns:
Type
Promise

(async, static) destroy(room) → {Promise}

Source:
See:

Remove an exsitng chat room. All connections in the room will be removed. Throws an error if the room does not exist.

Parameters:
Name Type Description
room string

The name of the room

Returns:
Type
Promise

(async, static) exists(room) → {Promise.<Boolean>}

Source:

Check if a room exists.

Parameters:
Name Type Description
room string

The name of the room

Returns:
Type
Promise.<Boolean>

(static) generateMemberDetails(connection) → {Object}

Source:
See:

An overwritable method which configures what properties of connections in a room are initially stored about a connection when added via api.chatRoom.addMember

Parameters:
Name Type Description
connection Object

A ActionHero.Connection

Returns:

sanitizedConnection The resulting object

Type
Object

(async, static) list() → {Promise.<Array>}

Source:

List all chat rooms created

Returns:

Returns an array of chatRoom names.

Type
Promise.<Array>

(async, static) removeMember(connectionId, room, toWaitRemote) → {Promise.<Boolean>}

Source:
See:

Remote a connection (via id) from a rooom. Throws errors if the room does not exist, or the connection is not in the room. Middleware errors also throw.

Parameters:
Name Type Description
connectionId string

An existing connection's ID

room srting

The name of the room.

toWaitRemote Boolean

Should this method wait until the remote ActionHero server (the one the connection is connected too) responds?

Returns:
Type
Promise.<Boolean>

(async, static) roomStatus(room) → {Promise.<Object>}

Source:

Learn about the connections in the room

Parameters:
Name Type Description
room string

The name of the room

Returns:

Returns a hash of the form { room: room, members: cleanedMembers, membersCount: count }. Members is an array of connections in the room sanitized via api.chatRoom.sanitizeMemberDetails

Type
Promise.<Object>

(static) sanitizeMemberDetails(memberData) → {Object}

Source:
See:

An overwritable method which configures what properties of connections in a room to return via api.chatRoom.roomStatus

Parameters:
Name Type Description
memberData Object

A connection

Returns:

sanitizedMemberDetails The resulting object

Type
Object