Class: Pilot

socket/Pilot~Pilot(clientEmitter, namespace)

Pilot

Constructor

new Pilot(clientEmitter, namespace)

Defines a base pilot for all pilots.

A Pilot is designed to interact with sockets' clients. It listens to sockets' messages by listening to its associated client emitter. It sends information to sockets' clients using its associated socket namespace.

A Pilot keeps a list of connected clients with associated sockets.

Parameters:
Name Type Description
clientEmitter module:emitters/AdvancedEmitter~AdvancedEmitter

The clients' emitter

namespace module:socket/SocketNamespace~SocketNamespace

The clients' namespace

Source:

Members

(readonly) clientEmitter :module:emitters/AdvancedEmitter~AdvancedEmitter

The emitter to receive sockets' messages from clients.

Type:
Source:

(readonly) clients :Array

The list of actually connected clients.

Type:
  • Array
Source:

(readonly) namespace :module:socket/SocketNamespace~SocketNamespace

The sockets' namespace to communicate with clients.

Type:
Source:

Methods

addClient(id, socket)

Adds a client to the list of connected clients.

Parameters:
Name Type Description
id String

The client's id

socket Socket

The client's associated socket

Source:

emitMessageAsIs(name, …argsopt)

Emits a message.

Alias of events.EventEmitter.emit method.

Parameters:
Name Type Attributes Description
name String

The event's name

args * <optional>
<repeatable>

Any number of arguments

Source:
Example
this.emitMessageAsIs('message', 'value1', 'value2');

// is equivalent to :
this.emit('message', 'value1', 'value2');

emitMessageWithId(…argsopt, socket, callback)

Emits a message replacing socket by the associated client's id.

Parameters:
Name Type Attributes Description
args * <optional>
<repeatable>

Any number of arguments

socket Socket

The socket

callback function

The function to call to respond to the client

Source:
Example
this.emitMessageWithId('message', 'value1', socket, callback);

// is equivalent to :
this.emit('message', 'value1', socket.id, callback);

getClient(id) → {Object|Null}

Gets a connected client by its id.

Parameters:
Name Type Description
id String

The client id

Source:
Returns:

The client or null if not found

Type
Object | Null

getClientBySocketId(socketId) → {Object|Null}

Gets a client by its associated socket id in the list of connected clients.

Parameters:
Name Type Description
socketId String

The socket id

Source:
Returns:

The client or null if not found

Type
Object | Null

removeClientBySocketId(id) → {Object|Null}

Removes a client, by its associated socket id, from the list of connected clients.

Parameters:
Name Type Description
id String

The socket id

Source:
Returns:

The removed client or null if not found

Type
Object | Null