margelo / margelo/react-native-nitro-fetch
NitroWebSocket does not satisfy typeof WebSocket
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:
CONNECTINGOPENCLOSINGCLOSED
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
NitroWebSocketaswebSocketConstructorto Convex React client
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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