Skip to content

Latest commit

 

History

History
43 lines (33 loc) · 2.33 KB

File metadata and controls

43 lines (33 loc) · 2.33 KB

Manages authenticated WebSocket user sessions in MeshCentral, handling real-time communication between browser clients and the server including device management, remote control, file operations, and event dispatching.

Key Components

  • CreateMeshUser(parent, db, ws, req, args, domain, user) — Factory function that constructs a user session object bound to an active WebSocket connection
  • obj.send(object) — Serializes and sends JSON messages to the connected browser client
  • obj.close(arg) — Tears down the session (soft or hard disconnect), cleaning up timers, event dispatchers, and session registries
  • meshPathToRealPath(meshpath, user) — Translates logical mesh path arrays (user or mesh-scoped) into validated server filesystem paths
  • sendPing() / sendPong() — Keepalive heartbeat helpers for browser WebSocket connections
  • Rights constants — Bitmask enumerations for mesh rights (MESHRIGHT_*), site rights (SITERIGHT_*), and user consent flags (USERCONSENT_*)
  • Protocol constants — Numeric identifiers for supported protocols (Terminal, Desktop, Files, AMT, WebRDP, WebSSH, WebSFTP, WebVNC)

Usage Example

const meshUser = require('./meshuser');

// Called internally by MeshCentral when a browser WebSocket connects
const userSession = meshUser.CreateMeshUser(
  parent,   // MeshServer parent object
  db,       // Database reference
  ws,       // Active WebSocket connection
  req,      // HTTP request (carries session data)
  args,     // Server arguments (e.g., browserping interval)
  domain,   // Domain configuration object
  user      // Authenticated user record
);

// Send a message to the browser
userSession.send({ action: 'info', message: 'Session ready' });

// Gracefully close the session
userSession.close(1); // 1 = soft close, 2 = hard TCP close

Notes

  • Session expiration is enforced via req.session.expire using a setTimeout
  • Cross-domain administration is gated by managecrossdomain config; only a specific allowlist of message types are permitted cross-domain
  • Session counts are tracked in parent.wssessions and broadcast to peers in multi-server deployments via parent.parent.multiServer

Source: meshuser.js