35 lines
849 B
JavaScript
35 lines
849 B
JavaScript
// WebSocketServer.js
|
|
|
|
import express from 'express';
|
|
import http from 'http';
|
|
import { Server as SocketIo } from 'socket.io';
|
|
import log4js from 'log4js';
|
|
import dotenv from 'dotenv';
|
|
import { KeycloakAuth, createAuthMiddleware } from './auth/auth.js';
|
|
|
|
dotenv.config();
|
|
|
|
const logger = log4js.getLogger('Web Sockets');
|
|
logger.level = process.env.LOG_LEVEL;
|
|
|
|
export default class WebSocketServer {
|
|
constructor() {
|
|
this.app = express();
|
|
this.server = http.createServer(this.app);
|
|
this.io = new SocketIo(this.server, {
|
|
cors: {
|
|
origin: '*'
|
|
},
|
|
maxHttpBufferSize: 1e8
|
|
});
|
|
this.hostServices = [];
|
|
this.userServices = [];
|
|
}
|
|
|
|
configureMiddleware() {
|
|
// Middleware for Keycloak authentication
|
|
const keycloakAuth = new KeycloakAuth();
|
|
this.io.use(createAuthMiddleware(keycloakAuth));
|
|
}
|
|
}
|