UNPKG

webssh2-server

Version:

A Websocket to SSH2 gateway using xterm.js, socket.io, ssh2

50 lines (49 loc) 1.8 kB
// app/socket-switcher.ts // Feature flag to switch between old and new socket implementation import { createNamespacedDebug } from './logger.js'; import initV1 from './socket.js'; import initV2 from './socket-v2.js'; const debug = createNamespacedDebug('socket:switcher'); /** * Initialize v2 socket with optional services */ function initV2Socket(io, config, SSHConnectionClass, services, store) { if (services !== undefined && store !== undefined) { debug('Services provided - using service-based adapters'); initV2(io, config, SSHConnectionClass, services, store); } else { debug('Warning: Services not provided, using v2 with legacy adapters'); initV2(io, config, SSHConnectionClass); } } /** * Initialize Socket.IO with either v1 (legacy) or v2 (refactored) implementation * based on environment variable or config setting */ export default function initSocket(io, config, SSHConnectionClass, services, store) { const version = getSocketVersion(); if (version === 'v2') { debug('Using v2 (refactored) socket implementation'); debug('V2 socket initialization starting'); initV2Socket(io, config, SSHConnectionClass, services, store); debug('V2 socket initialization complete'); } else { debug('Using v1 (legacy) socket implementation'); debug('V1 socket initialization starting'); initV1(io, config, SSHConnectionClass); debug('V1 socket initialization complete'); } } /** * Get version of socket implementation being used */ export function getSocketVersion() { const useV2 = process.env['WEBSSH2_USE_V2_SOCKET'] === 'true' || process.env['WEBSSH2_USE_REFACTORED_SOCKET'] === 'true'; if (useV2) { return 'v2'; } return 'v1'; }