Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Implements WebSocket servers with connection lifecycle, pub/sub, Redis scaling, reconnection logic, and authentication.
82% 86%+5 ptsof test cases passed
Passed 19 of 22 test cases with the skill, and 18 of 22 without it.
Write a TypeScript snippet showing how connection requests are authenticated when establishing a WebSocket session with Node's standard HTTP server. Developers often place authentication tokens in message body frames after the socket opens. Show how the HTTP upgrade request object req is passed during the server 'connection' event to authenticate before registering the connection.
The authenticate function receives req as its parameter within the connection listener.
3 of 3 safety checks passed
Expert assistance for implementing WebSocket real-time communication.
Invoke this skill when you need to:
import { WebSocketServer, WebSocket } from 'ws';
import { createServer } from 'http';
const server = createServer();
const wss = new WebSocketServer({ server });
const clients = new Map<string, WebSocket>();
wss.on('connection', (ws, req) => {
const userId = authenticateConnection(req);
clients.set(userId, ws);
ws.on('message', (data) => {
const message = JSON.parse(data.toString());
handleMessage(userId, message);
});
Next to this one in the catalogue, plus more from the same author.