heavily simplify server and app content. unify styling
All checks were successful
ci/woodpecker/pr/pr Pipeline was successful
All checks were successful
ci/woodpecker/pr/pr Pipeline was successful
This commit is contained in:
@@ -1,17 +1,7 @@
|
||||
/**
|
||||
* WebSocket server for WebRTC signaling.
|
||||
* Attaches to Nitro's HTTP server and handles WebSocket connections.
|
||||
*/
|
||||
|
||||
import { WebSocketServer } from 'ws'
|
||||
import { getDb } from '../utils/db.js'
|
||||
import { handleWebSocketMessage } from '../utils/webrtcSignaling.js'
|
||||
|
||||
/**
|
||||
* Parse cookie header string into object.
|
||||
* @param {string} cookieHeader
|
||||
* @returns {Record<string, string>} Parsed cookie name-value pairs.
|
||||
*/
|
||||
function parseCookie(cookieHeader) {
|
||||
const cookies = {}
|
||||
if (!cookieHeader) return cookies
|
||||
@@ -25,30 +15,16 @@ function parseCookie(cookieHeader) {
|
||||
}
|
||||
|
||||
let wss = null
|
||||
const connections = new Map() // sessionId -> Set<WebSocket>
|
||||
const connections = new Map()
|
||||
|
||||
/**
|
||||
* Get WebSocket server instance.
|
||||
* @returns {WebSocketServer | null} WebSocket server instance or null.
|
||||
*/
|
||||
export function getWebSocketServer() {
|
||||
return wss
|
||||
}
|
||||
|
||||
/**
|
||||
* Get connections for a session.
|
||||
* @param {string} sessionId
|
||||
* @returns {Set<WebSocket>} Set of WebSockets for the session.
|
||||
*/
|
||||
export function getSessionConnections(sessionId) {
|
||||
return connections.get(sessionId) || new Set()
|
||||
}
|
||||
|
||||
/**
|
||||
* Add connection to session.
|
||||
* @param {string} sessionId
|
||||
* @param {WebSocket} ws
|
||||
*/
|
||||
export function addSessionConnection(sessionId, ws) {
|
||||
if (!connections.has(sessionId)) {
|
||||
connections.set(sessionId, new Set())
|
||||
@@ -56,11 +32,6 @@ export function addSessionConnection(sessionId, ws) {
|
||||
connections.get(sessionId).add(ws)
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove connection from session.
|
||||
* @param {string} sessionId
|
||||
* @param {WebSocket} ws
|
||||
*/
|
||||
export function removeSessionConnection(sessionId, ws) {
|
||||
const conns = connections.get(sessionId)
|
||||
if (conns) {
|
||||
@@ -71,11 +42,6 @@ export function removeSessionConnection(sessionId, ws) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send message to all connections for a session.
|
||||
* @param {string} sessionId
|
||||
* @param {object} message
|
||||
*/
|
||||
export function broadcastToSession(sessionId, message) {
|
||||
const conns = getSessionConnections(sessionId)
|
||||
const data = JSON.stringify(message)
|
||||
|
||||
Reference in New Issue
Block a user