Skip to main content

Client Setup

The WSX client library enables real-time communication between your web applications and WSX servers. This guide covers installation, configuration, and basic usage.

Installation

Via CDN

The simplest way to get started is by including WSX from a CDN:

Download

Download the WSX client library and include it in your project:

Build from Source

If you’re building from the WSX repository:

Basic Setup

HTML Configuration

Add the WSX configuration to your HTML page:

Configuration Options

The wx-config attribute accepts a JSON object with these options:

JavaScript API

Manual Initialization

You can also initialize WSX programmatically:

Connection Management

Configuration Examples

Development Setup

Production Setup

Secure WebSocket (WSS)

Environment-Specific Configuration

Dynamic Configuration

Multiple Environments

JSON Channels

Use JSON channels when you need to move structured payloads alongside HTML swaps.
Each call to sendJson, broadcastJson, or sendJsonToConnection returns the message identifier so you can correlate acknowledgements.

Binary Streams

Binary streams let you move raw audio, video, or sensor data with metadata.
The sendStream helper accepts ArrayBuffer, typed arrays, or Blob instances. Handlers receive a Uint8Array view plus the metadata you supplied.

Error Handling

Connection Errors

Reconnection Logic

Security Considerations

Authentication

CORS and WebSocket Security

Advanced Setup

Custom Event Handlers

Conditional Loading

Service Worker Integration

Testing Setup

Test Environment

Integration Tests

Common Issues

WebSocket URL Issues

CORS Issues

Configuration Parsing

Next Steps