github.com/primecitizens/pcz/std@v0.2.1/plat/js/webext/mdns/bindings/ffi_bindings.ts (about)

     1  import { importModule, Application, heap, Pointer } from "@ffi";
     2  
     3  importModule("plat/js/webext/mdns", (A: Application) => {
     4    const WEBEXT = typeof globalThis.browser === "undefined" ? globalThis.chrome : globalThis.browser;
     5  
     6    return {
     7      "store_MDnsService": (ptr: Pointer, ref: heap.Ref<any>) => {
     8        const x = A.H.get<any>(ref);
     9  
    10        if (typeof x === "undefined") {
    11          A.store.Bool(ptr + 16, false);
    12          A.store.Ref(ptr + 0, undefined);
    13          A.store.Ref(ptr + 4, undefined);
    14          A.store.Ref(ptr + 8, undefined);
    15          A.store.Ref(ptr + 12, undefined);
    16        } else {
    17          A.store.Bool(ptr + 16, true);
    18          A.store.Ref(ptr + 0, x["serviceName"]);
    19          A.store.Ref(ptr + 4, x["serviceHostPort"]);
    20          A.store.Ref(ptr + 8, x["ipAddress"]);
    21          A.store.Ref(ptr + 12, x["serviceData"]);
    22        }
    23      },
    24      "load_MDnsService": (ptr: Pointer, create: heap.Ref<boolean>, ref: heap.Ref<any>): heap.Ref<any> => {
    25        const x = create === A.H.TRUE ? {} : A.H.get<any>(ref);
    26  
    27        x["serviceName"] = A.load.Ref(ptr + 0, undefined);
    28        x["serviceHostPort"] = A.load.Ref(ptr + 4, undefined);
    29        x["ipAddress"] = A.load.Ref(ptr + 8, undefined);
    30        x["serviceData"] = A.load.Ref(ptr + 12, undefined);
    31        return create === A.H.TRUE ? A.H.push(x) : ref;
    32      },
    33  
    34      "has_Properties_MAX_SERVICE_INSTANCES_PER_EVENT": (self: heap.Ref<any>): heap.Ref<boolean> => {
    35        if (WEBEXT?.mdns && "MAX_SERVICE_INSTANCES_PER_EVENT" in WEBEXT?.mdns) {
    36          return A.H.TRUE;
    37        }
    38        return A.H.FALSE;
    39      },
    40      "func_Properties_MAX_SERVICE_INSTANCES_PER_EVENT": (self: heap.Ref<any>, fn: Pointer): void => {
    41        A.store.Ref(fn, WEBEXT.mdns.MAX_SERVICE_INSTANCES_PER_EVENT);
    42      },
    43  
    44      "call_Properties_MAX_SERVICE_INSTANCES_PER_EVENT": (self: heap.Ref<object>, retPtr: Pointer): void => {
    45        const thiz = A.H.get<any>(self);
    46  
    47        const _ret = Reflect.apply(WEBEXT.mdns.MAX_SERVICE_INSTANCES_PER_EVENT, thiz, []);
    48        A.store.Int32(retPtr, _ret);
    49      },
    50      "try_Properties_MAX_SERVICE_INSTANCES_PER_EVENT": (
    51        self: heap.Ref<object>,
    52        retPtr: Pointer,
    53        errPtr: Pointer
    54      ): heap.Ref<boolean> => {
    55        try {
    56          const thiz = A.H.get<any>(self);
    57  
    58          const _ret = Reflect.apply(WEBEXT.mdns.MAX_SERVICE_INSTANCES_PER_EVENT, thiz, []);
    59          A.store.Int32(retPtr, _ret);
    60          return A.H.TRUE;
    61        } catch (err: any) {
    62          A.store.Ref(errPtr, err);
    63          return A.H.FALSE;
    64        }
    65      },
    66      "has_ForceDiscovery": (): heap.Ref<boolean> => {
    67        if (WEBEXT?.mdns && "forceDiscovery" in WEBEXT?.mdns) {
    68          return A.H.TRUE;
    69        }
    70        return A.H.FALSE;
    71      },
    72      "func_ForceDiscovery": (fn: Pointer): void => {
    73        A.store.Ref(fn, WEBEXT.mdns.forceDiscovery);
    74      },
    75      "call_ForceDiscovery": (retPtr: Pointer): void => {
    76        const _ret = WEBEXT.mdns.forceDiscovery();
    77        A.store.Ref(retPtr, _ret);
    78      },
    79      "try_ForceDiscovery": (retPtr: Pointer, errPtr: Pointer): heap.Ref<boolean> => {
    80        try {
    81          const _ret = WEBEXT.mdns.forceDiscovery();
    82          A.store.Ref(retPtr, _ret);
    83          return A.H.TRUE;
    84        } catch (err: any) {
    85          A.store.Ref(errPtr, err);
    86          return A.H.FALSE;
    87        }
    88      },
    89      "has_OnServiceList": (): heap.Ref<boolean> => {
    90        if (WEBEXT?.mdns?.onServiceList && "addListener" in WEBEXT?.mdns?.onServiceList) {
    91          return A.H.TRUE;
    92        }
    93        return A.H.FALSE;
    94      },
    95      "func_OnServiceList": (fn: Pointer): void => {
    96        A.store.Ref(fn, WEBEXT.mdns.onServiceList.addListener);
    97      },
    98      "call_OnServiceList": (retPtr: Pointer, callback: heap.Ref<object>): void => {
    99        const _ret = WEBEXT.mdns.onServiceList.addListener(A.H.get<object>(callback));
   100      },
   101      "try_OnServiceList": (retPtr: Pointer, errPtr: Pointer, callback: heap.Ref<object>): heap.Ref<boolean> => {
   102        try {
   103          const _ret = WEBEXT.mdns.onServiceList.addListener(A.H.get<object>(callback));
   104          return A.H.TRUE;
   105        } catch (err: any) {
   106          A.store.Ref(errPtr, err);
   107          return A.H.FALSE;
   108        }
   109      },
   110      "has_OffServiceList": (): heap.Ref<boolean> => {
   111        if (WEBEXT?.mdns?.onServiceList && "removeListener" in WEBEXT?.mdns?.onServiceList) {
   112          return A.H.TRUE;
   113        }
   114        return A.H.FALSE;
   115      },
   116      "func_OffServiceList": (fn: Pointer): void => {
   117        A.store.Ref(fn, WEBEXT.mdns.onServiceList.removeListener);
   118      },
   119      "call_OffServiceList": (retPtr: Pointer, callback: heap.Ref<object>): void => {
   120        const _ret = WEBEXT.mdns.onServiceList.removeListener(A.H.get<object>(callback));
   121      },
   122      "try_OffServiceList": (retPtr: Pointer, errPtr: Pointer, callback: heap.Ref<object>): heap.Ref<boolean> => {
   123        try {
   124          const _ret = WEBEXT.mdns.onServiceList.removeListener(A.H.get<object>(callback));
   125          return A.H.TRUE;
   126        } catch (err: any) {
   127          A.store.Ref(errPtr, err);
   128          return A.H.FALSE;
   129        }
   130      },
   131      "has_HasOnServiceList": (): heap.Ref<boolean> => {
   132        if (WEBEXT?.mdns?.onServiceList && "hasListener" in WEBEXT?.mdns?.onServiceList) {
   133          return A.H.TRUE;
   134        }
   135        return A.H.FALSE;
   136      },
   137      "func_HasOnServiceList": (fn: Pointer): void => {
   138        A.store.Ref(fn, WEBEXT.mdns.onServiceList.hasListener);
   139      },
   140      "call_HasOnServiceList": (retPtr: Pointer, callback: heap.Ref<object>): void => {
   141        const _ret = WEBEXT.mdns.onServiceList.hasListener(A.H.get<object>(callback));
   142        A.store.Bool(retPtr, _ret);
   143      },
   144      "try_HasOnServiceList": (retPtr: Pointer, errPtr: Pointer, callback: heap.Ref<object>): heap.Ref<boolean> => {
   145        try {
   146          const _ret = WEBEXT.mdns.onServiceList.hasListener(A.H.get<object>(callback));
   147          A.store.Bool(retPtr, _ret);
   148          return A.H.TRUE;
   149        } catch (err: any) {
   150          A.store.Ref(errPtr, err);
   151          return A.H.FALSE;
   152        }
   153      },
   154    };
   155  });