margelo / margelo/react-native-nitro-fetch

NitroWebSocket does not satisfy typeof WebSocket

Open
#114 4 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
997
Forks
50
Avg merge
1d 20h
Merged PRs (30d)
14

Description

Summary

NitroWebSocket is not assignable to APIs expecting a standard typeof WebSocket constructor because it does not expose the static constants required by the browser WebSocket constructor contract:

  • CONNECTING
  • OPEN
  • CLOSING
  • CLOSED

Reproduction

import { NitroWebSocket } from \"react-native-nitro-websockets\";
import { ConvexReactClient } from \"convex/react\";

new ConvexReactClient(url, {
  webSocketConstructor: NitroWebSocket,
});

TypeScript reports:

Type 'typeof NitroWebSocket' is missing the following properties from type '{ new (url: string | URL, protocols?: string | string[] | undefined): WebSocket; prototype: WebSocket; readonly CONNECTING: 0; readonly OPEN: 1; readonly CLOSING: 2; readonly CLOSED: 3; }': CONNECTING, OPEN, CLOSING, CLOSED

Expected behavior

If NitroWebSocket is intended to be browser-compatible enough to pass to libraries accepting a custom WebSocket constructor, it should expose the same static constants as the standard browser constructor:

NitroWebSocket.CONNECTING === 0;
NitroWebSocket.OPEN === 1;
NitroWebSocket.CLOSING === 2;
NitroWebSocket.CLOSED === 3;

Alternatively, the docs could clarify that NitroWebSocket is browser-like but not a full typeof WebSocket replacement.

Additional compatibility concern

The current docs describe readyState as string values:

\"CONNECTING\" | \"OPEN\" | \"CLOSING\" | \"CLOSED\"

The browser WebSocket API uses numeric values:

0 | 1 | 2 | 3

That may cause runtime incompatibility with libraries that compare socket.readyState === WebSocket.OPEN.

Environment

  • Package: react-native-nitro-websockets
  • Use case: passing NitroWebSocket as webSocketConstructor to Convex React client

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the NitroWebSocket implementation and its TypeScript declarations, then read the documented readyState behavior. Reproduce the ConvexReactClient webSocketConstructor error and check the static constants and readyState values against the browser WebSocket contract. Done means the compatibility behavior is implemented and documented, or the limitation is clearly documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
react-native, typescript
Domain
api, mobile-dev, networking
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.