@@ -2,6 +2,8 @@ import { Server as HTTPServer } from "http";
22import { Server , Socket } from "socket.io" ;
33import { UtilityService } from "../services/UtilityService.js" ;
44import { TokenProcessor } from "../processors/TokenProcessor.js" ;
5+ import { AppDataSource } from "../datasources/PostgresDS.js" ;
6+ import { EUserType } from "../types/EUserType.js" ;
57
68export class SocketIODriver {
79
@@ -120,6 +122,23 @@ export class SocketIODriver {
120122 } ) ;
121123 }
122124
125+ // Allow admin users to join the admin-dashboard room for real-time stats
126+ socket . on ( 'join-admin-room' , async ( ) => {
127+ if ( ! userId ) return ;
128+ try {
129+ const user = await AppDataSource . manager . findOne (
130+ ( await import ( '../models/DRAUsersPlatform.js' ) ) . DRAUsersPlatform ,
131+ { where : { id : userId } }
132+ ) ;
133+ if ( user && user . user_type === EUserType . ADMIN ) {
134+ socket . join ( 'admin-dashboard' ) ;
135+ console . log ( `[Socket.IO] Admin user ${ userId } joined admin-dashboard room` ) ;
136+ }
137+ } catch ( err ) {
138+ console . error ( '[Socket.IO] Error joining admin room:' , err ) ;
139+ }
140+ } ) ;
141+
123142 // Handle disconnection
124143 socket . on ( "disconnect" , ( ) => {
125144 const userId = ( socket as any ) . userId ;
@@ -184,5 +203,12 @@ export class SocketIODriver {
184203 } ) ;
185204 }
186205
187-
206+ /**
207+ * Emit an event to all sockets in a named room.
208+ */
209+ public emitToRoom ( room : string , event : string , data : any ) : void {
210+ if ( ! this . io ) return ;
211+ this . io . to ( room ) . emit ( event , data ) ;
212+ }
213+
188214}
0 commit comments