123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import { NativeEventEmitter, NativeModules, processColor } from "react-native";
  2. const RNGSModule = NativeModules.RNLGeetestSensebot;
  3. const RNGSEventEmitter = new NativeEventEmitter(RNGSModule);
  4. const EventName = "RNLGeetestSensebotEvent";
  5. export enum Lang {
  6. System = "system", // 跟随系统
  7. ZH = "zh", // 简体中文
  8. ZH_TW = "zh-tw", // 繁体中文
  9. ZH_HK = "zh-hk", // 繁体中文
  10. EN = "en", // 英语
  11. ID = "id", // 印尼语
  12. JA = "ja", // 日语
  13. KO = "ko", // 韩语
  14. RU = "ru", // 俄语
  15. AR = "ar", // 阿拉伯语
  16. ES = "es", // 西班牙语
  17. PT_PT = "pt-pt", // 葡萄牙语
  18. FR = "fr", // 法语
  19. DE = "de", // 德语
  20. }
  21. export enum BackgroundBlurEffectIOS {
  22. None = -1,
  23. ExtraLight = 0,
  24. Light,
  25. Dark,
  26. Regular, // NS_ENUM_AVAILABLE_IOS(10_0)
  27. Prominent, // NS_ENUM_AVAILABLE_IOS(10_0)
  28. }
  29. type Callback = (_: any) => void;
  30. export const start: (option: IGSOption) => void = RNGSModule.start;
  31. export const stop: (callback: Callback) => void = RNGSModule.stop;
  32. export const addListener = (listener: Callback) =>
  33. RNGSEventEmitter.addListener(EventName, listener);
  34. interface IGSOption {
  35. api1Result: string;
  36. debug: boolean;
  37. loadTimeout: number;
  38. reqTimeout: number;
  39. lang: Lang;
  40. enableBackgroundCancel: boolean;
  41. backgroundColorIOS: number;
  42. backgroundBlurEffectIOS: BackgroundBlurEffectIOS;
  43. }
  44. export function parseOption(o: any, defaultOption: IGSOption): IGSOption {
  45. const option = Object.assign({}, defaultOption);
  46. option.api1Result = JSON.stringify(o.api1Result);
  47. if (typeof o.debug === "boolean") {
  48. option.debug = o.debug;
  49. }
  50. if (typeof o.loadTimeout === "number") {
  51. option.loadTimeout = o.loadTimeout >> 0;
  52. }
  53. if (typeof o.reqTimeout === "number") {
  54. option.reqTimeout = o.reqTimeout >> 0;
  55. }
  56. if (typeof o.lang === "string") {
  57. option.lang = o.lang;
  58. }
  59. if (typeof o.enableBackgroundCancel === "boolean") {
  60. option.enableBackgroundCancel = o.enableBackgroundCancel;
  61. }
  62. if (o.backgroundColorIOS !== undefined) {
  63. option.backgroundColorIOS = processColor(o.backgroundColorIOS);
  64. }
  65. if (typeof o.backgroundBlurEffectIOS === "number") {
  66. option.backgroundBlurEffectIOS = o.backgroundBlurEffectIOS;
  67. }
  68. return option;
  69. }