Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save intergalacticspacehighway/ad67264c41f65d52f11ef95e5934d50d to your computer and use it in GitHub Desktop.
Save intergalacticspacehighway/ad67264c41f65d52f11ef95e5934d50d to your computer and use it in GitHub Desktop.
Streaming text request in React Native PoC
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