Steam for Node.js
This is a fork of node-steam's SteamClient. Essentially it's node-steam without the handler modules and with some more features. It should be compatible with all node-steam handler modules, as long as the underlying Steam protocol doesn't change without a third-party module's knowledge.
This exists because of how painfully slow it is to get new things implemented into node-steam, and also because of incompatibilities that can potentially arise between node-steam and third-party handler modules.
Protocol version bumps will always be major module releases. You're highly recommended to pin the major version in your
Requires Node.js v4.1.1 or later.
$ npm install steam-client
require this module.
var Steam = ;
Steam is now a namespace object containing:
Then you'll want to create an instance of CMClient and any handlers you need (externally), call
SteamClient#connect and assign event listeners. Some handlers, such as
node-steam-user do this automatically for you.
var steamClient = ;steamClient;steamClient;steamClient;
The constructor takes one argument: the protocol to use to connect to Steam. This should be a value from
Default is TCP. UDP support is experimental. There are some pros and cons to each:
- Pro: Operating system manages the connection, so you will automatically disconnect if your app crashes or is killed
- Con: Less fine control over the connection. It's up to the OS to detect poor network conditions and kill the connection
- Pro: Finer control over the connection. Able to tear down a broken connection faster in cases where the OS wouldn't detect it
- Pro: Gives you access to the server load of the CM you connected to
- Con: If your app crashes or is killed without properly logging off or disconnecting, your session will remain active for a minute while Steam waits for it to timeout
- Con: Currently support for UDP connections in
- Pro: More secure crypto. Uses TLSv1.2 instead of Valve's proprietary crypto, which has been broken (and fixed) in the past
- Pro: Runs over TCP, so all the benefits of TCP
CMClient's implementation of Valve's WebSocket protocol sends ping frames to the CM every 30 seconds, which the CM responds to, allowing for faster detection of dropped connections
- Pro: Runs over port 443, allowing access through nearly all firewalls
- Con: Currently support for WebSocket connections in
CMClientis in beta
Note that UDP connections use Valve-brand UDP, which is essentially TCP over UDP. Consequently, network unreliability is not a concern when using UDP.
var Steam = ;var client = SteamEConnectionProtocolTCP;
Steam.servers contains the list of CM servers that
CMClient will attempt to connect to. The bootstrapped list is not
always up-to-date and might contain dead servers. To avoid timeouts, replace it with your own list before logging in if
you have one (see 'servers' event).
Whenever a method accepts (or an event provides) an
ESomething, it's a Number that represents some enum value. See
eresult.steamd for the whole
list of them. For each enum, there is an equivalently named property on
Steam. The property is an object; for each of
the enum's members, there is an equivalently named property on the object with an equivalent value.
Note that you can't easily get the string value from the number, but you probably don't need to. You can still use them
in conditions (e.g.
if (type == Steam.EChatEntryType.Emote) ...) or switch statements.
Whenever a method accepts (or an event provides) a
CMsgSomething, it's an object that represents a protobuf message.
It has an equivalently named property for each set field in the specified message with the type as follows:
bytesfields: Buffer objects
See the node-steam wiki for descriptions of protobuf fields.
Most of the API is provided by handler classes that internally send and receive low-level client messages using 'message'/send.
A boolean that indicates whether you are currently connected and the encryption handshake is complete.
'connected' is emitted when it changes to
true, and 'error' is emitted when it changes to
false unless you called disconnect. Sending any client messages is only allowed while this is
A boolean that indicates whether you are currently logged on. Calling any handler methods except for methods to log on is only allowed while logged on.
Your own SteamID while logged on, otherwise unspecified. Must be set to a valid initial value before sending a logon message.
v2.1.0 or later is required to use this property
If we've initiated a connection previously, a string containing "ipv4:port" for the server we're connecting/connected to. Also contains the address of the last host we were connected to if we're currently disconnected.
localAddress- The local IP address you want to use for the outgoing connection
localPort- The local port you want to use for the outgoing connection
Override the address and/or port that will be used for the outgoing connection. Takes effect the next time you connect.
proxyUrl- A string containing the URL of your HTTP proxy
If you want to connect via an HTTP proxy, set the proxy URL using this method before connecting. HTTPS proxies are not
supported at this time. Example:
server- If you want to connect to a specific CM server, provide an object here containing
portproperties. Default is a random value from the
trueif you want to automatically retry connection until successful, or
falseif you want an
errorevent if connection fails. Default
You can call this method at any time. If you are already connected, disconnects you first. If there is an ongoing connection attempt, cancels it.
Immediately terminates the connection and prevents any events (including 'error') from being emitted until you connect again. If you are already disconnected, does nothing. If there is an ongoing connection attempt, cancels it.
details- An object containing your logon parameters
send(header, body, callback)
header- An object containing the message header. It has the following properties:
msg- A value from
CMsgProtoBufHeaderobject if this message is protobuf-backed, otherwise
header.protois falsy. The following fields are reserved for internal use and shall be ignored:
jobid_target. (Note: pass an empty object if you don't need to set any fields)
ByteBuffercontaining the rest of the message
callback(optional) - if not falsy, then this message is a request, and
callbackshall be called with any response to it instead of 'message'/send.
callbackhas the same arguments as 'message'/send.
Errorobject. May contain an
Connection closed by the server. Only emitted if the encryption handshake is complete, otherwise it will reconnect
automatically (unless you disabled
loggedOn is now
serverLoad- The load value of the CM server you're connected to. Only available if you're connecting using UDP. It's unclear at this time what scale this value uses.
response- An object with the properties in
Logon response received. If
loggedOn is now
servers- An array containing the up-to-date server list
CMClient will use this new list when reconnecting, but it will be lost when your application restarts. You might want
to save it to a file or a database and assign it to
Steam.servers before logging in next time.
Steam.servers will be automatically updated after this event is emitted. This will be useful if you want
to compare the old list with the new one for some reason - otherwise it shouldn't matter.
eresult- A value from
You were logged off from Steam.
loggedOn is now
header- An object containing the message header
Buffercontaining the rest of the message
callback- If set, then this message is a request and Steam expects a response back from you. To respond, call this callback instead of using
Emitted when you receive a message from the CM.