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

     1  // SPDX-License-Identifier: Apache-2.0
     2  // Copyright 2023 The Prime Citizens
     3  
     4  package webrtcaudioprivate
     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/webrtcaudioprivate/bindings"
    10  )
    11  
    12  type GetSinksCallbackFunc func(this js.Ref, sinkInfo js.Array[SinkInfo]) js.Ref
    13  
    14  func (fn GetSinksCallbackFunc) Register() js.Func[func(sinkInfo js.Array[SinkInfo])] {
    15  	return js.RegisterCallback[func(sinkInfo js.Array[SinkInfo])](
    16  		fn, abi.FuncPCABIInternal(fn),
    17  	)
    18  }
    19  
    20  func (fn GetSinksCallbackFunc) DispatchCallback(
    21  	targetPC uintptr, ctx *js.CallbackContext,
    22  ) {
    23  	args := ctx.Args()
    24  	if len(args) != 1+1 /* js this */ ||
    25  		targetPC != uintptr(abi.FuncPCABIInternal(fn)) {
    26  		js.ThrowInvalidCallbackInvocation()
    27  	}
    28  
    29  	if ctx.Return(fn(
    30  		args[0],
    31  
    32  		js.Array[SinkInfo]{}.FromRef(args[0+1]),
    33  	)) {
    34  		return
    35  	}
    36  
    37  	js.ThrowCallbackValueNotReturned()
    38  }
    39  
    40  type GetSinksCallback[T any] struct {
    41  	Fn  func(arg T, this js.Ref, sinkInfo js.Array[SinkInfo]) js.Ref
    42  	Arg T
    43  }
    44  
    45  func (cb *GetSinksCallback[T]) Register() js.Func[func(sinkInfo js.Array[SinkInfo])] {
    46  	return js.RegisterCallback[func(sinkInfo js.Array[SinkInfo])](
    47  		cb, abi.FuncPCABIInternal(cb.Fn),
    48  	)
    49  }
    50  
    51  func (cb *GetSinksCallback[T]) DispatchCallback(
    52  	targetPC uintptr, ctx *js.CallbackContext,
    53  ) {
    54  	args := ctx.Args()
    55  	if len(args) != 1+1 /* js this */ ||
    56  		targetPC != uintptr(abi.FuncPCABIInternal(cb.Fn)) {
    57  		js.ThrowInvalidCallbackInvocation()
    58  	}
    59  
    60  	if ctx.Return(cb.Fn(
    61  		cb.Arg,
    62  		args[0],
    63  
    64  		js.Array[SinkInfo]{}.FromRef(args[0+1]),
    65  	)) {
    66  		return
    67  	}
    68  
    69  	js.ThrowCallbackValueNotReturned()
    70  }
    71  
    72  type SinkInfo struct {
    73  	// SinkId is "SinkInfo.sinkId"
    74  	//
    75  	// Optional
    76  	SinkId js.String
    77  	// SinkLabel is "SinkInfo.sinkLabel"
    78  	//
    79  	// Optional
    80  	SinkLabel js.String
    81  	// SampleRate is "SinkInfo.sampleRate"
    82  	//
    83  	// Optional
    84  	//
    85  	// NOTE: FFI_USE_SampleRate MUST be set to true to make this field effective.
    86  	SampleRate int32
    87  	// IsReady is "SinkInfo.isReady"
    88  	//
    89  	// Optional
    90  	//
    91  	// NOTE: FFI_USE_IsReady MUST be set to true to make this field effective.
    92  	IsReady bool
    93  	// IsDefault is "SinkInfo.isDefault"
    94  	//
    95  	// Optional
    96  	//
    97  	// NOTE: FFI_USE_IsDefault MUST be set to true to make this field effective.
    98  	IsDefault bool
    99  
   100  	FFI_USE_SampleRate bool // for SampleRate.
   101  	FFI_USE_IsReady    bool // for IsReady.
   102  	FFI_USE_IsDefault  bool // for IsDefault.
   103  
   104  	FFI_USE bool
   105  }
   106  
   107  // FromRef calls UpdateFrom and returns a SinkInfo with all fields set.
   108  func (p SinkInfo) FromRef(ref js.Ref) SinkInfo {
   109  	p.UpdateFrom(ref)
   110  	return p
   111  }
   112  
   113  // New creates a new SinkInfo in the application heap.
   114  func (p SinkInfo) New() js.Ref {
   115  	return bindings.SinkInfoJSLoad(
   116  		js.Pointer(&p), js.True, 0,
   117  	)
   118  }
   119  
   120  // UpdateFrom copies value of all fields of the heap object to p.
   121  func (p *SinkInfo) UpdateFrom(ref js.Ref) {
   122  	bindings.SinkInfoJSStore(
   123  		js.Pointer(p), ref,
   124  	)
   125  }
   126  
   127  // Update writes all fields of the p to the heap object referenced by ref.
   128  func (p *SinkInfo) Update(ref js.Ref) {
   129  	bindings.SinkInfoJSLoad(
   130  		js.Pointer(p), js.False, ref,
   131  	)
   132  }
   133  
   134  // FreeMembers frees fields with heap reference, if recursive is true
   135  // free all heap references reachable from p.
   136  func (p *SinkInfo) FreeMembers(recursive bool) {
   137  	js.Free(
   138  		p.SinkId.Ref(),
   139  		p.SinkLabel.Ref(),
   140  	)
   141  	p.SinkId = p.SinkId.FromRef(js.Undefined)
   142  	p.SinkLabel = p.SinkLabel.FromRef(js.Undefined)
   143  }
   144  
   145  type SinkIdCallbackFunc func(this js.Ref, sinkId js.String) js.Ref
   146  
   147  func (fn SinkIdCallbackFunc) Register() js.Func[func(sinkId js.String)] {
   148  	return js.RegisterCallback[func(sinkId js.String)](
   149  		fn, abi.FuncPCABIInternal(fn),
   150  	)
   151  }
   152  
   153  func (fn SinkIdCallbackFunc) DispatchCallback(
   154  	targetPC uintptr, ctx *js.CallbackContext,
   155  ) {
   156  	args := ctx.Args()
   157  	if len(args) != 1+1 /* js this */ ||
   158  		targetPC != uintptr(abi.FuncPCABIInternal(fn)) {
   159  		js.ThrowInvalidCallbackInvocation()
   160  	}
   161  
   162  	if ctx.Return(fn(
   163  		args[0],
   164  
   165  		js.String{}.FromRef(args[0+1]),
   166  	)) {
   167  		return
   168  	}
   169  
   170  	js.ThrowCallbackValueNotReturned()
   171  }
   172  
   173  type SinkIdCallback[T any] struct {
   174  	Fn  func(arg T, this js.Ref, sinkId js.String) js.Ref
   175  	Arg T
   176  }
   177  
   178  func (cb *SinkIdCallback[T]) Register() js.Func[func(sinkId js.String)] {
   179  	return js.RegisterCallback[func(sinkId js.String)](
   180  		cb, abi.FuncPCABIInternal(cb.Fn),
   181  	)
   182  }
   183  
   184  func (cb *SinkIdCallback[T]) DispatchCallback(
   185  	targetPC uintptr, ctx *js.CallbackContext,
   186  ) {
   187  	args := ctx.Args()
   188  	if len(args) != 1+1 /* js this */ ||
   189  		targetPC != uintptr(abi.FuncPCABIInternal(cb.Fn)) {
   190  		js.ThrowInvalidCallbackInvocation()
   191  	}
   192  
   193  	if ctx.Return(cb.Fn(
   194  		cb.Arg,
   195  		args[0],
   196  
   197  		js.String{}.FromRef(args[0+1]),
   198  	)) {
   199  		return
   200  	}
   201  
   202  	js.ThrowCallbackValueNotReturned()
   203  }
   204  
   205  // HasFuncGetAssociatedSink returns true if the function "WEBEXT.webrtcAudioPrivate.getAssociatedSink" exists.
   206  func HasFuncGetAssociatedSink() bool {
   207  	return js.True == bindings.HasFuncGetAssociatedSink()
   208  }
   209  
   210  // FuncGetAssociatedSink returns the function "WEBEXT.webrtcAudioPrivate.getAssociatedSink".
   211  func FuncGetAssociatedSink() (fn js.Func[func(securityOrigin js.String, sourceIdInOrigin js.String) js.Promise[js.String]]) {
   212  	bindings.FuncGetAssociatedSink(
   213  		js.Pointer(&fn),
   214  	)
   215  	return
   216  }
   217  
   218  // GetAssociatedSink calls the function "WEBEXT.webrtcAudioPrivate.getAssociatedSink" directly.
   219  func GetAssociatedSink(securityOrigin js.String, sourceIdInOrigin js.String) (ret js.Promise[js.String]) {
   220  	bindings.CallGetAssociatedSink(
   221  		js.Pointer(&ret),
   222  		securityOrigin.Ref(),
   223  		sourceIdInOrigin.Ref(),
   224  	)
   225  
   226  	return
   227  }
   228  
   229  // TryGetAssociatedSink calls the function "WEBEXT.webrtcAudioPrivate.getAssociatedSink"
   230  // in a try/catch block and returns (_, err, ok = false) when it went through
   231  // the catch clause.
   232  func TryGetAssociatedSink(securityOrigin js.String, sourceIdInOrigin js.String) (ret js.Promise[js.String], exception js.Any, ok bool) {
   233  	ok = js.True == bindings.TryGetAssociatedSink(
   234  		js.Pointer(&ret), js.Pointer(&exception),
   235  		securityOrigin.Ref(),
   236  		sourceIdInOrigin.Ref(),
   237  	)
   238  
   239  	return
   240  }
   241  
   242  // HasFuncGetSinks returns true if the function "WEBEXT.webrtcAudioPrivate.getSinks" exists.
   243  func HasFuncGetSinks() bool {
   244  	return js.True == bindings.HasFuncGetSinks()
   245  }
   246  
   247  // FuncGetSinks returns the function "WEBEXT.webrtcAudioPrivate.getSinks".
   248  func FuncGetSinks() (fn js.Func[func() js.Promise[js.Array[SinkInfo]]]) {
   249  	bindings.FuncGetSinks(
   250  		js.Pointer(&fn),
   251  	)
   252  	return
   253  }
   254  
   255  // GetSinks calls the function "WEBEXT.webrtcAudioPrivate.getSinks" directly.
   256  func GetSinks() (ret js.Promise[js.Array[SinkInfo]]) {
   257  	bindings.CallGetSinks(
   258  		js.Pointer(&ret),
   259  	)
   260  
   261  	return
   262  }
   263  
   264  // TryGetSinks calls the function "WEBEXT.webrtcAudioPrivate.getSinks"
   265  // in a try/catch block and returns (_, err, ok = false) when it went through
   266  // the catch clause.
   267  func TryGetSinks() (ret js.Promise[js.Array[SinkInfo]], exception js.Any, ok bool) {
   268  	ok = js.True == bindings.TryGetSinks(
   269  		js.Pointer(&ret), js.Pointer(&exception),
   270  	)
   271  
   272  	return
   273  }
   274  
   275  type OnSinksChangedEventCallbackFunc func(this js.Ref) js.Ref
   276  
   277  func (fn OnSinksChangedEventCallbackFunc) Register() js.Func[func()] {
   278  	return js.RegisterCallback[func()](
   279  		fn, abi.FuncPCABIInternal(fn),
   280  	)
   281  }
   282  
   283  func (fn OnSinksChangedEventCallbackFunc) DispatchCallback(
   284  	targetPC uintptr, ctx *js.CallbackContext,
   285  ) {
   286  	args := ctx.Args()
   287  	if len(args) != 0+1 /* js this */ ||
   288  		targetPC != uintptr(abi.FuncPCABIInternal(fn)) {
   289  		js.ThrowInvalidCallbackInvocation()
   290  	}
   291  
   292  	if ctx.Return(fn(
   293  		args[0],
   294  	)) {
   295  		return
   296  	}
   297  
   298  	js.ThrowCallbackValueNotReturned()
   299  }
   300  
   301  type OnSinksChangedEventCallback[T any] struct {
   302  	Fn  func(arg T, this js.Ref) js.Ref
   303  	Arg T
   304  }
   305  
   306  func (cb *OnSinksChangedEventCallback[T]) Register() js.Func[func()] {
   307  	return js.RegisterCallback[func()](
   308  		cb, abi.FuncPCABIInternal(cb.Fn),
   309  	)
   310  }
   311  
   312  func (cb *OnSinksChangedEventCallback[T]) DispatchCallback(
   313  	targetPC uintptr, ctx *js.CallbackContext,
   314  ) {
   315  	args := ctx.Args()
   316  	if len(args) != 0+1 /* js this */ ||
   317  		targetPC != uintptr(abi.FuncPCABIInternal(cb.Fn)) {
   318  		js.ThrowInvalidCallbackInvocation()
   319  	}
   320  
   321  	if ctx.Return(cb.Fn(
   322  		cb.Arg,
   323  		args[0],
   324  	)) {
   325  		return
   326  	}
   327  
   328  	js.ThrowCallbackValueNotReturned()
   329  }
   330  
   331  // HasFuncOnSinksChanged returns true if the function "WEBEXT.webrtcAudioPrivate.onSinksChanged.addListener" exists.
   332  func HasFuncOnSinksChanged() bool {
   333  	return js.True == bindings.HasFuncOnSinksChanged()
   334  }
   335  
   336  // FuncOnSinksChanged returns the function "WEBEXT.webrtcAudioPrivate.onSinksChanged.addListener".
   337  func FuncOnSinksChanged() (fn js.Func[func(callback js.Func[func()])]) {
   338  	bindings.FuncOnSinksChanged(
   339  		js.Pointer(&fn),
   340  	)
   341  	return
   342  }
   343  
   344  // OnSinksChanged calls the function "WEBEXT.webrtcAudioPrivate.onSinksChanged.addListener" directly.
   345  func OnSinksChanged(callback js.Func[func()]) (ret js.Void) {
   346  	bindings.CallOnSinksChanged(
   347  		js.Pointer(&ret),
   348  		callback.Ref(),
   349  	)
   350  
   351  	return
   352  }
   353  
   354  // TryOnSinksChanged calls the function "WEBEXT.webrtcAudioPrivate.onSinksChanged.addListener"
   355  // in a try/catch block and returns (_, err, ok = false) when it went through
   356  // the catch clause.
   357  func TryOnSinksChanged(callback js.Func[func()]) (ret js.Void, exception js.Any, ok bool) {
   358  	ok = js.True == bindings.TryOnSinksChanged(
   359  		js.Pointer(&ret), js.Pointer(&exception),
   360  		callback.Ref(),
   361  	)
   362  
   363  	return
   364  }
   365  
   366  // HasFuncOffSinksChanged returns true if the function "WEBEXT.webrtcAudioPrivate.onSinksChanged.removeListener" exists.
   367  func HasFuncOffSinksChanged() bool {
   368  	return js.True == bindings.HasFuncOffSinksChanged()
   369  }
   370  
   371  // FuncOffSinksChanged returns the function "WEBEXT.webrtcAudioPrivate.onSinksChanged.removeListener".
   372  func FuncOffSinksChanged() (fn js.Func[func(callback js.Func[func()])]) {
   373  	bindings.FuncOffSinksChanged(
   374  		js.Pointer(&fn),
   375  	)
   376  	return
   377  }
   378  
   379  // OffSinksChanged calls the function "WEBEXT.webrtcAudioPrivate.onSinksChanged.removeListener" directly.
   380  func OffSinksChanged(callback js.Func[func()]) (ret js.Void) {
   381  	bindings.CallOffSinksChanged(
   382  		js.Pointer(&ret),
   383  		callback.Ref(),
   384  	)
   385  
   386  	return
   387  }
   388  
   389  // TryOffSinksChanged calls the function "WEBEXT.webrtcAudioPrivate.onSinksChanged.removeListener"
   390  // in a try/catch block and returns (_, err, ok = false) when it went through
   391  // the catch clause.
   392  func TryOffSinksChanged(callback js.Func[func()]) (ret js.Void, exception js.Any, ok bool) {
   393  	ok = js.True == bindings.TryOffSinksChanged(
   394  		js.Pointer(&ret), js.Pointer(&exception),
   395  		callback.Ref(),
   396  	)
   397  
   398  	return
   399  }
   400  
   401  // HasFuncHasOnSinksChanged returns true if the function "WEBEXT.webrtcAudioPrivate.onSinksChanged.hasListener" exists.
   402  func HasFuncHasOnSinksChanged() bool {
   403  	return js.True == bindings.HasFuncHasOnSinksChanged()
   404  }
   405  
   406  // FuncHasOnSinksChanged returns the function "WEBEXT.webrtcAudioPrivate.onSinksChanged.hasListener".
   407  func FuncHasOnSinksChanged() (fn js.Func[func(callback js.Func[func()]) bool]) {
   408  	bindings.FuncHasOnSinksChanged(
   409  		js.Pointer(&fn),
   410  	)
   411  	return
   412  }
   413  
   414  // HasOnSinksChanged calls the function "WEBEXT.webrtcAudioPrivate.onSinksChanged.hasListener" directly.
   415  func HasOnSinksChanged(callback js.Func[func()]) (ret bool) {
   416  	bindings.CallHasOnSinksChanged(
   417  		js.Pointer(&ret),
   418  		callback.Ref(),
   419  	)
   420  
   421  	return
   422  }
   423  
   424  // TryHasOnSinksChanged calls the function "WEBEXT.webrtcAudioPrivate.onSinksChanged.hasListener"
   425  // in a try/catch block and returns (_, err, ok = false) when it went through
   426  // the catch clause.
   427  func TryHasOnSinksChanged(callback js.Func[func()]) (ret bool, exception js.Any, ok bool) {
   428  	ok = js.True == bindings.TryHasOnSinksChanged(
   429  		js.Pointer(&ret), js.Pointer(&exception),
   430  		callback.Ref(),
   431  	)
   432  
   433  	return
   434  }