Description
Description
Traditionally, when creating a WebSocket a url
param can be either a String
or URL
instance.
Types on GitHub support this as well.
NativeWebSocketModule
only accepts a String
which breaks other 3rd party libraries which assume web compatibility.
https://github.com/facebook/react-native/blob/main/packages/react-native/Libraries/WebSocket/WebSocketInterceptor.js#L182
Here is an example of a library providing a URL
instance.
https://github.com/openai/openai-node/blob/master/src/beta/realtime/websocket.ts#L56
I've opened an issue with the OpenAI Node SDK but this issue is not isolated to them.
openai/openai-node#1323
Steps to reproduce
Works:
new WebSocket('https://example.com')
Throw an error
new WebSocket(new URL('https://example.com'))
[Error: Exception in HostFunction: Expected argument 0 of method "connect" to be a string, but got an object]
React Native Version
0.76.7
Affected Platforms
Runtime - Android, Runtime - iOS
Output of npx react-native info
System:
OS: Windows 11 10.0.26100
CPU: (6) x64 Intel(R) Core(TM) i5-9600K CPU @ 3.70GHz
Memory: 7.20 GB / 31.92 GB
Binaries:
Node:
version: 20.13.1
path: C:\Program Files\nodejs\node.EXE
Yarn: Not Found
npm:
version: 10.5.2
path: C:\Program Files\nodejs\npm.CMD
Watchman: Not Found
SDKs:
Android SDK: Not Found
Windows SDK:
AllowDevelopmentWithoutDevLicense: Enabled
AllowAllTrustedApps: Enabled
IDEs:
Android Studio: AI-222.4459.24.2221.10121639
Visual Studio:
- 17.12.35707.178 (Visual Studio Community 2022)
Languages:
Java: 17.0.7
Ruby: Not Found
npmPackages:
"@react-native-community/cli":
installed: 15.1.3
wanted: ^15.1.3
react:
installed: 18.3.1
wanted: 18.3.1
react-native:
installed: 0.76.7
wanted: 0.76.7
react-native-windows: Not Found
npmGlobalPackages:
"*react-native*": Not Found
Android:
hermesEnabled: true
newArchEnabled: true
iOS:
hermesEnabled: Not found
newArchEnabled: Not found
Stacktrace or Logs
[Error: Exception in HostFunction: Expected argument 0 of method "connect" to be a string, but got an object]
Reproducer
https://github.com/vyrotek/react-native-websocket
Screenshots and Videos
No response
Activity