Last active
November 13, 2023 19:14
-
-
Save intergalacticspacehighway/ad67264c41f65d52f11ef95e5934d50d to your computer and use it in GitHub Desktop.
Streaming text request in React Native PoC
This file contains hidden or 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
import Networking from "react-native/Libraries/Network/RCTNetworking.ios"; | |
// Same import from .android | |
// import Networking from "react-native/Libraries/Network/RCTNetworking.android"; | |
let streamingServer = "Streaming Server URL"; | |
let requestId = null; | |
Networking.addListener("didReceiveNetworkIncrementalData", (args) => { | |
if (args[0] === requestId) { | |
const response = args[1]; | |
console.log("response ", response); | |
} | |
}); | |
// Checkout https://github.com/facebook/react-native/blob/main/packages/react-native/Libraries/Network/RCTNetworking.ios.js | |
// to pass headers, body etc. | |
Networking.sendRequest( | |
"GET", | |
streamingServer, | |
streamingServer, | |
{}, | |
null, | |
"text", | |
true, | |
null, | |
(_requestId) => { | |
console.log("request sent ", _requestId); | |
requestId = _requestId; | |
}, | |
true | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment