STAXIS

staxis js platform -> gitlab project
staxis on gitlab gitlab project 🏷️ V-0.X-Beta
We’re actively updating this manual. Content and layout may change as we refine it.

WebSocket for a Webgame

This is a draft integration guide for the Staxis WebSocket layer, not an engine-specific SDK. Start with the server-side echo path and the same versioned application message shape. Add player authentication and game-state authorization separately.


A Browser Lobby or Turn-Based Game

Use a text contract first for lobby notices or discrete player actions. Open the connection once, send only after it is ready, match replies by requestId, and keep rendering independent from network callbacks. Choose a message budget rather than sending every render frame.


Browser Client

The example uses the isolated listener from the main page. Adjust the URL for shared mode or your TLS endpoint. A deployed HTTPS page needs an appropriate wss endpoint. The example assumes the opening handshake has been made compatible with the browser's extension offer.

                const socket = new WebSocket('ws://127.0.0.1:8081/ws/game')
                socket.binaryType = 'arraybuffer'
                
                socket.addEventListener('open', () => {
                    socket.send(JSON.stringify({
                        v: 1,
                        action: 'echo',
                        requestId: 'demo-1',
                        data: { text: 'hello' }
                    }))
                })
                
                socket.addEventListener('message', event => {
                    if (typeof event.data !== 'string') return
                
                    try {
                        const reply = JSON.parse(event.data)
                        // Match reply.requestId to pending application requests.
                    } catch {
                        // Reject messages outside your application's text protocol.
                    }
                })
                
                socket.addEventListener('close', event => {
                    // Reset local connection state; reconnect through a bounded retry policy.
                })
            

Browser Handshake and Authentication

Browsers add Sec-WebSocket-Extensions according to their capabilities; the standard WebSocket constructor does not expose that header as an option. The current Staxis baseline rejects any extension offer while allowExtensions=false. Validate this compatibility point before expecting the example to connect in a browser; enabling a flag does not add compression support. See the browser extension-header reference.

Keep authentication as an application flow, for example a short-lived backend-issued ticket verified before accepting game actions. Origin filtering is a separate browser-origin policy. Do not embed Staxis Vault credentials in the game, and avoid long-lived secrets in connection URLs.


If You Add Binary Messages

Use binaryType='arraybuffer' and interpret bytes only after checking the expected message length. The server binary example uses version, kind, and sequence fields with explicit big-endian byte order. Keep binary transport tags separate from game actions.


Reference

Browser WebSocket API