### Start the server with node Source: https://github.com/auscaster/symple-docs/blob/main/docs/quickstart.md Runs the server.js file to start the symple server. ```bash node server.js ``` -------------------------------- ### Install symple-client with npm Source: https://github.com/auscaster/symple-docs/blob/main/docs/quickstart.md Installs the symple-client package in a separate directory or browser project. ```bash npm install symple-client ``` -------------------------------- ### Install symple-server with npm Source: https://github.com/auscaster/symple-docs/blob/main/docs/quickstart.md Creates a new project directory and installs the symple-server package. Requires Node.js 18 or later and npm or yarn. ```bash mkdir symple-demo && cd symple-demo npm init -y npm install symple-server ``` -------------------------------- ### Create server.js with SympleServer Source: https://github.com/auscaster/symple-docs/blob/main/docs/quickstart.md Sets up a SympleServer on port 4500 with authentication disabled and dynamic rooms enabled. Logs peer connection and disconnection events, then starts the server. ```javascript const { SympleServer } = require("symple-server"); const server = new SympleServer({ port: 4500, authentication: false, dynamicRooms: true, }); server.on("connection", (peer) => { console.log("peer connected:", peer.user, peer.id); }); server.on("disconnection", (peer) => { console.log("peer disconnected:", peer.user, peer.id); }); server.start(); console.log("symple server listening on ws://localhost:4500"); ``` -------------------------------- ### Console client example Source: https://github.com/auscaster/symple-docs/blob/main/docs/cpp-client.md Shows how to configure and start a symple client in C++ using smpl::Client. Sets host, port, user, and name options, attaches state and peer connection handlers, then starts the client and runs the libuv loop. ```cpp smpl::Client::Options opts; opts.host = "localhost"; opts.port = 4500; opts.user = "alice"; opts.name = "Alice"; smpl::Client client(opts); client.StateChange += [](void*, smpl::ClientState& state, const smpl::ClientState&) { // Handle state transitions }; client.PeerConnected += [](smpl::Peer& peer) { std::cout << "Peer connected: " << peer.address() << '\n'; }; client.start(); uv::runLoop(); ``` -------------------------------- ### Run alice.js and bob.js in separate terminals Source: https://github.com/auscaster/symple-docs/blob/main/docs/quickstart.md Starts both client scripts. Alice receives Bob's message because they share the 'demo-room' room. ```bash node alice.js node bob.js ``` -------------------------------- ### Dockerfile for symple server Source: https://github.com/auscaster/symple-docs/blob/main/docs/docker.md Builds a Node.js 22 Alpine image, installs production dependencies with npm ci, copies the application code, exposes port 4500, and runs server.js. ```dockerfile FROM node:22-alpine WORKDIR /app COPY package*.json ./ RUN npm ci --production COPY . . EXPOSE 4500 CMD ["node", "server.js"] ``` -------------------------------- ### Create alice.js with SympleClient Source: https://github.com/auscaster/symple-docs/blob/main/docs/quickstart.md Connects a client as user 'alice' to the server, joins the 'demo-room' on connect, and logs incoming messages. ```javascript const { SympleClient } = require("symple-client"); const client = new SympleClient({ url: "ws://localhost:4500", peer: { user: "alice", name: "Alice", type: "person", }, }); client.on("connect", () => { console.log("alice connected"); client.join("demo-room"); }); client.on("message", (msg) => { console.log("alice received:", msg.data); }); client.connect(); ``` -------------------------------- ### Start symple server via npm start Source: https://github.com/auscaster/symple-docs/blob/main/docs/server.md Starts the server using the built-in entry point. Reads configuration from environment variables via config.js. ```bash cd symple-server npm start ``` -------------------------------- ### server.init() Source: https://github.com/auscaster/symple-docs/blob/main/docs/server.md Starts the HTTP and WebSocket servers, and connects to Redis if configured. This method must be called to start the server. ```APIDOC ## Method: server.init() ### Description Starts the HTTP and WebSocket servers, and connects to Redis if configured. ### Method init ### Parameters None ### Example ```javascript server.init() ``` ``` -------------------------------- ### Install symple-player Source: https://github.com/auscaster/symple-docs/blob/main/docs/call-manager.md Install the symple-player package via npm. ```bash npm install symple-player ``` -------------------------------- ### WebRTC signalling example Source: https://github.com/auscaster/symple-docs/blob/main/docs/cpp-client.md Integrates symple with icey's WebRTC module using wrtc::SympleSignaller. Creates a PeerSession, accepts incoming calls, starts the symple client, and initiates a call to a remote peer. ```cpp smpl::Client symple(opts); wrtc::SympleSignaller signaller(symple); wrtc::PeerSession session(signaller, rtcConfig); session.IncomingCall += [&](const std::string& peerId) { session.accept(); }; symple.start(); session.call(remotePeerId); uv::runLoop(); ``` -------------------------------- ### Create bob.js with SympleClient Source: https://github.com/auscaster/symple-docs/blob/main/docs/quickstart.md Connects a client as user 'bob', joins 'demo-room', and sends a chat message to the room after a 1-second delay. Logs incoming messages. ```javascript const { SympleClient } = require("symple-client"); const client = new SympleClient({ url: "ws://localhost:4500", peer: { user: "bob", name: "Bob", type: "person", }, }); client.on("connect", () => { console.log("bob connected"); client.join("demo-room"); // send a message to the room after a short delay setTimeout(() => { client.sendMessage({ to: "demo-room", subtype: "chat", data: { text: "Hello from Bob!" }, }); }, 1000); }); client.on("message", (msg) => { console.log("bob received:", msg.data); }); client.connect(); ``` -------------------------------- ### Browser usage with SympleClient import Source: https://github.com/auscaster/symple-docs/blob/main/docs/quickstart.md Imports SympleClient in a browser project using a bundler (webpack, vite, esbuild). Connects as 'browser-user' and logs on connect. For production, use wss:// with TLS. ```javascript import { SympleClient } from "symple-client"; const client = new SympleClient({ url: "ws://localhost:4500", peer: { user: "browser-user", name: "Browser" }, }); client.on("connect", () => { console.log("connected from browser"); }); client.connect(); ``` -------------------------------- ### Docker Compose configuration for symple with Redis Source: https://github.com/auscaster/symple-docs/blob/main/docs/docker.md Defines a Redis service and a symple service using the node:22-alpine image. The symple service mounts the local ./symple-server directory, runs npm start, and sets environment variables including SYMPLE_AUTHENTICATION, SYMPLE_DYNAMIC_ROOMS, and SYMPLE_REDIS_URL. The symple service depends on Redis. ```yaml services: redis: image: redis:7-alpine ports: - "6379:6379" symple: image: node:22-alpine working_dir: /app volumes: - ./symple-server:/app command: npm start ports: - "4500:4500" environment: PORT: 4500 SYMPLE_AUTHENTICATION: "true" SYMPLE_DYNAMIC_ROOMS: "false" SYMPLE_REDIS_URL: redis://redis:6379 depends_on: - redis ``` -------------------------------- ### WebRTCPlayer Setup and Usage Source: https://github.com/auscaster/symple-docs/blob/main/docs/media-players.md Create a WebRTCPlayer for two-way video/audio using RTCPeerConnection. Configure initiator, RTC config, media constraints, and local/remote media. Listen for SDP, candidate, and stream events, then play and handle remote SDP/candidates. Mute audio/video and destroy when done. Typically used via CallManager. ```javascript import WebRTCPlayer from 'symple-player/src/webrtc.js' const player = new WebRTCPlayer(videoElement, { initiator: true, rtcConfig: { iceServers: [{ urls: 'stun:stun.l.google.com:19302' }] }, mediaConstraints: { audio: true, video: true }, localMedia: true, // acquire local camera/mic receiveMedia: true // expect remote media }) player.on('sdp', (desc) => { /* send to remote peer */ }) player.on('candidate', (candidate) => { /* send to remote peer */ }) player.on('localstream', (stream) => { /* local preview */ }) player.on('remotestream', (stream) => { /* remote video */ }) await player.play() await player.recvRemoteSDP(remoteDesc) await player.recvRemoteCandidate(candidate) player.muteAudio(true) player.muteVideo(true) player.destroy() ``` -------------------------------- ### Send a direct message with client.sendMessage Source: https://github.com/auscaster/symple-docs/blob/main/docs/quickstart.md Sends a private message to a specific peer by setting 'to' to their address (user|). The session ID is assigned by the server on connection; discover peer addresses via presence events. ```javascript // bob sends directly to alice client.sendMessage({ to: "alice|", subtype: "chat", data: { text: "Private message" }, }); ``` -------------------------------- ### Initialize Symple server with options Source: https://github.com/auscaster/symple-docs/blob/main/docs/server.md Creates a new Symple server instance with specified port, authentication disabled, and dynamic rooms enabled. Call init() to start the HTTP and WebSocket servers and connect to Redis if configured. ```javascript const Symple = require('symple-server') const server = new Symple({ port: 4500, authentication: false, dynamicRooms: true }) server.init() ``` -------------------------------- ### Initialize CallManager with SympleClient Source: https://github.com/auscaster/symple-docs/blob/main/docs/call-manager.md Creates a SympleClient and CallManager, wiring messaging to WebRTC. Requires a video element and optional rtcConfig/mediaConstraints. Connects the client after setup. ```javascript import SympleClient from 'symple-client' import CallManager from 'symple-player/src/call-manager.js' const client = new SympleClient({ url: 'ws://localhost:4500', peer: { user: 'alice', name: 'Alice' } }) const calls = new CallManager(client, document.getElementById('video'), { rtcConfig: { iceServers: [ { urls: 'stun:stun.l.google.com:19302' } ] }, mediaConstraints: { audio: true, video: true } }) client.connect() ``` -------------------------------- ### Install symple-client-ruby gem Source: https://github.com/auscaster/symple-docs/blob/main/docs/ruby-client.md Add the gem to your Gemfile to use the Ruby client for server-side messaging. ```ruby # Gemfile gem 'symple-client-ruby' ``` -------------------------------- ### Roster usage in JavaScript Source: https://github.com/auscaster/symple-docs/blob/main/docs/presence.md Shows how to use the client-side Roster to get peers by ID or properties, and listen for add/remove events. The roster updates automatically from presence messages. ```javascript // Get a peer by ID or address const alice = client.roster.get('alice|session-abc') // Find by properties const peer = client.roster.findOne({ user: 'alice' }) // Listen for changes client.on('addPeer', (peer) => { console.log('online:', peer.user) }) client.on('removePeer', (peer) => { console.log('offline:', peer.user) }) ``` -------------------------------- ### Media.preferredEngine() Source: https://github.com/auscaster/symple-docs/blob/main/docs/media-players.md Returns the best available media engine based on preference score and browser support. Use this to get the default engine for playback. ```APIDOC ## Media.preferredEngine() ### Description Returns the best available media engine based on preference score and browser support. ### Method Function ### Returns - **engine** (Engine) - The preferred engine instance. ### Example ```javascript const engine = Media.preferredEngine() ``` ``` -------------------------------- ### Docker Compose scaling configuration with replicas Source: https://github.com/auscaster/symple-docs/blob/main/docs/docker.md Scales the symple service to three replicas behind a load balancer. All instances point to the same Redis URL, enabling cross-instance messaging automatically. No sticky sessions are required because session tokens are stored in Redis. ```yaml services: symple: deploy: replicas: 3 environment: SYMPLE_REDIS_URL: redis://redis:6379 ``` -------------------------------- ### Docker Compose healthcheck configuration Source: https://github.com/auscaster/symple-docs/blob/main/docs/docker.md Uses wget to perform a health check against the HTTP server at http://localhost:4500/. The check runs every 30 seconds with a 5-second timeout and 3 retries. ```yaml healthcheck: test: ["CMD", "wget", "-q", "--spider", "http://localhost:4500/"] interval: 30s timeout: 5s retries: 3 ``` -------------------------------- ### getCapability(peerId, name) Source: https://github.com/auscaster/symple-docs/blob/main/docs/javascript-client.md Gets the value of a remote peer's capability. ```APIDOC ## getCapability(peerId, name) ### Description Gets the value of a remote peer's capability. ### Parameters - `peerId` (string) - Required - The peer ID to check - `name` (string) - Required - The capability name ### Returns - (any) - The capability value ### Example ```javascript const videoCapability = client.getCapability('bob|session-id', 'video') ``` ``` -------------------------------- ### Symple::Session.new Source: https://github.com/auscaster/symple-docs/blob/main/docs/ruby-client.md Creates a new Session instance for managing auth tokens in Redis. The session object provides methods to set, get, touch, check existence, and delete session data. ```APIDOC ## Symple::Session.new ### Description Creates a new Session instance for managing auth tokens in Redis. ### Method Constructor ### Parameters - **redis** (Redis) - Required - Redis client instance ### Example ```ruby session = Symple::Session.new(redis: $redis) ``` ``` -------------------------------- ### Media Engine Registry Usage Source: https://github.com/auscaster/symple-docs/blob/main/docs/media-players.md Use the Media registry to get the best available engine, list compatible engines sorted by preference, and check support for a specific engine like 'WebRTC'. ```javascript import Media from 'symple-player/src/media.js' // Get the best available engine const engine = Media.preferredEngine() // List all compatible engines (sorted by preference) const engines = Media.compatibleEngines() // Check support Media.supports('WebRTC') // true if RTCPeerConnection exists ``` -------------------------------- ### Presence message JSON Source: https://github.com/auscaster/symple-docs/blob/main/docs/presence.md Example of a presence message broadcast by the server when a peer authenticates or disconnects. Contains type, from, and data fields with user info and online status. ```json { "type": "presence", "from": "alice|session-abc", "data": { "user": "alice", "name": "Alice", "id": "session-abc", "online": true } } ``` -------------------------------- ### Custom authentication hook Source: https://github.com/auscaster/symple-docs/blob/main/docs/server.md Override server.authenticate to validate credentials. Return an object with allowed boolean and optional rooms array. Example checks a token against a database and returns user teams as rooms. ```javascript server.authenticate = async (peer, auth) => { const user = await db.users.findByToken(auth.token) if (!user) return { allowed: false } return { allowed: true, rooms: user.teams } } ``` -------------------------------- ### new Symple(options) Source: https://github.com/auscaster/symple-docs/blob/main/docs/server.md Creates a new Symple server instance with the provided configuration options. The constructor accepts an options object to configure the server. ```APIDOC ## Constructor: new Symple(options) ### Description Creates a new Symple server instance with the provided configuration options. ### Parameters - **options** (object) - Required - Configuration object with the following properties: - `port` (number) - Optional - Listen port (default: 4500) - `authentication` (boolean) - Optional - Require token auth via Redis (default: false) - `dynamicRooms` (boolean) - Optional - Allow runtime join/leave (default: true) - `sessionTTL` (number) - Optional - Session timeout in minutes (-1 = no expiry) - `redis` (string) - Optional - Redis connection URL - `ssl.enabled` (boolean) - Optional - Enable HTTPS/WSS (default: false) - `ssl.key` (string) - Optional - SSL key file path - `ssl.cert` (string) - Optional - SSL cert file path ### Example ```javascript const server = new Symple({ port: 4500, authentication: false, dynamicRooms: true }) ``` ``` -------------------------------- ### new WebcamPlayer(container) Source: https://github.com/auscaster/symple-docs/blob/main/docs/media-players.md Creates a local webcam capture player with frame snapshot capabilities. ```APIDOC ## new WebcamPlayer(container) ### Description Creates a local webcam capture player with frame snapshot capabilities. ### Constructor - **container** (HTMLElement) - Required - The container element for the player. ### Methods - **play(options)** - Starts webcam capture. Options include `audio` (boolean) and `video` (boolean). Returns a Promise. - **toBlob(type, quality)** - Captures a frame as a Blob. Returns a Promise resolving to a Blob. - **capture(scale)** - Captures a frame as a canvas. Returns a canvas element. - **destroy()** - Destroys the player. ### Example ```javascript const player = new WebcamPlayer(containerElement) await player.play({ audio: false, video: true }) const blob = await player.toBlob('image/jpeg', 0.75) const canvas = player.capture(0.5) player.destroy() ``` ``` -------------------------------- ### Media.compatibleEngines() Source: https://github.com/auscaster/symple-docs/blob/main/docs/media-players.md Returns a list of all media engines compatible with the current browser, sorted by preference score. Use this to enumerate available engines. ```APIDOC ## Media.compatibleEngines() ### Description Returns a list of all media engines compatible with the current browser, sorted by preference score. ### Method Function ### Returns - **engines** (Array) - List of compatible engines. ### Example ```javascript const engines = Media.compatibleEngines() ``` ``` -------------------------------- ### emitter.create_session Source: https://github.com/auscaster/symple-docs/blob/main/docs/ruby-client.md Creates a session using the emitter. ```APIDOC ## emitter.create_session ### Description Creates a session using the emitter. ### Method create_session ### Parameters - **token** (String) - Required - Session token - **data** (Hash) - Required - Session data (e.g., user, rooms) - **ttl** (Integer) - Optional - Time-to-live in seconds ### Example ```ruby emitter.create_session(token, { user: 'alice', rooms: ['team-a'] }, ttl: 604800) ``` ``` -------------------------------- ### WebcamPlayer Capture and Snapshot Source: https://github.com/auscaster/symple-docs/blob/main/docs/media-players.md Create a WebcamPlayer for local webcam capture. Play with audio/video constraints, capture a frame as a Blob with toBlob, capture as a canvas with capture (scale factor), and destroy when done. ```javascript import WebcamPlayer from 'symple-player/src/webcam.js' const player = new WebcamPlayer(containerElement) await player.play({ audio: false, video: true }) // Capture a frame as a Blob const blob = await player.toBlob('image/jpeg', 0.75) // Capture as canvas const canvas = player.capture(0.5) // 50% scale player.destroy() ``` -------------------------------- ### join(room) Source: https://github.com/auscaster/symple-docs/blob/main/docs/javascript-client.md Joins a dynamic room. Requires `dynamicRooms: true` on the server. ```APIDOC ## join(room) ### Description Joins a dynamic room. Requires `dynamicRooms: true` on the server. ### Parameters - `room` (string) - Required - The room name to join ### Example ```javascript client.join('room-name') ``` ``` -------------------------------- ### sendPresence(p?) Source: https://github.com/auscaster/symple-docs/blob/main/docs/javascript-client.md Broadcasts presence to all rooms. Merges peer data automatically. ```APIDOC ## sendPresence(p?) ### Description Broadcasts presence to all rooms. Merges peer data automatically. ### Parameters - `p` (object) - Optional - Presence data to include ### Example ```javascript client.sendPresence({ status: 'online' }) ``` ``` -------------------------------- ### connect() Source: https://github.com/auscaster/symple-docs/blob/main/docs/javascript-client.md Opens a WebSocket connection and authenticates the client. This method must be called to establish a connection to the server. ```APIDOC ## connect() ### Description Opens a WebSocket connection and authenticates the client. ### Method connect() ### Parameters None ### Example ```javascript client.connect() ``` ``` -------------------------------- ### client.on('addPeer', callback) Source: https://github.com/auscaster/symple-docs/blob/main/docs/presence.md Listens for when a peer comes online. The callback receives the peer object. ```APIDOC ## client.on('addPeer', callback) ### Description Listens for when a peer comes online. ### Method Event subscription ### Parameters - **event** (string) - Required - The event name, 'addPeer'. - **callback** (function) - Required - Function called with the peer object when a peer is added. ### Example ```javascript client.on('addPeer', (peer) => { console.log('online:', peer.user) }) ``` ``` -------------------------------- ### Session creation from emitter Source: https://github.com/auscaster/symple-docs/blob/main/docs/ruby-client.md The emitter can also manage sessions: create a session with a token and TTL, or delete a session. ```ruby emitter = Symple::Emitter.new(redis: $redis) # Create a session emitter.create_session(token, { user: 'alice', rooms: ['team-a'] }, ttl: 604800) # Delete a session emitter.destroy_session(token) ``` -------------------------------- ### Session creation from any language Source: https://github.com/auscaster/symple-docs/blob/main/docs/authentication.md Creates a session by writing directly to Redis with `SET` and `EXPIRE` commands. The session data merges with the auth message and rooms are joined automatically. ```redis SET symple:session:my-token '{"user":"alice","name":"Alice","rooms":["team-a"]}' EXPIRE symple:session:my-token 604800 ``` -------------------------------- ### Enable SSL/TLS via environment variables Source: https://github.com/auscaster/symple-docs/blob/main/docs/configuration.md Set these environment variables to enable WSS for production. If SYMPLE_SSL_ENABLED is true but key/cert paths are missing, the server falls back to HTTP with a warning. ```bash SYMPLE_SSL_ENABLED=true SYMPLE_SSL_KEY=/etc/ssl/private/symple.key SYMPLE_SSL_CERT=/etc/ssl/certs/symple.crt ``` -------------------------------- ### new SympleClient(options) Source: https://github.com/auscaster/symple-docs/blob/main/docs/javascript-client.md Creates a new Symple client instance with the provided configuration options. The constructor accepts a WebSocket URL, optional authentication token, peer identity, and reconnection settings. ```APIDOC ## Constructor ### Description Creates a new Symple client instance with the provided configuration options. ### Parameters - `url` (string) - Required - Server WebSocket URL (default: `ws://localhost:4500`) - `token` (string) - Optional - Auth token - `peer` (object) - Optional - Peer identity (`user` required, `name` and `type` optional) - `reconnection` (boolean) - Optional - Auto-reconnect on disconnect (default: `true`) - `reconnectionDelay` (number) - Optional - Milliseconds between retries (default: `3000`) - `reconnectionAttempts` (number) - Optional - Max retries (0 = unlimited, default: `0`) ### Example ```javascript const client = new SympleClient({ url: 'ws://localhost:4500', token: 'optional-auth-token', peer: { user: 'alice', name: 'Alice', type: 'person' }, reconnection: true, reconnectionDelay: 3000, reconnectionAttempts: 0 }) ``` ``` -------------------------------- ### welcome (server → client) Source: https://github.com/auscaster/symple-docs/blob/main/docs/protocol.md Sent after successful authentication. ```APIDOC ## welcome (server → client) ### Description Sent after successful authentication. ### Message Type welcome ### Direction server → client ### Fields - **protocol** (string) - Protocol version (`"symple/4"`) - **peer** (object) - Authenticated peer object - **peer.id** (string) - Server-assigned session ID (unique per connection) - **status** (integer) - HTTP-style status code (200 = success) - **rooms** (array) - Rooms the peer was auto-joined to ### Response Example ```json { "type": "welcome", "protocol": "symple/4", "peer": { "id": "a1b2c3d4", "user": "alice", "name": "Alice", "online": true, "host": "192.168.1.100" }, "status": 200, "rooms": ["alice", "team-a", "design"] } ``` ``` -------------------------------- ### Architecture diagram for scaled deployment Source: https://github.com/auscaster/symple-docs/blob/main/docs/scaling.md Shows the architecture with a load balancer distributing connections to multiple server instances, which share Redis for pub/sub messaging and session storage. ```text Load Balancer / \ Server A Server B (ws peers) (ws peers) \ / Redis / \ pub/sub sessions ``` -------------------------------- ### new WebRTCPlayer(container, options) Source: https://github.com/auscaster/symple-docs/blob/main/docs/media-players.md Creates a WebRTC player for two-way video/audio using RTCPeerConnection. Typically used via CallManager rather than directly. ```APIDOC ## new WebRTCPlayer(container, options) ### Description Creates a WebRTC player for two-way video/audio using RTCPeerConnection. ### Constructor - **container** (HTMLElement) - Required - The container element for the player. - **options** (Object) - Required - Configuration options. - **initiator** (boolean) - Optional - Whether this peer initiates the connection. - **rtcConfig** (Object) - Optional - RTCPeerConnection configuration (e.g., iceServers). - **mediaConstraints** (Object) - Optional - Media constraints for getUserMedia. - **localMedia** (boolean) - Optional - Acquire local camera/mic. - **receiveMedia** (boolean) - Optional - Expect remote media. ### Methods - **play()** - Starts the player. Returns a Promise. - **recvRemoteSDP(desc)** - Receives remote SDP description. Returns a Promise. - **recvRemoteCandidate(candidate)** - Receives remote ICE candidate. Returns a Promise. - **muteAudio(muted)** - Mutes or unmutes audio. - **muteVideo(muted)** - Mutes or unmutes video. - **destroy()** - Destroys the player. ### Events - **sdp** - Emitted with SDP description to send to remote peer. - **candidate** - Emitted with ICE candidate to send to remote peer. - **localstream** - Emitted with local media stream. - **remotestream** - Emitted with remote media stream. ### Example ```javascript const player = new WebRTCPlayer(videoElement, { initiator: true, rtcConfig: { iceServers: [{ urls: 'stun:stun.l.google.com:19302' }] }, mediaConstraints: { audio: true, video: true }, localMedia: true, receiveMedia: true }) player.on('sdp', (desc) => { /* send to remote peer */ }) player.on('candidate', (candidate) => { /* send to remote peer */ }) player.on('localstream', (stream) => { /* local preview */ }) player.on('remotestream', (stream) => { /* remote video */ }) await player.play() await player.recvRemoteSDP(remoteDesc) await player.recvRemoteCandidate(candidate) player.muteAudio(true) player.muteVideo(true) player.destroy() ``` ``` -------------------------------- ### new MJPEGPlayer(container) Source: https://github.com/auscaster/symple-docs/blob/main/docs/media-players.md Creates a native MJPEG player that streams via multipart/x-mixed-replace using an element. ```APIDOC ## new MJPEGPlayer(container) ### Description Creates a native MJPEG player that streams via multipart/x-mixed-replace using an element. ### Constructor - **container** (HTMLElement) - Required - The container element for the player. ### Methods - **play(options)** - Starts playback. Options include `url` (string) - the MJPEG stream URL. - **stop()** - Stops playback. ### Example ```javascript const player = new MJPEGPlayer(containerElement) player.play({ url: 'http://camera.local/stream.mjpg' }) player.stop() ``` ``` -------------------------------- ### Media.supports(format) Source: https://github.com/auscaster/symple-docs/blob/main/docs/media-players.md Checks if the browser supports a given media format (e.g., 'WebRTC'). Use this to conditionally enable features. ```APIDOC ## Media.supports(format) ### Description Checks if the browser supports a given media format. ### Method Function ### Parameters - **format** (string) - Required - The media format to check (e.g., 'WebRTC'). ### Returns - **boolean** - True if supported, false otherwise. ### Example ```javascript Media.supports('WebRTC') ``` ``` -------------------------------- ### new MJPEGWebSocketPlayer(container) Source: https://github.com/auscaster/symple-docs/blob/main/docs/media-players.md Creates an MJPEG player that streams over WebSocket binary frames. ```APIDOC ## new MJPEGWebSocketPlayer(container) ### Description Creates an MJPEG player that streams over WebSocket binary frames. ### Constructor - **container** (HTMLElement) - Required - The container element for the player. ### Methods - **play(options)** - Starts playback. Options include `url` (string) - the WebSocket stream URL. - **stop()** - Stops playback. ### Example ```javascript const player = new MJPEGWebSocketPlayer(containerElement) player.play({ url: 'ws://camera.local/stream.ws' }) player.stop() ``` ``` -------------------------------- ### Redis Session Commands Source: https://github.com/auscaster/symple-docs/blob/main/docs/authentication.md Create and manage sessions directly via Redis commands from any language. ```APIDOC ## Redis Session Commands ### Description Create and manage sessions directly via Redis commands from any language. ### Commands #### SET - **key** (string) - Required - Redis key in format `symple:session:`. - **value** (string) - Required - JSON string containing session data (user, name, rooms). #### EXPIRE - **key** (string) - Required - Redis key to set expiration on. - **seconds** (integer) - Required - Time-to-live in seconds. ### Example ``` SET symple:session:my-token '{"user":"alice","name":"Alice","rooms":["team-a"]}' EXPIRE symple:session:my-token 604800 ``` ``` -------------------------------- ### How it works: flow diagram Source: https://github.com/auscaster/symple-docs/blob/main/docs/ruby-client.md Shows the message flow from a Rails model callback through Redis pub/sub to WebSocket peers. ```text Rails model callback → Emitter.emit() → Redis PUBLISH symple:broadcast ↓ Symple Server(s) subscribe ↓ Route to WebSocket peers ``` -------------------------------- ### client.addCapability(key, value) Source: https://github.com/auscaster/symple-docs/blob/main/docs/presence.md Adds a capability to the local client, advertising it to other peers. Capabilities are key-value pairs describing what the peer supports. ```APIDOC ## client.addCapability(key, value) ### Description Adds a capability to the local client, advertising it to other peers. ### Method POST (client-side method) ### Parameters - **key** (string) - Required - The capability key. - **value** (any) - Required - The capability value. ### Example ```javascript client.addCapability('video', true) client.addCapability('maxResolution', '1080p') ``` ``` -------------------------------- ### session.touch Source: https://github.com/auscaster/symple-docs/blob/main/docs/ruby-client.md Extends the TTL of an existing session, typically called on user activity. ```APIDOC ## session.touch ### Description Extends the TTL of an existing session, typically called on user activity. ### Method touch ### Parameters - **token** (String) - Required - Session token - **ttl** (Integer) - Required - New time-to-live in seconds ### Example ```ruby session.touch(token, ttl: 1.week.to_i) ``` ``` -------------------------------- ### Programmatic configuration with Symple constructor Source: https://github.com/auscaster/symple-docs/blob/main/docs/configuration.md Pass a config object to the Symple constructor to configure the server programmatically. Environment variables take precedence over config properties, e.g., PORT overrides config.port. ```javascript const Symple = require('symple-server') const server = new Symple({ port: 4500, authentication: true, dynamicRooms: false, sessionTTL: 10080, // 1 week in minutes redis: 'redis://localhost:6379', ssl: { enabled: true, key: '/path/to/key.pem', cert: '/path/to/cert.pem' } }) server.init() ``` -------------------------------- ### call:init Source: https://github.com/auscaster/symple-docs/blob/main/docs/webrtc-signalling.md Initiates a call from the caller to the callee. Sent as a message with subtype 'call:init'. ```APIDOC ## [MESSAGE] call:init ### Description Initiates a call from the caller to the callee. ### Message Format - **type** (string) - Required - Must be `message` - **subtype** (string) - Required - Must be `call:init` - **from** (string) - Required - Caller identifier (e.g., `alice|session-abc`) - **to** (string) - Required - Callee identifier (e.g., `bob|session-xyz`) - **data** (object) - Optional - Additional data ### Example ```json { "type": "message", "subtype": "call:init", "from": "alice|session-abc", "to": "bob|session-xyz" } ``` ``` -------------------------------- ### addCapability(name, value?) Source: https://github.com/auscaster/symple-docs/blob/main/docs/javascript-client.md Adds a capability to the local peer. Value defaults to `true`. ```APIDOC ## addCapability(name, value?) ### Description Adds a capability to the local peer. Value defaults to `true`. ### Parameters - `name` (string) - Required - The capability name - `value` (any) - Optional - The capability value (default: `true`) ### Example ```javascript client.addCapability('video', true) ``` ``` -------------------------------- ### client.send (multicast) Source: https://github.com/auscaster/symple-docs/blob/main/docs/addressing.md Sends a message to multiple rooms using an array of room names. ```APIDOC ## client.send (multicast) ### Description Sends a message to multiple rooms specified in an array. The sender is excluded from receiving the message. ### Method `send` ### Parameters - **message** (Object) - Required - The message object. Must include a `type` field and optionally a `data` field. - **to** (Array) - Required - An array of room names to broadcast to. ### Example ```javascript client.send({ type: 'message', to: ['team-a', 'team-b'], data: { text: 'Cross-team announcement' } }) ``` ``` -------------------------------- ### Parse and build addresses with Symple utility Source: https://github.com/auscaster/symple-docs/blob/main/docs/addressing.md Use `Symple.parseAddress` to split an address into user and id, and `Symple.buildAddress` to construct an address from an object. The utility is imported from 'symple-client/src/symple.js'. ```javascript import Symple from 'symple-client/src/symple.js' Symple.parseAddress('alice|k7f9x2m4abc') // { user: 'alice', id: 'k7f9x2m4abc' } Symple.buildAddress({ user: 'alice', id: 'k7f9x2m4abc' }) // 'alice|k7f9x2m4abc' ``` -------------------------------- ### session.set Source: https://github.com/auscaster/symple-docs/blob/main/docs/ruby-client.md Creates or updates a session in Redis with the given token, data, and TTL. Typically called on login. ```APIDOC ## session.set ### Description Creates or updates a session in Redis with the given token, data, and TTL. Typically called on login. ### Method set ### Parameters - **token** (String) - Required - Session token - **data** (Hash) - Required - Session data (e.g., user, name, rooms) - **ttl** (Integer) - Optional - Time-to-live in seconds ### Example ```ruby session.set(token, { user: user.username, name: user.display_name, rooms: user.teams.pluck(:slug) }, ttl: 1.week.to_i) ``` ``` -------------------------------- ### session.get Source: https://github.com/auscaster/symple-docs/blob/main/docs/ruby-client.md Retrieves session data for a given token from Redis. ```APIDOC ## session.get ### Description Retrieves session data for a given token from Redis. ### Method get ### Parameters - **token** (String) - Required - Session token ### Returns - **Hash** - Session data (e.g., user, name, rooms) ### Example ```ruby data = session.get(token) # => { "user" => "alice", "name" => "Alice", "rooms" => ["team-a"] } ``` ``` -------------------------------- ### Symple.buildAddress Source: https://github.com/auscaster/symple-docs/blob/main/docs/addressing.md Builds a peer address string from a user and session id object. ```APIDOC ## Symple.buildAddress ### Description Builds a peer address string in the format `user|session-id` from an object containing `user` and `id` fields. ### Method `buildAddress` ### Parameters - **address** (Object) - Required - An object with properties `user` (string) and `id` (string). ### Returns - **string** - The formatted address string, e.g., `'alice|k7f9x2m4abc'`. ### Example ```javascript Symple.buildAddress({ user: 'alice', id: 'k7f9x2m4abc' }) // 'alice|k7f9x2m4abc' ``` ``` -------------------------------- ### Manual presence broadcast in JavaScript Source: https://github.com/auscaster/symple-docs/blob/main/docs/presence.md Shows how to manually broadcast presence state, optionally with additional data. The client merges peer data into the presence message automatically. ```javascript // Broadcast current state client.sendPresence() // With additional data client.sendPresence({ data: { status: 'away' } }) ``` -------------------------------- ### Connection lifecycle sequence diagram Source: https://github.com/auscaster/symple-docs/blob/main/docs/protocol.md ASCII sequence diagram showing the WebSocket connection lifecycle: client connects, sends auth, receives welcome or error, then presence broadcasts and messages, followed by graceful close. The diagram illustrates the order of events and the two possible outcomes after auth (success with welcome, failure with error). ```text Client Server | | |--- WebSocket connect ------------->| | | |--- {"type":"auth", ...} --------->| Client sends auth | | Server validates credentials |<-- {"type":"welcome", ...} -------| Success: peer assigned, rooms joined | or | |<-- {"type":"error", ...} ---------| Failure: connection closed | | |<-- presence broadcasts ----------->| Peer online/offline notifications |<-- messages ---------------------->| Routed messages between peers | | |--- {"type":"close"} ------------->| Graceful disconnect |--- WebSocket close --------------->| ``` -------------------------------- ### MJPEGPlayer Native Streaming Source: https://github.com/auscaster/symple-docs/blob/main/docs/media-players.md Create an MJPEGPlayer for native MJPEG streaming using multipart/x-mixed-replace via an element. Call play with the stream URL and stop to end. ```javascript import { MJPEGPlayer } from 'symple-player/src/mjpeg.js' const player = new MJPEGPlayer(containerElement) player.play({ url: 'http://camera.local/stream.mjpg' }) player.stop() ``` -------------------------------- ### client.getCapability(peerId, key) Source: https://github.com/auscaster/symple-docs/blob/main/docs/presence.md Retrieves the value of a specific capability from a remote peer. ```APIDOC ## client.getCapability(peerId, key) ### Description Retrieves the value of a specific capability from a remote peer. ### Method GET (client-side method) ### Parameters - **peerId** (string) - Required - The peer's ID. - **key** (string) - Required - The capability key to retrieve. ### Returns - **value** (any) - The capability value, or undefined if not present. ### Example ```javascript const res = client.getCapability('alice|session-abc', 'maxResolution') ``` ``` -------------------------------- ### server.onAuthorize(ws, peer) Source: https://github.com/auscaster/symple-docs/blob/main/docs/server.md Event handler called after a peer is authorized. Can be used to log or perform actions after authorization. ```APIDOC ## Event: server.onAuthorize(ws, peer) ### Description Event handler called after a peer is authorized. Can be used to log or perform actions after authorization. ### Parameters - **ws** (WebSocket) - Required - The WebSocket connection. - **peer** (object) - Required - The peer object. ### Example ```javascript server.onAuthorize = (ws, peer) => { console.log('authorized:', peer.user, peer.id) } ``` ``` -------------------------------- ### client.roster.findOne(query) Source: https://github.com/auscaster/symple-docs/blob/main/docs/presence.md Finds a peer in the roster that matches the given properties. This method is part of the client-side Roster. ```APIDOC ## client.roster.findOne(query) ### Description Finds a peer in the roster that matches the given properties. ### Method GET (client-side method) ### Parameters - **query** (object) - Required - An object with properties to match against peer data. ### Returns - **peer** (object) - The first matching peer object, or undefined if none found. ### Example ```javascript const peer = client.roster.findOne({ user: 'alice' }) ``` ``` -------------------------------- ### welcome message (server → client) Source: https://github.com/auscaster/symple-docs/blob/main/docs/protocol.md Sent after successful authentication. Contains protocol version, peer object, status code, and rooms. ```json { "type": "welcome", "protocol": "symple/4", "peer": { "id": "a1b2c3d4", "user": "alice", "name": "Alice", "online": true, "host": "192.168.1.100" }, "status": 200, "rooms": ["alice", "team-a", "design"] } ``` -------------------------------- ### leave(room) Source: https://github.com/auscaster/symple-docs/blob/main/docs/javascript-client.md Leaves a room. ```APIDOC ## leave(room) ### Description Leaves a room. ### Parameters - `room` (string) - Required - The room name to leave ### Example ```javascript client.leave('room-name') ``` ``` -------------------------------- ### Set Redis URL via environment variable Source: https://github.com/auscaster/symple-docs/blob/main/docs/scaling.md Configure the Redis URL for a symple server instance using the SYMPLE_REDIS_URL environment variable. Run this command on each server instance to enable horizontal scaling. ```bash SYMPLE_REDIS_URL=redis://redis:6379 node server.js ``` -------------------------------- ### call:candidate Source: https://github.com/auscaster/symple-docs/blob/main/docs/webrtc-signalling.md Exchanges ICE candidates between both parties. ```APIDOC ## [MESSAGE] call:candidate ### Description Exchanges ICE candidates between both parties. ### Message Format - **type** (string) - Required - Must be `message` - **subtype** (string) - Required - Must be `call:candidate` - **from** (string) - Required - Sender identifier - **to** (string) - Required - Receiver identifier - **data** (object) - Required - Contains ICE candidate - **candidate** (string) - Required - ICE candidate string - **sdpMid** (string) - Optional - Media stream identification - **sdpMLineIndex** (number) - Optional - Index of the m-line ### Example ```json { "type": "message", "subtype": "call:candidate", "from": "alice|session-abc", "to": "bob|session-xyz", "data": { "candidate": "candidate:...", "sdpMid": "0", "sdpMLineIndex": 0 } } ``` ``` -------------------------------- ### call:offer Source: https://github.com/auscaster/symple-docs/blob/main/docs/webrtc-signalling.md Sends an SDP offer from the caller to the callee. ```APIDOC ## [MESSAGE] call:offer ### Description Sends an SDP offer from the caller to the callee. ### Message Format - **type** (string) - Required - Must be `message` - **subtype** (string) - Required - Must be `call:offer` - **from** (string) - Required - Caller identifier - **to** (string) - Required - Callee identifier - **data** (object) - Required - Contains SDP offer - **type** (string) - Required - Must be `offer` - **sdp** (string) - Required - SDP description ### Example ```json { "type": "message", "subtype": "call:offer", "from": "alice|session-abc", "to": "bob|session-xyz", "data": { "type": "offer", "sdp": "v=0\r\no=- ..." } } ``` ``` -------------------------------- ### call:accept Source: https://github.com/auscaster/symple-docs/blob/main/docs/webrtc-signalling.md Accepts an incoming call. Sent from the callee to the caller. ```APIDOC ## [MESSAGE] call:accept ### Description Accepts an incoming call from the callee to the caller. ### Message Format - **type** (string) - Required - Must be `message` - **subtype** (string) - Required - Must be `call:accept` - **from** (string) - Required - Callee identifier - **to** (string) - Required - Caller identifier - **data** (object) - Optional - Additional data ### Example ```json { "type": "message", "subtype": "call:accept", "from": "bob|session-xyz", "to": "alice|session-abc" } ``` ```