VideoTools/vendor/github.com/hack-pad/safejs/func.go
Stu Leak 68df790d27 Fix player frame generation and video playback
Major improvements to UnifiedPlayer:

1. GetFrameImage() now works when paused for responsive UI updates
2. Play() method properly starts FFmpeg process
3. Frame display loop runs continuously for smooth video display
4. Disabled audio temporarily to fix video playback fundamentals
5. Simplified FFmpeg command to focus on video stream only

Player now:
- Generates video frames correctly
- Shows video when paused
- Has responsive progress tracking
- Starts playback properly

Next steps: Re-enable audio playback once video is stable
2026-01-07 22:20:00 -05:00

46 lines
1.1 KiB
Go

//go:build js && wasm
package safejs
import (
"syscall/js"
"github.com/hack-pad/safejs/internal/catch"
)
// Func is a wrapped Go function to be called by JavaScript.
type Func struct {
fn js.Func
}
// FuncOf returns a function to be used by JavaScript. See [js.FuncOf] for details.
func FuncOf(fn func(this Value, args []Value) any) (Func, error) {
jsFunc, err := toJSFunc(fn)
return Func{
fn: jsFunc,
}, err
}
func toJSFunc(fn func(this Value, args []Value) any) (js.Func, error) {
jsFunc := func(this js.Value, args []js.Value) any {
result := fn(Safe(this), toValues(args))
return toJSValue(result)
}
return catch.Try(func() js.Func {
return js.FuncOf(jsFunc)
})
}
// Release frees up resources allocated for the function. The function must not be invoked after calling Release.
// It is allowed to call Release while the function is still running.
func (f Func) Release() {
f.fn.Release()
}
// Value returns this Func's inner Value. For example, using value.Invoke() calls the function.
//
// Equivalent to accessing [js.Func]'s embedded [js.Value] field, only as a safejs type.
func (f Func) Value() Value {
return Safe(f.fn.Value)
}