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

     1  import { importModule, Application, heap, Pointer } from "@ffi";
     2  
     3  importModule("plat/js/webext/desktopcapture", (A: Application) => {
     4    const WEBEXT = typeof globalThis.browser === "undefined" ? globalThis.chrome : globalThis.browser;
     5  
     6    return {
     7      "store_ChooseDesktopMediaArgCallbackArgOptions": (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 + 1, false);
    12          A.store.Bool(ptr + 0, false);
    13        } else {
    14          A.store.Bool(ptr + 1, true);
    15          A.store.Bool(ptr + 0, x["canRequestAudioTrack"] ? true : false);
    16        }
    17      },
    18      "load_ChooseDesktopMediaArgCallbackArgOptions": (
    19        ptr: Pointer,
    20        create: heap.Ref<boolean>,
    21        ref: heap.Ref<any>
    22      ): heap.Ref<any> => {
    23        const x = create === A.H.TRUE ? {} : A.H.get<any>(ref);
    24  
    25        x["canRequestAudioTrack"] = A.load.Bool(ptr + 0);
    26        return create === A.H.TRUE ? A.H.push(x) : ref;
    27      },
    28      "constof_SelfCapturePreferenceEnum": (ref: heap.Ref<string>): number => {
    29        const idx = ["include", "exclude"].indexOf(A.H.get(ref));
    30        return idx < 0 ? 0 : idx + 1;
    31      },
    32      "constof_SystemAudioPreferenceEnum": (ref: heap.Ref<string>): number => {
    33        const idx = ["include", "exclude"].indexOf(A.H.get(ref));
    34        return idx < 0 ? 0 : idx + 1;
    35      },
    36  
    37      "store_ChooseDesktopMediaArgOptions": (ptr: Pointer, ref: heap.Ref<any>) => {
    38        const x = A.H.get<any>(ref);
    39  
    40        if (typeof x === "undefined") {
    41          A.store.Bool(ptr + 13, false);
    42          A.store.Enum(ptr + 0, -1);
    43          A.store.Bool(ptr + 12, false);
    44          A.store.Bool(ptr + 4, false);
    45          A.store.Enum(ptr + 8, -1);
    46        } else {
    47          A.store.Bool(ptr + 13, true);
    48          A.store.Enum(ptr + 0, ["include", "exclude"].indexOf(x["selfBrowserSurface"] as string));
    49          A.store.Bool(ptr + 12, "suppressLocalAudioPlaybackIntended" in x ? true : false);
    50          A.store.Bool(ptr + 4, x["suppressLocalAudioPlaybackIntended"] ? true : false);
    51          A.store.Enum(ptr + 8, ["include", "exclude"].indexOf(x["systemAudio"] as string));
    52        }
    53      },
    54      "load_ChooseDesktopMediaArgOptions": (
    55        ptr: Pointer,
    56        create: heap.Ref<boolean>,
    57        ref: heap.Ref<any>
    58      ): heap.Ref<any> => {
    59        const x = create === A.H.TRUE ? {} : A.H.get<any>(ref);
    60  
    61        x["selfBrowserSurface"] = A.load.Enum(ptr + 0, ["include", "exclude"]);
    62        if (A.load.Bool(ptr + 12)) {
    63          x["suppressLocalAudioPlaybackIntended"] = A.load.Bool(ptr + 4);
    64        } else {
    65          delete x["suppressLocalAudioPlaybackIntended"];
    66        }
    67        x["systemAudio"] = A.load.Enum(ptr + 8, ["include", "exclude"]);
    68        return create === A.H.TRUE ? A.H.push(x) : ref;
    69      },
    70      "constof_DesktopCaptureSourceType": (ref: heap.Ref<string>): number => {
    71        const idx = ["screen", "window", "tab", "audio"].indexOf(A.H.get(ref));
    72        return idx < 0 ? 0 : idx + 1;
    73      },
    74      "has_CancelChooseDesktopMedia": (): heap.Ref<boolean> => {
    75        if (WEBEXT?.desktopCapture && "cancelChooseDesktopMedia" in WEBEXT?.desktopCapture) {
    76          return A.H.TRUE;
    77        }
    78        return A.H.FALSE;
    79      },
    80      "func_CancelChooseDesktopMedia": (fn: Pointer): void => {
    81        A.store.Ref(fn, WEBEXT.desktopCapture.cancelChooseDesktopMedia);
    82      },
    83      "call_CancelChooseDesktopMedia": (retPtr: Pointer, desktopMediaRequestId: number): void => {
    84        const _ret = WEBEXT.desktopCapture.cancelChooseDesktopMedia(desktopMediaRequestId);
    85      },
    86      "try_CancelChooseDesktopMedia": (
    87        retPtr: Pointer,
    88        errPtr: Pointer,
    89        desktopMediaRequestId: number
    90      ): heap.Ref<boolean> => {
    91        try {
    92          const _ret = WEBEXT.desktopCapture.cancelChooseDesktopMedia(desktopMediaRequestId);
    93          return A.H.TRUE;
    94        } catch (err: any) {
    95          A.store.Ref(errPtr, err);
    96          return A.H.FALSE;
    97        }
    98      },
    99      "has_ChooseDesktopMedia": (): heap.Ref<boolean> => {
   100        if (WEBEXT?.desktopCapture && "chooseDesktopMedia" in WEBEXT?.desktopCapture) {
   101          return A.H.TRUE;
   102        }
   103        return A.H.FALSE;
   104      },
   105      "func_ChooseDesktopMedia": (fn: Pointer): void => {
   106        A.store.Ref(fn, WEBEXT.desktopCapture.chooseDesktopMedia);
   107      },
   108      "call_ChooseDesktopMedia": (
   109        retPtr: Pointer,
   110        sources: heap.Ref<object>,
   111        targetTab: Pointer,
   112        options: Pointer,
   113        callback: heap.Ref<object>
   114      ): void => {
   115        const targetTab_ffi = {};
   116  
   117        targetTab_ffi["active"] = A.load.Bool(targetTab + 0);
   118        if (A.load.Bool(targetTab + 0)) {
   119          targetTab_ffi["audible"] = A.load.Bool(targetTab + 0);
   120        }
   121        targetTab_ffi["autoDiscardable"] = A.load.Bool(targetTab + 0);
   122        targetTab_ffi["discarded"] = A.load.Bool(targetTab + 0);
   123        targetTab_ffi["favIconUrl"] = A.load.Ref(targetTab + 0, undefined);
   124        targetTab_ffi["groupId"] = A.load.Int0(targetTab + 0);
   125        if (A.load.Bool(targetTab + 0)) {
   126          targetTab_ffi["height"] = A.load.Int0(targetTab + 0);
   127        }
   128        targetTab_ffi["highlighted"] = A.load.Bool(targetTab + 0);
   129        if (A.load.Bool(targetTab + 0)) {
   130          targetTab_ffi["id"] = A.load.Int0(targetTab + 0);
   131        }
   132        targetTab_ffi["incognito"] = A.load.Bool(targetTab + 0);
   133        targetTab_ffi["index"] = A.load.Int0(targetTab + 0);
   134        if (A.load.Bool(targetTab + 0 + 0)) {
   135          targetTab_ffi["mutedInfo"] = {};
   136          targetTab_ffi["mutedInfo"]["extensionId"] = A.load.Ref(targetTab + 0 + 0, undefined);
   137          targetTab_ffi["mutedInfo"]["muted"] = A.load.Bool(targetTab + 0 + 0);
   138          targetTab_ffi["mutedInfo"]["reason"] = A.load.Enum(targetTab + 0 + 0, ["user", "capture", "extension"]);
   139        }
   140        if (A.load.Bool(targetTab + 0)) {
   141          targetTab_ffi["openerTabId"] = A.load.Int0(targetTab + 0);
   142        }
   143        targetTab_ffi["pendingUrl"] = A.load.Ref(targetTab + 0, undefined);
   144        targetTab_ffi["pinned"] = A.load.Bool(targetTab + 0);
   145        targetTab_ffi["selected"] = A.load.Bool(targetTab + 0);
   146        targetTab_ffi["sessionId"] = A.load.Ref(targetTab + 0, undefined);
   147        targetTab_ffi["status"] = A.load.Enum(targetTab + 0, ["unloaded", "loading", "complete"]);
   148        targetTab_ffi["title"] = A.load.Ref(targetTab + 0, undefined);
   149        targetTab_ffi["url"] = A.load.Ref(targetTab + 0, undefined);
   150        if (A.load.Bool(targetTab + 0)) {
   151          targetTab_ffi["width"] = A.load.Int0(targetTab + 0);
   152        }
   153        targetTab_ffi["windowId"] = A.load.Int0(targetTab + 0);
   154  
   155        const options_ffi = {};
   156  
   157        options_ffi["selfBrowserSurface"] = A.load.Enum(options + 0, ["include", "exclude"]);
   158        if (A.load.Bool(options + 12)) {
   159          options_ffi["suppressLocalAudioPlaybackIntended"] = A.load.Bool(options + 4);
   160        }
   161        options_ffi["systemAudio"] = A.load.Enum(options + 8, ["include", "exclude"]);
   162  
   163        const _ret = WEBEXT.desktopCapture.chooseDesktopMedia(
   164          A.H.get<object>(sources),
   165          targetTab_ffi,
   166          options_ffi,
   167          A.H.get<object>(callback)
   168        );
   169        A.store.Int64(retPtr, _ret);
   170      },
   171      "try_ChooseDesktopMedia": (
   172        retPtr: Pointer,
   173        errPtr: Pointer,
   174        sources: heap.Ref<object>,
   175        targetTab: Pointer,
   176        options: Pointer,
   177        callback: heap.Ref<object>
   178      ): heap.Ref<boolean> => {
   179        try {
   180          const targetTab_ffi = {};
   181  
   182          targetTab_ffi["active"] = A.load.Bool(targetTab + 0);
   183          if (A.load.Bool(targetTab + 0)) {
   184            targetTab_ffi["audible"] = A.load.Bool(targetTab + 0);
   185          }
   186          targetTab_ffi["autoDiscardable"] = A.load.Bool(targetTab + 0);
   187          targetTab_ffi["discarded"] = A.load.Bool(targetTab + 0);
   188          targetTab_ffi["favIconUrl"] = A.load.Ref(targetTab + 0, undefined);
   189          targetTab_ffi["groupId"] = A.load.Int0(targetTab + 0);
   190          if (A.load.Bool(targetTab + 0)) {
   191            targetTab_ffi["height"] = A.load.Int0(targetTab + 0);
   192          }
   193          targetTab_ffi["highlighted"] = A.load.Bool(targetTab + 0);
   194          if (A.load.Bool(targetTab + 0)) {
   195            targetTab_ffi["id"] = A.load.Int0(targetTab + 0);
   196          }
   197          targetTab_ffi["incognito"] = A.load.Bool(targetTab + 0);
   198          targetTab_ffi["index"] = A.load.Int0(targetTab + 0);
   199          if (A.load.Bool(targetTab + 0 + 0)) {
   200            targetTab_ffi["mutedInfo"] = {};
   201            targetTab_ffi["mutedInfo"]["extensionId"] = A.load.Ref(targetTab + 0 + 0, undefined);
   202            targetTab_ffi["mutedInfo"]["muted"] = A.load.Bool(targetTab + 0 + 0);
   203            targetTab_ffi["mutedInfo"]["reason"] = A.load.Enum(targetTab + 0 + 0, ["user", "capture", "extension"]);
   204          }
   205          if (A.load.Bool(targetTab + 0)) {
   206            targetTab_ffi["openerTabId"] = A.load.Int0(targetTab + 0);
   207          }
   208          targetTab_ffi["pendingUrl"] = A.load.Ref(targetTab + 0, undefined);
   209          targetTab_ffi["pinned"] = A.load.Bool(targetTab + 0);
   210          targetTab_ffi["selected"] = A.load.Bool(targetTab + 0);
   211          targetTab_ffi["sessionId"] = A.load.Ref(targetTab + 0, undefined);
   212          targetTab_ffi["status"] = A.load.Enum(targetTab + 0, ["unloaded", "loading", "complete"]);
   213          targetTab_ffi["title"] = A.load.Ref(targetTab + 0, undefined);
   214          targetTab_ffi["url"] = A.load.Ref(targetTab + 0, undefined);
   215          if (A.load.Bool(targetTab + 0)) {
   216            targetTab_ffi["width"] = A.load.Int0(targetTab + 0);
   217          }
   218          targetTab_ffi["windowId"] = A.load.Int0(targetTab + 0);
   219  
   220          const options_ffi = {};
   221  
   222          options_ffi["selfBrowserSurface"] = A.load.Enum(options + 0, ["include", "exclude"]);
   223          if (A.load.Bool(options + 12)) {
   224            options_ffi["suppressLocalAudioPlaybackIntended"] = A.load.Bool(options + 4);
   225          }
   226          options_ffi["systemAudio"] = A.load.Enum(options + 8, ["include", "exclude"]);
   227  
   228          const _ret = WEBEXT.desktopCapture.chooseDesktopMedia(
   229            A.H.get<object>(sources),
   230            targetTab_ffi,
   231            options_ffi,
   232            A.H.get<object>(callback)
   233          );
   234          A.store.Int64(retPtr, _ret);
   235          return A.H.TRUE;
   236        } catch (err: any) {
   237          A.store.Ref(errPtr, err);
   238          return A.H.FALSE;
   239        }
   240      },
   241    };
   242  });