github.com/primecitizens/pcz/std@v0.2.1/plat/js/webext/webrtcdesktopcaptureprivate/apis_js_wasm.go (about)

     1  // SPDX-License-Identifier: Apache-2.0
     2  // Copyright 2023 The Prime Citizens
     3  
     4  package webrtcdesktopcaptureprivate
     5  
     6  import (
     7  	"github.com/primecitizens/pcz/std/core/abi"
     8  	"github.com/primecitizens/pcz/std/ffi/js"
     9  	"github.com/primecitizens/pcz/std/plat/js/webext/webrtcdesktopcaptureprivate/bindings"
    10  )
    11  
    12  type DesktopCaptureSourceType uint32
    13  
    14  const (
    15  	_ DesktopCaptureSourceType = iota
    16  
    17  	DesktopCaptureSourceType_SCREEN
    18  	DesktopCaptureSourceType_WINDOW
    19  	DesktopCaptureSourceType_TAB
    20  )
    21  
    22  func (DesktopCaptureSourceType) FromRef(str js.Ref) DesktopCaptureSourceType {
    23  	return DesktopCaptureSourceType(bindings.ConstOfDesktopCaptureSourceType(str))
    24  }
    25  
    26  func (x DesktopCaptureSourceType) String() (string, bool) {
    27  	switch x {
    28  	case DesktopCaptureSourceType_SCREEN:
    29  		return "screen", true
    30  	case DesktopCaptureSourceType_WINDOW:
    31  		return "window", true
    32  	case DesktopCaptureSourceType_TAB:
    33  		return "tab", true
    34  	default:
    35  		return "", false
    36  	}
    37  }
    38  
    39  type RequestInfo struct {
    40  	// GuestProcessId is "RequestInfo.guestProcessId"
    41  	//
    42  	// Optional
    43  	//
    44  	// NOTE: FFI_USE_GuestProcessId MUST be set to true to make this field effective.
    45  	GuestProcessId int32
    46  	// GuestRenderFrameId is "RequestInfo.guestRenderFrameId"
    47  	//
    48  	// Optional
    49  	//
    50  	// NOTE: FFI_USE_GuestRenderFrameId MUST be set to true to make this field effective.
    51  	GuestRenderFrameId int32
    52  
    53  	FFI_USE_GuestProcessId     bool // for GuestProcessId.
    54  	FFI_USE_GuestRenderFrameId bool // for GuestRenderFrameId.
    55  
    56  	FFI_USE bool
    57  }
    58  
    59  // FromRef calls UpdateFrom and returns a RequestInfo with all fields set.
    60  func (p RequestInfo) FromRef(ref js.Ref) RequestInfo {
    61  	p.UpdateFrom(ref)
    62  	return p
    63  }
    64  
    65  // New creates a new RequestInfo in the application heap.
    66  func (p RequestInfo) New() js.Ref {
    67  	return bindings.RequestInfoJSLoad(
    68  		js.Pointer(&p), js.True, 0,
    69  	)
    70  }
    71  
    72  // UpdateFrom copies value of all fields of the heap object to p.
    73  func (p *RequestInfo) UpdateFrom(ref js.Ref) {
    74  	bindings.RequestInfoJSStore(
    75  		js.Pointer(p), ref,
    76  	)
    77  }
    78  
    79  // Update writes all fields of the p to the heap object referenced by ref.
    80  func (p *RequestInfo) Update(ref js.Ref) {
    81  	bindings.RequestInfoJSLoad(
    82  		js.Pointer(p), js.False, ref,
    83  	)
    84  }
    85  
    86  // FreeMembers frees fields with heap reference, if recursive is true
    87  // free all heap references reachable from p.
    88  func (p *RequestInfo) FreeMembers(recursive bool) {
    89  }
    90  
    91  // HasFuncCancelChooseDesktopMedia returns true if the function "WEBEXT.webrtcDesktopCapturePrivate.cancelChooseDesktopMedia" exists.
    92  func HasFuncCancelChooseDesktopMedia() bool {
    93  	return js.True == bindings.HasFuncCancelChooseDesktopMedia()
    94  }
    95  
    96  // FuncCancelChooseDesktopMedia returns the function "WEBEXT.webrtcDesktopCapturePrivate.cancelChooseDesktopMedia".
    97  func FuncCancelChooseDesktopMedia() (fn js.Func[func(desktopMediaRequestId int32)]) {
    98  	bindings.FuncCancelChooseDesktopMedia(
    99  		js.Pointer(&fn),
   100  	)
   101  	return
   102  }
   103  
   104  // CancelChooseDesktopMedia calls the function "WEBEXT.webrtcDesktopCapturePrivate.cancelChooseDesktopMedia" directly.
   105  func CancelChooseDesktopMedia(desktopMediaRequestId int32) (ret js.Void) {
   106  	bindings.CallCancelChooseDesktopMedia(
   107  		js.Pointer(&ret),
   108  		int32(desktopMediaRequestId),
   109  	)
   110  
   111  	return
   112  }
   113  
   114  // TryCancelChooseDesktopMedia calls the function "WEBEXT.webrtcDesktopCapturePrivate.cancelChooseDesktopMedia"
   115  // in a try/catch block and returns (_, err, ok = false) when it went through
   116  // the catch clause.
   117  func TryCancelChooseDesktopMedia(desktopMediaRequestId int32) (ret js.Void, exception js.Any, ok bool) {
   118  	ok = js.True == bindings.TryCancelChooseDesktopMedia(
   119  		js.Pointer(&ret), js.Pointer(&exception),
   120  		int32(desktopMediaRequestId),
   121  	)
   122  
   123  	return
   124  }
   125  
   126  type ChooseDesktopMediaCallbackFunc func(this js.Ref, streamId js.String) js.Ref
   127  
   128  func (fn ChooseDesktopMediaCallbackFunc) Register() js.Func[func(streamId js.String)] {
   129  	return js.RegisterCallback[func(streamId js.String)](
   130  		fn, abi.FuncPCABIInternal(fn),
   131  	)
   132  }
   133  
   134  func (fn ChooseDesktopMediaCallbackFunc) DispatchCallback(
   135  	targetPC uintptr, ctx *js.CallbackContext,
   136  ) {
   137  	args := ctx.Args()
   138  	if len(args) != 1+1 /* js this */ ||
   139  		targetPC != uintptr(abi.FuncPCABIInternal(fn)) {
   140  		js.ThrowInvalidCallbackInvocation()
   141  	}
   142  
   143  	if ctx.Return(fn(
   144  		args[0],
   145  
   146  		js.String{}.FromRef(args[0+1]),
   147  	)) {
   148  		return
   149  	}
   150  
   151  	js.ThrowCallbackValueNotReturned()
   152  }
   153  
   154  type ChooseDesktopMediaCallback[T any] struct {
   155  	Fn  func(arg T, this js.Ref, streamId js.String) js.Ref
   156  	Arg T
   157  }
   158  
   159  func (cb *ChooseDesktopMediaCallback[T]) Register() js.Func[func(streamId js.String)] {
   160  	return js.RegisterCallback[func(streamId js.String)](
   161  		cb, abi.FuncPCABIInternal(cb.Fn),
   162  	)
   163  }
   164  
   165  func (cb *ChooseDesktopMediaCallback[T]) DispatchCallback(
   166  	targetPC uintptr, ctx *js.CallbackContext,
   167  ) {
   168  	args := ctx.Args()
   169  	if len(args) != 1+1 /* js this */ ||
   170  		targetPC != uintptr(abi.FuncPCABIInternal(cb.Fn)) {
   171  		js.ThrowInvalidCallbackInvocation()
   172  	}
   173  
   174  	if ctx.Return(cb.Fn(
   175  		cb.Arg,
   176  		args[0],
   177  
   178  		js.String{}.FromRef(args[0+1]),
   179  	)) {
   180  		return
   181  	}
   182  
   183  	js.ThrowCallbackValueNotReturned()
   184  }
   185  
   186  // HasFuncChooseDesktopMedia returns true if the function "WEBEXT.webrtcDesktopCapturePrivate.chooseDesktopMedia" exists.
   187  func HasFuncChooseDesktopMedia() bool {
   188  	return js.True == bindings.HasFuncChooseDesktopMedia()
   189  }
   190  
   191  // FuncChooseDesktopMedia returns the function "WEBEXT.webrtcDesktopCapturePrivate.chooseDesktopMedia".
   192  func FuncChooseDesktopMedia() (fn js.Func[func(sources js.Array[DesktopCaptureSourceType], request RequestInfo, callback js.Func[func(streamId js.String)]) int32]) {
   193  	bindings.FuncChooseDesktopMedia(
   194  		js.Pointer(&fn),
   195  	)
   196  	return
   197  }
   198  
   199  // ChooseDesktopMedia calls the function "WEBEXT.webrtcDesktopCapturePrivate.chooseDesktopMedia" directly.
   200  func ChooseDesktopMedia(sources js.Array[DesktopCaptureSourceType], request RequestInfo, callback js.Func[func(streamId js.String)]) (ret int32) {
   201  	bindings.CallChooseDesktopMedia(
   202  		js.Pointer(&ret),
   203  		sources.Ref(),
   204  		js.Pointer(&request),
   205  		callback.Ref(),
   206  	)
   207  
   208  	return
   209  }
   210  
   211  // TryChooseDesktopMedia calls the function "WEBEXT.webrtcDesktopCapturePrivate.chooseDesktopMedia"
   212  // in a try/catch block and returns (_, err, ok = false) when it went through
   213  // the catch clause.
   214  func TryChooseDesktopMedia(sources js.Array[DesktopCaptureSourceType], request RequestInfo, callback js.Func[func(streamId js.String)]) (ret int32, exception js.Any, ok bool) {
   215  	ok = js.True == bindings.TryChooseDesktopMedia(
   216  		js.Pointer(&ret), js.Pointer(&exception),
   217  		sources.Ref(),
   218  		js.Pointer(&request),
   219  		callback.Ref(),
   220  	)
   221  
   222  	return
   223  }