### Xirsys API Daily Statistics Response (JSON) Source: https://github.com/xirsys/xirsys-api-markdown/blob/master/xirsys-api.md This JSON example illustrates the structure of the Xirsys API response when the `break=1` parameter is used, providing a daily breakdown of statistics for the specified date range. ```json { "s": "ok", "v": { "2025:3:1": { "count": 102, "max": 33, "min": 5, "sum": 1518 }, "2025:3:2": { "count": 481, "max": 600, "min": 4, "sum": 7846 } // Additional daily statistics... } } ``` -------------------------------- ### Fetch Xirsys Usage Statistics (JavaScript) Source: https://github.com/xirsys/xirsys-api-markdown/blob/master/xirsys-api.md This JavaScript snippet demonstrates how to make a GET request to the Xirsys API to retrieve usage statistics for a specified date range. It uses `fetch` with Basic Authentication and includes an option to break down statistics daily. ```javascript fetch('https://global.xirsys.net/_stats/?l=turn:session&gs=2025:03:01&ge=2025:03:31&break=1', { method: 'GET', headers: { 'Authorization': 'Basic ' + btoa('{YOUR_IDENT}:{YOUR_SECRET_KEY}'), 'Content-Type': 'application/json' } }) .then(res => res.json()) .then(data => { console.log(data); }); ``` -------------------------------- ### Xirsys API Total Statistics Response (JSON) Source: https://github.com/xirsys/xirsys-api-markdown/blob/master/xirsys-api.md This JSON example shows the structure of the Xirsys API response when the `break` parameter is omitted, providing aggregated total statistics for the entire specified date range. ```json { "s": "ok", "v": { "count": 3812, "max": 711, "min": 4, "sum": 72436 } } ``` -------------------------------- ### Retrieve Xirsys Signaling Host (JavaScript) Source: https://github.com/xirsys/xirsys-api-markdown/blob/master/xirsys-api.md Retrieves the WebSocket signaling host URL from the Xirsys API, which is a necessary first step before establishing a real-time signaling connection. This request uses a GET method and requires authentication. ```javascript fetch('https://global.xirsys.net/_host?type=signal&k={YOUR_CHANNEL}', { method: 'GET', headers: { 'Authorization': 'Basic ' + btoa('{YOUR_IDENT}:{YOUR_SECRET_KEY}') } }) .then(response => response.json()) .then(data => { const signalingHost = data.v; // e.g., "wss://xs-api1.xirsys.com:443/ws/v2/" }); ``` -------------------------------- ### Connect to Xirsys Signaling WebSocket (JavaScript) Source: https://github.com/xirsys/xirsys-api-markdown/blob/master/xirsys-api.md Establishes a WebSocket connection to the Xirsys signaling server using the previously retrieved host and token. The 'onopen' handler is triggered upon successful connection, ready for initiating the signaling process. ```javascript // Connect to the WebSocket server using the host and token const ws = new WebSocket(`${signalingHost}/v2/${token}`); // When connection is established, you can start the signaling process ws.onopen = async () => { console.log('WebSocket connected'); // For initiating a connection, create and send an offer immediately await createAndSendOffer(); }; ``` -------------------------------- ### Request Xirsys TURN ICE Servers (JavaScript) Source: https://github.com/xirsys/xirsys-api-markdown/blob/master/xirsys-api.md Fetches ICE servers (STUN/TURN) from the Xirsys TURN API for WebRTC connections using a JavaScript 'fetch' request. This requires HTTP Basic Authentication and your Xirsys channel identifier. ```javascript fetch('https://global.xirsys.net/_turn/{YOUR_CHANNEL}', { method: 'PUT', headers: { 'Authorization': 'Basic ' + btoa('{YOUR_IDENT}:{YOUR_SECRET_KEY}'), 'Content-Type': 'application/json' }, body: JSON.stringify({ format: 'urls' }) }) .then(response => response.json()) .then(data => { const iceServers = [data.v.iceServers]; // Use iceServers in RTCPeerConnection }); ``` ```json { "v": { "iceServers": { "username": "response-username", "credential": "response-credential", "urls": [ "stun:xx-turn1.xirsys.com", "turn:xx-turn1.xirsys.com:80?transport=udp", "turns:xx-turn1.xirsys.com:443?transport=tcp" ] } }, "s": "ok" } ``` -------------------------------- ### Xirsys Stats API Available Reports Source: https://github.com/xirsys/xirsys-api-markdown/blob/master/xirsys-api.md Lists the available report types for the Xirsys Stats API, providing metrics on TURN and STUN usage including sessions created, and data sent/received. ```APIDOC Available Reports: - turn:session: TURN sessions created (time in seconds) - turn:recv: TURN data received (bytes) - turn:sent: TURN data sent (bytes) - stun:session: STUN sessions created (count) ``` -------------------------------- ### Xirsys API Basic Authentication Header Source: https://github.com/xirsys/xirsys-api-markdown/blob/master/xirsys-api.md Demonstrates the HTTP Basic Authentication header format required for Xirsys API requests. Your Xirsys credentials (identifier and secret key) must be Base64 encoded. ```plaintext Authorization: Basic base64({YOUR_IDENT}:{YOUR_SECRET_KEY}) ``` -------------------------------- ### Handle Incoming Xirsys Signaling Messages (JavaScript) Source: https://github.com/xirsys/xirsys-api-markdown/blob/master/xirsys-api.md Illustrates how to parse and handle incoming WebSocket messages from the Xirsys signaling server. It checks for user messages within a specified room and processes them based on the operation type (offer, answer, or ICE candidate). ```javascript ws.onmessage = (event) => { const message = JSON.parse(event.data); // Check if it's a user message for our room if (message.t === 'u' && message.m.f === roomName) { switch (message.m.o) { case 'offer': // Handle incoming offer handleOffer(message.p.sdp); break; case 'answer': // Handle incoming answer handleAnswer(message.p.sdp); break; case 'candidate': // Handle incoming ICE candidate handleCandidate(message.p.candidate); break; } } }; ``` -------------------------------- ### Xirsys API Base URL Source: https://github.com/xirsys/xirsys-api-markdown/blob/master/xirsys-api.md The base URL for all Xirsys API endpoints. ```plaintext https://global.xirsys.net ``` -------------------------------- ### Xirsys API Statistics Response Fields Reference Source: https://github.com/xirsys/xirsys-api-markdown/blob/master/xirsys-api.md This section details the various fields returned in Xirsys API statistics reports for both TURN/STUN session data and data transfer metrics, explaining the meaning of each field like count, max, min, and sum. ```APIDOC TURN/STUN Session Reports (turn:session, stun:session): count: Number of sessions. max: Longest single session duration (seconds). min: Shortest session duration (seconds). sum: Total duration of all sessions (seconds). Data Transfer Reports (turn:recv, turn:sent): count: Number of transfers. max: Largest single transfer (bytes). min: Smallest transfer (bytes). sum: Total data transferred (bytes). ``` -------------------------------- ### Xirsys Signaling WebSocket Message Format (JavaScript) Source: https://github.com/xirsys/xirsys-api-markdown/blob/master/xirsys-api.md Defines the JSON structure for sending signaling messages (offer, answer, or ICE candidate) over the Xirsys WebSocket. Messages include a type, room/channel name, operation, and a payload specific to the operation. ```javascript // Sending a signaling message (offer, answer, or ICE candidate) ws.send(JSON.stringify({ t: "u", // Type: "u" for user message m: { f: "room_name", // Room/channel name that both peers must use o: "offer" // Operation: "offer", "answer", or "candidate" }, p: { // Payload depends on the operation type sdp: offerSdp // For offer/answer: include SDP // OR candidate: iceCandidate // For ICE candidates } })); ``` -------------------------------- ### Generate Xirsys WebSocket Token (JavaScript) Source: https://github.com/xirsys/xirsys-api-markdown/blob/master/xirsys-api.md Generates a unique WebSocket token from the Xirsys API, which is required for authenticating and connecting to the signaling server. The token request includes a random peer ID and an optional expiration. ```javascript fetch(`https://global.xirsys.net/_token/{YOUR_CHANNEL}?k=${{RANDOM_PEER_ID}}&expire=0`, { method: 'PUT', headers: { 'Authorization': 'Basic ' + btoa('{YOUR_IDENT}:{YOUR_SECRET_KEY}') } }) .then(response => response.json()) .then(data => { const token = data.v; // WebSocket token }); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.