fix: Remove un-used file

This commit is contained in:
April Hall 2025-01-07 11:51:43 -05:00
parent 3232c21c69
commit 3754648362
No known key found for this signature in database
GPG Key ID: A49AC35CB186266C

View File

@ -1,51 +0,0 @@
import { parse } from 'url';
import { WebSocketServer } from 'ws';
import { nanoid } from 'nanoid';
import type { Server, WebSocket as WebSocketBase } from 'ws';
import type { IncomingMessage } from 'http';
import type { Duplex } from 'stream';
export const GlobalThisWSS = Symbol.for('sveltekit.wss');
export interface ExtendedWebSocket extends WebSocketBase {
socketId: string;
// userId: string;
}
// You can define server-wide functions or class instances here
// export interface ExtendedServer extends Server<ExtendedWebSocket> {};
export type ExtendedWebSocketServer = Server<ExtendedWebSocket>;
export type ExtendedGlobal = typeof globalThis & {
[GlobalThisWSS]: ExtendedWebSocketServer;
};
export const onHttpServerUpgrade = (req: IncomingMessage, sock: Duplex, head: Buffer) => {
const pathname = req.url ? parse(req.url).pathname : null;
if (pathname !== '/websocket') return;
const wss = (globalThis as ExtendedGlobal)[GlobalThisWSS];
wss.handleUpgrade(req, sock, head, (ws) => {
console.log('[handleUpgrade] creating new connecttion');
wss.emit('connection', ws, req);
});
};
export const createWSSGlobalInstance = () => {
const wss = new WebSocketServer({ noServer: true }) as ExtendedWebSocketServer;
(globalThis as ExtendedGlobal)[GlobalThisWSS] = wss;
wss.on('connection', (ws) => {
ws.socketId = nanoid();
console.log(`[wss:global] client connected (${ws.socketId})`);
ws.on('close', () => {
console.log(`[wss:global] client disconnected (${ws.socketId})`);
});
});
return wss;
};