Throttle
These events relate to controlling various aspects of locomotives, from speed to track power.
Server to client events
throttle/speedUpdate Update
Parameters
identifierstring | number - Either the name or id of the locospeednumber - The new speed that has been setsocketIDstring - The id of the socket that thethrottle/setSpeedoriginated 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
identifierstring | number - Either the name or id of the locodirectionDirection - The new direction that has been set, seeDirectionsocketIDstring - The id of the socket that thethrottle/setDirectionoriginated 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
identifierstring | number - Either the name or id of the locofunctionNumnumber - The number of the function that has been setstateboolean - The state the function has been set tosocketIDstring - The id of the socket that thethrottle/setFunctionoriginated 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
stateboolean - The state the track power has been set tosocketIDstring - The id of the socket that thethrottle/setTrackPoweroriginated 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
identifierstring | number - Either the name or id of the locospeednumber - The new speed to set
Response: throttle/speedUpdate
This command is used to set a loco to a specific speed.
throttle/setDirection Setter
Parameters
identifierstring | number - Either the name or id of the locodirectionDirection - 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
identifierstring | number - Either the name or id of the locofunctionNumnumber - The number of the function to setstateboolean - 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.