Open Jedi1820 opened 4 months ago
server.on("upgrade", (request, socket, head) => { // You may check auth of request here.. // See https://github.com/websockets/ws#client-authentication const handleAuth = (ws: WebSocket) => { const { auth = () => verifyWssUrl(ws, request) } = SERVER_OPTIONS_WEAKMAP.get(server) ?? {} auth(request, ws).then((res) => { if (!res) { ws.close(1008, undefined) } else { wss.emit("connection", ws, request) } }) } wss.handleUpgrade(request, socket, head, handleAuth) })
const verifyWssUrl = async ( conn: WebSocket.WebSocket, request: http.IncomingMessage ) => { const url = request.url console.log("wss url:" + url)
try { // @ts-ignore 初始化上下文 conn.context = await context.initContext(url) // @ts-ignore console.log(conn.context) } catch (error: any) { console.error("初始化上下文失败", error) return false }
return true }
server.on("upgrade", (request, socket, head) => { // You may check auth of request here.. // See https://github.com/websockets/ws#client-authentication const handleAuth = (ws: WebSocket) => { const { auth = () => verifyWssUrl(ws, request) } = SERVER_OPTIONS_WEAKMAP.get(server) ?? {} auth(request, ws).then((res) => { if (!res) { ws.close(1008, undefined) } else { wss.emit("connection", ws, request) } }) } wss.handleUpgrade(request, socket, head, handleAuth) })
const verifyWssUrl = async ( conn: WebSocket.WebSocket, request: http.IncomingMessage ) => { const url = request.url console.log("wss url:" + url)
try { // @ts-ignore 初始化上下文 conn.context = await context.initContext(url) // @ts-ignore console.log(conn.context) } catch (error: any) { console.error("初始化上下文失败", error) return false }
return true }