RCTNetworking.ios.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /**
  2. * Copyright (c) Facebook, Inc. and its affiliates.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. *
  7. * @format
  8. * @flow
  9. */
  10. 'use strict';
  11. const NativeEventEmitter = require('../EventEmitter/NativeEventEmitter');
  12. const convertRequestBody = require('./convertRequestBody');
  13. import NativeNetworkingIOS from './NativeNetworkingIOS';
  14. import type {NativeResponseType} from './XMLHttpRequest';
  15. import type {RequestBody} from './convertRequestBody';
  16. class RCTNetworking extends NativeEventEmitter {
  17. constructor() {
  18. super(NativeNetworkingIOS);
  19. }
  20. sendRequest(
  21. method: string,
  22. trackingName: string,
  23. url: string,
  24. headers: Object,
  25. data: RequestBody,
  26. responseType: NativeResponseType,
  27. incrementalUpdates: boolean,
  28. timeout: number,
  29. callback: (requestId: number) => void,
  30. withCredentials: boolean,
  31. ) {
  32. const body = convertRequestBody(data);
  33. NativeNetworkingIOS.sendRequest(
  34. {
  35. method,
  36. url,
  37. data: {...body, trackingName},
  38. headers,
  39. responseType,
  40. incrementalUpdates,
  41. timeout,
  42. withCredentials,
  43. },
  44. callback,
  45. );
  46. }
  47. abortRequest(requestId: number) {
  48. NativeNetworkingIOS.abortRequest(requestId);
  49. }
  50. clearCookies(callback: (result: boolean) => void) {
  51. NativeNetworkingIOS.clearCookies(callback);
  52. }
  53. }
  54. module.exports = (new RCTNetworking(): RCTNetworking);