erictik / midjourney-discord

node.js client for MidJourney wrapper in Discord.
MIT License
70 stars 21 forks source link

Client network socket disconnected before secure TLS connection was established #5

Open chinlee1523 opened 1 year ago

chinlee1523 commented 1 year ago

node -v v20.2.0 报错: Error: Client network socket disconnected before secure TLS connection was established at connResetException (node:internal/errors:714:14) at TLSSocket.onConnectEnd (node:_tls_wrap:1615:19) at TLSSocket.emit (node:events:523:35) at endReadableNT (node:internal/streams/readable:1367:12) at processTicksAndRejections (node:internal/process/task_queues:82:21) Waiting for the debugger to disconnect...

代码 const proxyFetch: FetchFn = async ( input: RequestInfo | URL, init?: RequestInit | undefined ): Promise => { const agent = new SocksProxyAgent("socks5://127.0.0.1:7890", { keepAlive: true, }); if (!init) init = {}; // @ts-ignore init.agent = agent; // @ts-ignore return fetch(input, init); };

  class ProxyWebSocket extends WebSocket {
    constructor(address: string | URL, options?: WebSocket.ClientOptions) {
      const agent = new SocksProxyAgent("socks5://127.0.0.1:7890", {
        keepAlive: true,
      });
      if (!options) options = {};
      options.agent = agent;
      super(address, options);
    }
  }

  this.client = new Midjourney({
    // MaxWait: 1000000,
    ServerId: "662267976984324324",
    ChannelId: "10085712443242346",
    SalaiToken:
      "MTExN",
    Debug: true,
    Ws: true,
    fetch: proxyFetch,
    WebSocket: ProxyWebSocket as typeof WebSocket,
  });