Skip to content

WebSocket URL only accepts a String - Should accept a URL instance too #49382

Open
@vyrotek

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.
Image

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
Image

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
Image

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    Type: EnhancementA new feature or enhancement of an existing feature.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions