react-native#Networking JavaScript Examples
The following examples show how to use
react-native#Networking.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Fetch.js From ipfs-action with MIT License | 6 votes |
__subscribeToNetworkEvents() {
[
"didReceiveNetworkResponse",
"didReceiveNetworkData",
"didReceiveNetworkIncrementalData",
// "didReceiveNetworkDataProgress",
"didCompleteNetworkResponse",
].forEach((eventName) => {
const subscription = Networking.addListener(eventName, (args) => {
this[`__${eventName}`](...args);
});
this._nativeNetworkSubscriptions.add(subscription);
});
}
Example #2
Source File: Fetch.js From ipfs-action with MIT License | 6 votes |
__doFetch() {
this.__subscribeToNetworkEvents();
Networking.sendRequest(
this._request.method,
this._request.url.toString(), // request tracking name
this._request.url.toString(),
this._nativeRequestHeaders,
this._request._body._bodyInit ?? null,
this._nativeResponseType,
this._nativeResponseType === "text", // send incremental events only when response type is text
this._nativeRequestTimeout,
this.__didCreateRequest.bind(this),
["include", "same-origin"].includes(this._request.credentials) // with credentials
);
}
Example #3
Source File: Fetch.js From ipfs-action with MIT License | 6 votes |
__didReceiveNetworkResponse(requestId, status, headers, url) {
// console.log("fetch __didReceiveNetworkResponse", {
// requestId,
// status,
// headers,
// url,
// });
if (requestId !== this._requestId) {
return;
}
const { stream, streamController } = createStream(() => {
this.__clearNetworkSubscriptions();
Networking.abortRequest(this._requestId);
});
this._streamController = streamController;
this._stream = stream;
this._responseStatus = status;
this._nativeResponseHeaders = headers;
this._responseUrl = url;
if (this._nativeResponseType === "text") {
this._response = new Response(stream, { status, headers, url });
this._deferredPromise.resolve(this._response);
}
}
Example #4
Source File: Fetch.js From ipfs-action with MIT License | 5 votes |
__abort() {
this._requestId && Networking.abortRequest(this._requestId);
this._streamController?.error(new AbortError());
this._deferredPromise.reject(new AbortError());
this.__clearNetworkSubscriptions();
}