-
Notifications
You must be signed in to change notification settings - Fork 327
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(iOS): Solana error after broadcast on WebSockets
We are adding a missing user-agent header on the websocket for iOS with RN facebook/react-native#28450 facebook/react-native#30727 We need to use the interceptor as we don't control the code initiating the websocket Updating the options passed in by the interceptor works fine https://github.com/facebook/react-native/blob/3dfe22bd27429a43b4648c597b71f7965f31ca65/packages/react-native/Libraries/WebSocket/WebSocketInterceptor.js#L148-L163 Another solution could be to use pnpm to patch react native WebSocket linked below https://github.com/facebook/react-native/blob/3dfe22bd27429a43b4648c597b71f7965f31ca65/packages/react-native/Libraries/WebSocket/WebSocket.js But the interceptor seems lean enough and a simple hack vs patching a lib seems preferable
- Loading branch information
Showing
3 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--- | ||
"live-mobile": patch | ||
--- | ||
|
||
fix(iOS): Solana error after broadcast on WebSockets | ||
|
||
We are adding a missing user-agent header on the websocket for iOS with RN | ||
https://github.com/facebook/react-native/issues/28450 | ||
https://github.com/facebook/react-native/issues/30727 | ||
We need to use the interceptor as we don't control the code initiating the websocket | ||
Updating the options passed in by the interceptor works fine | ||
https://github.com/facebook/react-native/blob/3dfe22bd27429a43b4648c597b71f7965f31ca65/packages/react-native/Libraries/WebSocket/WebSocketInterceptor.js#L148-L163 | ||
Another solution could be to use pnpm to patch react native WebSocket linked below | ||
https://github.com/facebook/react-native/blob/3dfe22bd27429a43b4648c597b71f7965f31ca65/packages/react-native/Libraries/WebSocket/WebSocket.js | ||
But the interceptor seems lean enough and a simple hack vs patching a lib seems preferable |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { Platform } from "react-native"; | ||
// @ts-expect-error WebSocketInterceptor is not exposed by react d.ts | ||
import WebSocketInterceptor from "react-native/Libraries/WebSocket/WebSocketInterceptor.js"; | ||
|
||
// We are adding a missing user-agent header on the websocket for iOS with RN | ||
// https://github.com/facebook/react-native/issues/28450 | ||
// https://github.com/facebook/react-native/issues/30727 | ||
// We need to use the interceptor as we don't control the code initiating the websocket | ||
// Updating the options passed in by the interceptor works fine | ||
// https://github.com/facebook/react-native/blob/3dfe22bd27429a43b4648c597b71f7965f31ca65/packages/react-native/Libraries/WebSocket/WebSocketInterceptor.js#L148-L163 | ||
// Another solution could be to use pnpm to patch react native WebSocket linked below | ||
// https://github.com/facebook/react-native/blob/3dfe22bd27429a43b4648c597b71f7965f31ca65/packages/react-native/Libraries/WebSocket/WebSocket.js | ||
// But the interceptor seems lean enough and a simple hack vs patching a lib seems preferable | ||
|
||
if (Platform.OS === "ios") { | ||
WebSocketInterceptor.enableInterception(); | ||
WebSocketInterceptor.setConnectCallback( | ||
(_url: string, _protocols: string[] | null, options?: { headers?: Record<string, string> }) => { | ||
if (options) { | ||
if (!options.headers) options.headers = {}; | ||
if (!options.headers["User-Agent"]) options.headers["User-Agent"] = "ReactNative"; | ||
} | ||
}, | ||
); | ||
} |