WebGLXHRNativeInterface.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #if UNITY_WEBGL && !UNITY_EDITOR
  2. using System;
  3. using System.Runtime.InteropServices;
  4. namespace Best.HTTP.Hosts.Connections.WebGL
  5. {
  6. delegate void OnWebGLXHRRequestHandlerDelegate(int nativeId, [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.U1, SizeParamIndex = 2)] byte[] pBuffer, int length);
  7. delegate void OnWebGLXHRBufferDelegate(int nativeId, [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.U1, SizeParamIndex = 2)] byte[] pBuffer, int length);
  8. delegate void OnWebGLXHRProgressDelegate(int nativeId, int downloaded, int total);
  9. delegate void OnWebGLXHRErrorDelegate(int nativeId, string error);
  10. delegate void OnWebGLXHRTimeoutDelegate(int nativeId);
  11. delegate void OnWebGLXHRAbortedDelegate(int nativeId);
  12. delegate IntPtr OnWebGLXHRAllocArray(int nativeId, int size);
  13. internal static class WebGLXHRNativeInterface
  14. {
  15. [DllImport("__Internal")]
  16. public static extern int XHR_Create(string method, string url, string userName, string passwd, int withCredentials);
  17. /// <summary>
  18. /// Is an unsigned long representing the number of milliseconds a request can take before automatically being terminated. A value of 0 (which is the default) means there is no timeout.
  19. /// </summary>
  20. [DllImport("__Internal")]
  21. public static extern void XHR_SetTimeout(int nativeId, uint timeout);
  22. [DllImport("__Internal")]
  23. public static extern void XHR_SetRequestHeader(int nativeId, string header, string value);
  24. [DllImport("__Internal")]
  25. public static extern void XHR_SetResponseHandler(int nativeId,
  26. OnWebGLXHRRequestHandlerDelegate onresponse,
  27. OnWebGLXHRErrorDelegate onerror,
  28. OnWebGLXHRTimeoutDelegate ontimeout,
  29. OnWebGLXHRAbortedDelegate onabort,
  30. OnWebGLXHRBufferDelegate onbuffer,
  31. OnWebGLXHRAllocArray onallocArray);
  32. [DllImport("__Internal")]
  33. public static extern void XHR_SetProgressHandler(int nativeId, OnWebGLXHRProgressDelegate onDownloadProgress, OnWebGLXHRProgressDelegate onUploadProgress);
  34. [DllImport("__Internal")]
  35. public static extern void XHR_Send(int nativeId, [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.U1, SizeParamIndex = 2)] byte[] body, int length);
  36. [DllImport("__Internal")]
  37. public static extern void XHR_Abort(int nativeId);
  38. [DllImport("__Internal")]
  39. public static extern void XHR_Release(int nativeId);
  40. [DllImport("__Internal")]
  41. public static extern void XHR_SetLoglevel(int logLevel);
  42. }
  43. }
  44. #endif