websocket-implementation

Solid

Implements real-time WebSocket communication with connection management, room-based messaging, and horizontal scaling. Use when building chat systems, live notifications, collaborative tools, or real-time dashboards.

Web & Frontend 162 stars 25 forks Updated 2 weeks ago MIT

Install

View on GitHub

Quality Score: 88/100

Stars 20%
74
Recency 20%
90
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
80
License 10%
100
Description 5%
100

Skill Content

# WebSocket Implementation Build scalable real-time communication systems with proper connection management. ## Server Implementation (Socket.IO) ```javascript const { Server } = require('socket.io'); const { createAdapter } = require('@socket.io/redis-adapter'); const { createClient } = require('redis'); const io = new Server(server, { cors: { origin: process.env.CLIENT_URL, credentials: true } }); // Redis adapter for horizontal scaling const pubClient = createClient({ url: process.env.REDIS_URL }); const subClient = pubClient.duplicate(); Promise.all([pubClient.connect(), subClient.connect()]).then(() => { io.adapter(createAdapter(pubClient, subClient)); }); // Connection management const users = new Map(); io.use((socket, next) => { const token = socket.handshake.auth.token; try { socket.user = verifyToken(token); next(); } catch (err) { next(new Error('Authentication failed')); } }); io.on('connection', (socket) => { users.set(socket.user.id, socket.id); console.log(`User ${socket.user.id} connected`); socket.on('join-room', (roomId) => { socket.join(roomId); socket.to(roomId).emit('user-joined', socket.user); }); socket.on('message', ({ roomId, content }) => { io.to(roomId).emit('message', { userId: socket.user.id, content, timestamp: Date.now() }); }); socket.on('disconnect', () => { users.delete(socket.user.id); }); }); // Utility methods for message distribution function broadca...

Details

Author
secondsky
Repository
secondsky/claude-skills
Created
6 months ago
Last Updated
2 weeks ago
Language
TypeScript
License
MIT

Integrates with

Similar Skills

Semantically similar based on skill content — not just same category