Throttle
These events relate to controlling various aspects of locomotives, from speed to track power.
Server to client events
throttle/speedUpdate
Update
Parameters
identifier
string | number - Either the name or id of the locospeed
number - The new speed that has been setsocketID
string - The id of the socket that thethrottle/setSpeed
originated from
Response to: throttle/setSpeed
Used to inform the client that a loco's speed has changed. It's recommended to compare socketID to the ID of the client's socket and ignore any updates where these match as this means the message originated from the client. This prevents problems occurring due to the slight delay of the server, especially if a slider is being used for speed. If the update originated due to an event other than throttle/setSpeed
then socketID
will be a blank string.
throttle/directionUpdate
Update
Parameters
identifier
string | number - Either the name or id of the locodirection
Direction - The new direction that has been set, seeDirection
socketID
string - The id of the socket that thethrottle/setDirection
originated from
Response to: throttle/setDirection
Used to inform the client that a loco's direction has changed. It's not normally necessary to compare socketID to the ID of the client's socket and ignore any updates where these match as this means the message originated from the client. However, if your client will be changing the direction of a loco very quickly in succession then it may be helpful to check this property like with speed. If the update originated due to an event other than throttle/setSpeed
then socketID
will be a blank string.
throttle/functionUpdate
Update
Parameters
identifier
string | number - Either the name or id of the locofunctionNum
number - The number of the function that has been setstate
boolean - The state the function has been set tosocketID
string - The id of the socket that thethrottle/setFunction
originated from
Response to: throttle/setFunction
Used to inform the client that a loco's function has changed state. It's not normally necessary to compare socketID to the ID of the client's socket and ignore any updates where these match as this means the message originated from the client. However, if your client will be changing the function of a loco very quickly in succession then it may be helpful to check this property like with speed. If the update originated due to an event other than throttle/setSpeed
then socketID
will be a blank string.
throttle/trackPowerUpdate
Update
Parameters
state
boolean - The state the track power has been set tosocketID
string - The id of the socket that thethrottle/setTrackPower
originated from
Response to: throttle/setTrackPower
Used to inform the client that the track power has. It's not normally necessary to compare socketID to the ID of the client's socket and ignore any updates where these match as this means the message originated from the client. However, if your client will be changing the track power very quickly in succession then it may be helpful to check this property like with speed. If the update originated due to an event other than throttle/setSpeed
then socketID
will be a blank string.
Client to server events
throttle/setSpeed
Setter
Parameters
identifier
string | number - Either the name or id of the locospeed
number - The new speed to set
Response: throttle/speedUpdate
This command is used to set a loco to a specific speed.
throttle/setDirection
Setter
Parameters
identifier
string | number - Either the name or id of the locodirection
Direction - The new direction to set, seeDirection
Response: throttle/directionUpdate
This command is used to set a loco to a specific direction. The direction
property takes an enum with three different values, forwards, stopped and backwards which describes the direction to set. A value of stopped will cause an emergency stop.
throttle/setFunction
Setter
Parameters
identifier
string | number - Either the name or id of the locofunctionNum
number - The number of the function to setstate
boolean - The state to set the function to
Response: throttle/functionUpdate
This command is used to set a loco's function to a different state. The functionNum
is the function number to set, eg if you wanted to set F6 to on for a loco with the id of 3 you would do as following:
socket.emit('throttle/setFunction', 3, 6, true);
throttle/setTrackPower
Setter
This command sets the track power to either on or off, true for on and false for off.