Kasumi20

请教, workers 如何中转 WebSocket

  •  
  •   Kasumi20 · Oct 28, 2021 · 1872 views
    This topic created in 1671 days ago, the information mentioned may be changed or developed.

    我的想法:

    async function handleRequest(request) {
    
        const webSocketPair = new WebSocketPair()
        const [client, server] = Object.values(webSocketPair)
        server.accept()
    
        const proxy = new WebSocket('wss://abc.com:9443'); // 这个 API 不能用
        proxy.onmessage = msg => {
            client.send(msg);
        }
        server.onmessage = msg => {
            proxy.send(msg);
        }
    
        return new Response(null, {
            status: 101,
            webSocket: client
        });
    }
    

    new WebSocket 抛异常了,怎么办

    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   6029 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 45ms · UTC 02:59 · PVG 10:59 · LAX 19:59 · JFK 22:59
    ♥ Do have faith in what you're doing.