Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface ChatMiddleware

Middleware definition for processing chat events. Can be of the

 var chatMiddleware = {
   name: 'chat middleware',
   priority: 1000,
   join: (connection, room) => {
     // announce all connections entering a room
     api.chatRoom.broadcast({}, room, 'I have joined the room: ' + connection.id, callback)
   },
   leave:(connection, room, callback) => {
     // announce all connections leaving a room
     api.chatRoom.broadcast({}, room, 'I have left the room: ' + connection.id, callback)
   },
   // Will be executed once per client connection before delivering the message.
   say: (connection, room, messagePayload) => {
     // do stuff
     log(messagePayload)
   },
   // Will be executed only once, when the message is sent to the server.
   onSayReceive: (connection, room, messagePayload) => {
     // do stuff
     log(messagePayload)
   }
}
api.chatRoom.addMiddleware(chatMiddleware)

Hierarchy

  • ChatMiddleware

Index

Properties

Optional join

join: Function

Called when a connection joins a room.

Optional leave

leave: Function

Called when a connection leaves a room.

name

name: string

Unique name for the middleware.

Optional onSayReceive

onSayReceive: Function

Called when a connection says a message to a room.

Optional priority

priority: number

Module load order. Defaults to api.config.general.defaultMiddlewarePriority.

Optional say

say: Function

Called when a connection is about to receive a say message.

Generated using TypeDoc