Class: Command

Command(messageID, name, params)

A command is a request from the client to run a series of remote end steps and return a fitting response.

The command can be synthesised from the message passed over the Marionette socket using the fromPacket function. The format of a message is:

    [type, id, name, params]

where

type (integer)
Must be zero (integer). Zero means that this message is a command.
id (integer)
Integer used as a sequence number. The server replies with the same ID for the response.
name (string)
String representing the command name with an associated set of remote end steps.
params (JSON Object or null)
Object of command function arguments. The keys of this object must be strings, but the values can be arbitrary values.

A command has an associated message id that prevents the dispatcher from sending responses in the wrong order.

The command may also have optional error- and result handlers that are called when the client returns with a response. These are function onerror({Object}), function onresult({Object}), and function onresult({Response}):

Constructor

new Command(messageID, name, params)

Parameters:
Name Type Description
messageID number

Message ID unique identifying this message.

name string

Command name.

params Object.<string, ?>

Command parameters.

Source:

Methods

(static) fromPacket(data) → {Command}

Converts a data packet into Command.

Parameters:
Name Type Description
data Array.<number, number, ?, ?>

A four element array where the elements, in sequence, signifies message type, message ID, command name, and parameters.

Source:
Throws:

If the message type is not recognised.

Type
TypeError
Returns:

Representation of packet.

Type
Command

onresponse(resp)

Calls the error- or result handler associated with this command. This function can be replaced with a custom response handler.

Parameters:
Name Type Description
resp Response

The response to pass on to the result or error to the onerror or onresult handlers to.

Source:

toPacket() → {Array}

Encodes the command to a packet.

Source:
Returns:

Packet.

Type
Array