websockets / ws

Simple to use, blazing fast and thoroughly tested WebSocket client and server for Node.js
MIT License
21.34k stars 2.3k forks source link

options.autoPong #2188

Closed LiST-GIT closed 6 months ago

LiST-GIT commented 6 months ago

Is there an existing issue for this?

Description

// websocket.js line 69
if (address !== null) {
      this._bufferedAmount = 0;
      this._isServer = false;
      this._redirects = 0;

      if (protocols === undefined) {
        protocols = [];
      } else if (!Array.isArray(protocols)) {
        if (typeof protocols === 'object' && protocols !== null) {
          options = protocols;
          protocols = [];
        } else {
          protocols = [protocols];
        }
      }

      initAsClient(this, address, protocols, options);
    } else {
      this._autoPong = options.autoPong;
                    // ^ options?.autoPong
      this._isServer = true;
    }
  }
new WebSocket(null) // Performing it this way will result in an error.

ws version

8.16.0

Node.js Version

v20.5.0

System

No response

Expected result

No response

Actual result

No response

Attachments

No response

lpinca commented 6 months ago

That's expected.

new WebSocket(null) is not a public API. Use new WebSocket(null, undefined, {}).

LiST-GIT commented 6 months ago
new WebSocket(address[, protocols][, options])

In the declaration, both protocols and options are optional. However, if I usenew WebSocket(null, undefined, {})to avoid errors, it could cause compatibility issues. I have encountered this problem. If this is expected behavior, then I will close the issue.

lpinca commented 6 months ago

address can't be null. It's a special value ws uses to create server-side instances, but that is not an official API.

LiST-GIT commented 6 months ago

Okay, I got it. Thank you for your answer.