Pilot
Summary
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.
Constructor
Pilot
Syntax
Pilot
-
clientEmitter -
namespace
Summary
Parameters:
-
clientEmitterAdvancedEmitterThe clients' emitter
-
namespaceSocketNamespaceThe clients' namespace
Item Index
Methods
Properties
Methods
addClient
Syntax
addClient
-
id -
socket
Summary
Adds a client to the list of connected clients.
Parameters:
-
idStringThe client's id
-
socketSocketThe client's associated socket
emitMessageAsIs
Syntax
emitMessageAsIs
-
name -
[args]
Summary
Emits a message.
Alias of events.EventEmitter.emit method.
Parameters:
-
nameStringThe event's name
-
[args]Mixed optional multipleAny number of arguments
Example:
this.emitMessageAsIs('message', 'value1', 'value2');
// is equivalent to :
this.emit('message', 'value1', 'value2');
emitMessageWithId
Syntax
emitMessageWithId
-
[args] -
socket -
callback
Summary
Emits a message replacing socket by the associated client's id.
Parameters:
-
[args]Mixed optional multipleAny number of arguments
-
socketSocketThe socket
-
callbackFunctionThe function to call to respond to the client
Example:
this.emitMessageWithId('message', 'value1', socket, callback);
// is equivalent to :
this.emit('message', 'value1', socket.id, callback);
getClient
Syntax
Summary
Gets a connected client by its id.
Parameters:
-
idStringThe client id
Returns:
The client or null if not found
Properties
clientEmitter
Syntax
Summary
The emitter to receive sockets' messages from clients.
namespace
Syntax
Summary
The sockets' namespace to communicate with clients.