Networking and more
Networking: networking and the New Namespaces
Section titled “Networking: networking and the New Namespaces”Two families of networking APIs coexist. The networking namespace is the original P2P packet API (sendP2PPacket, readP2PPacket, acceptP2PSession), and it is unchanged. The new networkingSockets, networkingMessages and networkingUtils namespaces wrap Steam’s Networking Sockets, Networking Messages and Networking Utils interfaces.
networkingsends unreliable or reliable packets to a SteamID and reads them back in arrival order. There is no connection object, so you cannot close one peer or tell when it dropped.networkingSocketscreates listen sockets and connections (by IP address or by SteamID), sends and receives messages with send flags, and groups connections into poll groups. Connections are objects withclose, and state queries show whether each one is open.networkingMessagesis connectionless, like UDP: send to a SteamID on a channel, receive by channel, and handle session requests and failures. Steam creates the underlying session implicitly.networkingUtilsstarts relay network access and reports its availability.
const steamworks = require('steamworks.js')const client = steamworks.init(appId)
// Relay access and authentication: start them early if you expect relayed or authenticated connectionsclient.networkingUtils.initRelayNetworkAccess()console.log(client.networkingUtils.getRelayNetworkStatus()) // NetworkingAvailability valueclient.networkingSockets.initAuthentication()
// Host: poll the listen socket without waiting, accept connecting peers and take the connection when it is connectedconst listen = client.networkingSockets.createListenSocketIp('0.0.0.0:27015')const event = listen.tryReceiveEvent() // null when nothing is pendingif (event && event.kind === 0 /* Connecting */) { event.accept()}if (event && event.kind === 1 /* Connected */) { const connection = event.takeConnection() connection.send(Buffer.from('hello'), 8) // 8 = reliable console.log(connection.receive(16))}
// Client: connect by IP address, then close with a reasonconst connection = client.networkingSockets.connectByIpAddress('203.0.113.5:27015')connection.setUserData(1n)connection.close(1000, 'done', true)
// Messages: accept requests from Steam users and read channel 3client.networkingMessages.onSessionRequest((request) => request.accept())client.networkingMessages.sendMessageToUser(friendSteamId, 8, Buffer.from('hi'), 3)console.log(client.networkingMessages.receiveMessagesOnChannel(3, 10))- Send flags are a bitmask of Steam’s
k_nSteamNetworkingSend_*values:0unreliable,8reliable,1no Nagle delay. Invalid addresses and closed handles fail with a readable error. - Listen socket events and session requests are only produced while
runCallbacks()runs.init()already calls it about 30 times a second. - A connection or request you never close or answer is closed or rejected when its JavaScript object is garbage collected. Close connections explicitly.
- Connections and messages need a Steam network path, so they cannot be exercised offline. The offline smoke test only checks that these functions are exported.
Server Browser, Timeline, Screenshots and Remote Play
Section titled “Server Browser, Timeline, Screenshots and Remote Play”matchmakingServers lists game servers and queries single servers. timeline marks game state and events for Steam’s timeline. screenshots hooks the screenshot hotkey and adds images to the Steam library. remotePlay lists Remote Play Together sessions and sends invites.
const steamworks = require('steamworks.js')const client = steamworks.init(appId)
// Server list: request, read, then release itconst list = client.matchmakingServers.lanServerList(appId)try { for (let i = 0; i < list.getServerCount(); i++) { const server = list.getServerDetails(i) // ip, port, name, map, players, maxPlayers, ping console.log(server.name, server.players, server.maxPlayers, server.ping) }} finally { list.release()}
// Single server: these are Promises and reject when the server does not answerconst ping = await client.matchmakingServers.pingServer('192.168.1.10', 27015)const players = await client.matchmakingServers.playerDetails('192.168.1.10', 27015)const rules = await client.matchmakingServers.serverRules('192.168.1.10', 27015)
// Timeline: 0 = Playing (the game mode values are Playing, Staging, Menus, LoadingScreen)client.timeline.setGameMode(0)client.timeline.addEvent('icon', 'Boss defeated', '', 0, -5, 5, 1) // clip priority 1 = Standard
// Screenshots: with the hook on, the hotkey raises ScreenshotRequested instead of Steam taking the pictureclient.screenshots.hookScreenshots(true)client.screenshots.triggerScreenshot()
// Remote Play Togetherfor (const session of client.remotePlay.sessions()) { console.log(session.sessionId, session.steamId64, client.remotePlay.sessionDetails(session.sessionId))}client.remotePlay.invite(friendSteamId)- Steam fills a server list over time, through callbacks that
init()pumps automatically. Read the count after a short wait, not right after the request. The single-server functions are Promises that resolve the same way. - Release every server list request when you finish with it. Methods called after
release()throw a readable error. - Invalid IPv4 addresses, negative durations and strings with NUL characters are rejected with a readable error before any Steam call.
timelinecalls are silent when the Steam timeline interface is unavailable.
Supplemental Functions
Section titled “Supplemental Functions”These functions extend existing namespaces. Nothing that existed before has changed.
const client = steamworks.init(appId)
// apps: the launch command line, and a query parameter from a Steam link such as steam://run/480//mode=democlient.apps.launchCommandLine()client.apps.launchQueryParam('mode') // '' when the parameter is absent
// utils: overlay and UI stateclient.utils.isOverlayEnabled()client.utils.isSteamInBigPictureMode()client.utils.getUiLanguage() // for example 'english'
// input: digital and analog action data, and the origins bound to an actionconst pressed = client.input.getDigitalActionData(controllerHandle, actionHandle).stateconst stick = client.input.getAnalogActionData(controllerHandle, analogHandle) // { x, y, active }const origins = client.input.getDigitalActionOrigins(controllerHandle, actionSetHandle, actionHandle)const label = client.input.getStringForActionOrigin(origins[0] ?? 0)
// networking: P2P packets on a channel, and closing a sessionclient.networking.sendP2PPacketOnChannel(friendSteamId, SendType.Reliable, Buffer.from('hi'), 2)client.networking.isP2PPacketAvailableOnChannel(2)client.networking.closeP2PSession(friendSteamId)
// cloud: share a file (a Promise), stop syncing it, and choose the platforms it syncs toconst shareHandle = await client.cloud.shareFile('save.json')client.cloud.forgetFile('save.json')client.cloud.setSyncPlatforms('save.json', 0 /* SyncPlatform.None */)getStringForActionOriginandgetGlyphForActionOriginreturn an empty string for an origin number that Steam does not define.getSyncPlatformsrejects when a file syncs to a combination of platforms, because a singleSyncPlatformvalue cannot describe it.shareFileresolves once Steam answers, which happens throughrunCallbacks().init()runs it for you.
Turn ideas into shipped software.
HagiCode is an agentic coding workspace. OpenSpec workflows plan the change, multi-agent execution carries it out, and Hero Scenario makes the long run visible, so ideas become shipped software.
- Smart
- OpenSpec workflows turn intent into a path from proposal to shipped change.
- Efficient
- Multi-agent execution runs research, build, and review in parallel.
- Fun
- Rich UI interactions make planning, agent work, and projects easier to follow.
© 2026 HagiCode | Powered By hagilight-starlight@0.23.0 | Branch: main | Commit: 7164ec7 | Built:
