A node.js client library for krpc. Allows you to send commands to Kerbal Space Program from node.
JavaScript to space via krpc!
Client
Services:
- SpaceCenter - Main api for controlling KSP.
- UI - Api for interacting with user interface elements.
- InfernalRobotics - Api for interacting with the Infernal Robotics mod.
- KerbalAlarmClock - Api for interacting with the Kerbal Alarm Clock mod.
- RemoteTech - Api for interacting with the Remote Tech mod.
- Drawing - Api for for drawing objects in the flight scene.
- KRPC - Api for interacting with the kRPC server.
Examples:
- Examples - Some practical examples to get you started.
Create a new krpc-node client
Parameters
optionsobject The options used to create the clientoptions.protocolstring ="ws" - The protocol to use to connect to the server. ws or wss.options.hoststring ="127.0.0.1" - The host address of the server.options.port(string | number) ="50000" - The port number on which to connect to the server.options.wsProtocols[(string | Array<string>)] WebSocket protocols.options.wsOptions[object] Additional connection options.
callbackfunction The function called once the client has been created.
Callback Parameters
errError The error object if there was a problem creating the client, otherwise null.clientClient The client to use for subsequent calls.
Examples
let util = require('util');
let Client = require('krpc-node');
let options = null;
Client(options, clientCreated);
function clientCreated(err, client) {
if(err){
throw err;
}
console.log(util.format('Connection Opened'));
client.send(client.services.krpc.getClients(), getClientsCompleted);
}
function getClientsCompleted(err, response){
if(err){
throw err;
}
expect(response.error).to.not.be.ok();
expect(response.results.length).to.equal(1);
let result = response.results[0];
expect(result.error).to.not.be.ok();
result.value.items.forEach(function (item) {
expect(item).to.be.ok();
console.log(item);
});
}An instance of the Client class
Properties
callbackStackArray<function> An ordered array of callback functions to call when responses are received.decodeStackArray<function> An ordered array of decode functions to call when responses are received.rpcobject Contains items related to communicating directly with the server.rpc.socketWebSocket The underlying websocket instance used to communicate with the server.rpc.emitterEventEmitter The emitter that handles events.rpc.onfunction Registers for one of the events for messages from the server [open, message, error, close].
sendfunction Sends one or more calls to the server to processservicesobject The collection of services that can be called. Each function within a service will return a procedureCall object.services.drawingobject Provides functionality for drawing objects in the flight scene. For drawing and interacting with the user interface, see the UI service.services.infernalRoboticsobject This service provides functionality to interact with Infernal Robotics.services.kerbalAlarmClockobject This service provides functionality to interact with Kerbal Alarm Clock.services.krpcobject Main kRPC service, used by clients to interact with basic server functionality.services.remoteTechobject This service provides functionality to interact with RemoteTech.services.spaceCenterobject Provides functionality to interact with Kerbal Space Program. This includes controlling the active vessel, managing its resources, planning maneuver nodes and auto-piloting.services.uiobject Provides functionality for drawing and interacting with in-game user interface elements. For drawing 3D objects in the flight scene, see the Drawing service.
encodersobject The raw encoders that can be used to manually encode values.decodersobject The raw decoders that can be used to manually decode values.streamsobject The list of registered stream responses and how to decode themstreamStateobject The last known values of the result returned from the streams.connectToStreamServerfunction Establishes a separate connection to the stream server.addStreamfunction Adds a single call to the stream communication. Make sure you call connectToStreamServer fist.removeStreamfunction Removes a single call from the stream communication. Make sure you call connectToStreamServer and of course have called addStream fist.streamobject Contains items related to communicating with the stream server.stream.socketWebSocket The underlying websocket instance used to communicate with the server.stream.emitterEventEmitter The emitter that handles events.stream.onfunction Registers for one of the events for messages from the server [open, message, error, close].
Registers for one of the events [open, message, error, close].
Parameters
eventNamestring The event to register for [open, message, error, close].fnfunction The function to execute when an event happens
Sends one or more calls to the server to process
Parameters
calls(procedureCall | Array<procedureCall>) One or more calls to send to the server.callbackfunction The function called once the client has been created.
Callback Parameters
errError The error object if there was a problem creating the client, otherwise null.responseObject The client response object.
A procedure call with a decode function an a procedure object to send to the server
Properties
decodefunction The function used to decode the response from the server.callobject The actual call + arguments to send to the server to execute.
Adds an call to the continuous update stream.
Parameters
callprocedureCall One or more calls to send to the server.propertyPathprocedureCall The lodash set path to use to set the result of the stream call onclient.streamState.callbackfunction The function called once the stream has been added.
Callback Parameters
errError The error object if there was a problem creating the client, otherwise null.streamObject The stream object.
Removes a call from the continuous update stream.
Parameters
propertyPathprocedureCall The lodash set path to used to set the result of the stream call onclient.streamState.callbackfunction The function called once the stream has been added.
Callback Parameters
errError The error object if there was a problem creating the client, otherwise null.
Checkout the examples repository for some practical examples.
