
Security News
arXiv Is Rate Limiting Authors Following a Flood of AI Slop Submissions
arXiv now limits authors to two submissions a month as AI slop overwhelms moderators, delays good papers, and sparks debate over applying the limit to everyone.
smart-socket-nestjs
Advanced tools
Author: Nurul Islam Rimon
A powerful and simple real-time WebSocket library for NestJS using Socket.IO.
forRoot() and forRootAsync()@SocketGateway("namespace") for namespace registration@SocketEvent("event") for handling socket eventsnpm install smart-socket-nestjs
import { SmartSocketModule } from 'smart-socket-nestjs';
@Module({
imports: [
SmartSocketModule.forRoot({
namespace: '/chat',
cors: {
origin: '*',
},
}),
],
})
export class AppModule {}
import { Controller } from '@nestjs/common';
import { SocketGateway, SocketEvent } from 'smart-socket-nestjs';
import { SmartSocketService, AuthenticatedSocket } from 'smart-socket-nestjs';
@SocketGateway('chat')
export class ChatGateway {
constructor(private readonly socketService: SmartSocketService) {}
@SocketEvent('message')
async handleMessage(socket: AuthenticatedSocket, data: { text: string }) {
console.log(`User ${socket.user?.id} sent: ${data.text}`);
// Broadcast to all users in the room
this.socketService.toRoom('room-1', 'new-message', {
userId: socket.user?.id,
text: data.text,
});
}
@SocketEvent('join-room')
async handleJoinRoom(socket: AuthenticatedSocket, data: { room: string }) {
await this.socketService.joinRoom(socket, data.room);
socket.emit('joined', { room: data.room });
}
}
SmartSocketModule.forRoot({
namespace: '/api',
cors: {
origin: '*',
},
enableRateLimiting: true,
rateLimitOptions: {
windowMs: 60000,
maxRequests: 100,
},
jwtSecret: 'your-secret-key',
jwtAlgorithm: 'HS256',
redis: {
host: 'localhost',
port: 6379,
},
}),
SmartSocketModule.forRootAsync({
useFactory: (configService: ConfigService) => ({
namespace: '/api',
jwtSecret: configService.get('JWT_SECRET'),
redis: {
host: configService.get('REDIS_HOST'),
port: configService.get('REDIS_PORT'),
},
}),
inject: [ConfigService],
}),
constructor(private readonly socketService: SmartSocketService) {}
// Emit to all clients
this.socketService.emit('event', data);
// Emit to specific room
this.socketService.toRoom('room-id', 'event', data);
// Emit to specific user
this.socketService.toUser(userId, 'event', data);
// Broadcast to all clients
this.socketService.broadcast('event', data);
// Join room
await this.socketService.joinRoom(socket, 'room-id');
// Leave room
await this.socketService.leaveRoom(socket, 'room-id');
// Join user to room
await this.socketService.joinUser(userId, 'room-id');
// Leave user from room
await this.socketService.leaveUser(userId, 'room-id');
// Get all connected users
const users = this.socketService.getConnectedUsers();
// Check if user is online
const online = this.socketService.isOnline(userId);
interface ChatMessage {
id: string;
text: string;
userId: string;
}
@SocketGateway('chat')
export class ChatGateway {
@SocketEvent('message')
handleMessage(socket: AuthenticatedSocket, data: ChatMessage) {
// data is typed as ChatMessage
}
}
When JWT is configured, the socket will have access to socket.user:
@SocketGateway('chat')
export class ChatGateway {
@SocketEvent('private-message')
handlePrivateMessage(socket: AuthenticatedSocket, data: { to: string; text: string }) {
// Access authenticated user
const fromUserId = socket.user?.id;
console.log(`User ${fromUserId} sending private message`);
}
}
Client-side connection with JWT:
import { io } from 'socket.io-client';
const socket = io('http://localhost:3000/chat', {
auth: {
token: 'your-jwt-token',
},
});
SmartSocketModule.forRoot({
namespace: '/api',
redis: {
host: 'localhost',
port: 6379,
password: 'redis-password',
db: 0,
},
}),
@SocketGateway(namespace: string, options?: Record<string, unknown>)Registers a Socket.IO namespace.
@SocketEvent(event: string)Handles a socket event.
| Method | Description |
|---|---|
emit(event, data, options?) | Emit to all clients or specific targets |
toUser(userId, event, data, namespace?) | Emit to specific user |
toRoom(room, event, data, namespace?) | Emit to specific room |
broadcast(event, data, namespace?) | Broadcast to all clients |
joinRoom(socket, room) | Join a socket to a room |
leaveRoom(socket, room) | Leave a socket from a room |
joinUser(userId, room, namespace?) | Join user to room |
leaveUser(userId, room, namespace?) | Remove user from room |
getConnectedUsers() | Get all connected users |
isOnline(userId) | Check if user is online |
getUserSocketIds(userId) | Get socket IDs for user |
MIT
FAQs
A powerful real-time WebSocket system for NestJS using Socket.IO
The npm package smart-socket-nestjs receives a total of 4 weekly downloads. As such, smart-socket-nestjs popularity was classified as not popular.
We found that smart-socket-nestjs demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.

Security News
arXiv now limits authors to two submissions a month as AI slop overwhelms moderators, delays good papers, and sparks debate over applying the limit to everyone.

Research
/Security News
A new GhostAction wave hits hundreds of GitHub repos, expanding CI/CD secret theft to cloud and AI credentials in source code and git history.

Research
/Security News
Tensorlake npm SDK version 0.5.144 was compromised in a ChainDrop / Shai-Hulud attack, delivering credential-stealing malware.