فهرست منبع

Merge pull request #9148 from ryantrem/xmlhttprequest-native-override

Allow override of XMLHttpRequest for Babylon Native
Raanan Weber 4 سال پیش
والد
کامیت
7cb5aef616
1فایلهای تغییر یافته به همراه14 افزوده شده و 1 حذف شده
  1. 14 1
      src/Misc/webRequest.ts

+ 14 - 1
src/Misc/webRequest.ts

@@ -1,11 +1,24 @@
 import { IWebRequest } from './interfaces/iWebRequest';
 import { Nullable } from '../types';
 
+/** @hidden */
+declare const _native: any;
+
+/** @hidden */
+function createXMLHttpRequest(): XMLHttpRequest {
+    // If running in Babylon Native, then defer to the native XMLHttpRequest, which has the same public contract
+    if (typeof _native !== 'undefined' && _native.XMLHttpRequest) {
+        return new _native.XMLHttpRequest();
+    } else {
+        return new XMLHttpRequest();
+    }
+}
+
 /**
  * Extended version of XMLHttpRequest with support for customizations (headers, ...)
  */
 export class WebRequest implements IWebRequest {
-    private _xhr = new XMLHttpRequest();
+    private readonly _xhr = createXMLHttpRequest();
 
     /**
      * Custom HTTP Request Headers to be sent with XMLHttpRequests