faiface / beep

A little package that brings sound to any Go application. Suitable for playback and audio-processing.
MIT License
2.04k stars 150 forks source link

Can't compile to wasm #113

Open cgimenez opened 3 years ago

cgimenez commented 3 years ago

Hi ! I've been toying a little with Beep under Mac OS with success. Great lib !

Then I tried to compile my little hello world for wasm with

GOOS=js GOARCH=wasm go build -o tstbeep

and I got these errors

/Users/chris/go/pkg/mod/github.com/gopherjs/gopherwasm@v1.0.0/js/js_wasm.go:38:17: undefined: js.Callback
/Users/chris/go/pkg/mod/github.com/gopherjs/gopherwasm@v1.0.0/js/js_wasm.go:40:26: undefined: js.EventCallbackFlag
/Users/chris/go/pkg/mod/github.com/gopherjs/gopherwasm@v1.0.0/js/js_wasm.go:43:29: undefined: js.PreventDefault
/Users/chris/go/pkg/mod/github.com/gopherjs/gopherwasm@v1.0.0/js/js_wasm.go:44:29: undefined: js.StopPropagation
/Users/chris/go/pkg/mod/github.com/gopherjs/gopherwasm@v1.0.0/js/js_wasm.go:45:29: undefined: js.StopImmediatePropagation
/Users/chris/go/pkg/mod/github.com/gopherjs/gopherwasm@v1.0.0/js/js_wasm.go:49:9: undefined: js.NewCallback
/Users/chris/go/pkg/mod/github.com/gopherjs/gopherwasm@v1.0.0/js/js_wasm.go:53:9: undefined: js.NewEventCallback
/Users/chris/go/pkg/mod/github.com/gopherjs/gopherwasm@v1.0.0/js/js_wasm.go:64:19: undefined: js.TypedArray
/Users/chris/go/pkg/mod/github.com/gopherjs/gopherwasm@v1.0.0/js/js_wasm.go:67:9: undefined: js.TypedArrayOf

Most, if not all, of these functions have been deprecated for a while.

At first I thought it could be a problem related with Oto, so I compiled https://github.com/hajimehoshi/oto/blob/master/example/main.go to wasm and go it working (at least for Firefox, Chrome is more restrictive but that's not the point)

My tstbeep go.mod is simple as

module tstbeep

go 1.16

require (
    github.com/faiface/beep v1.0.2 // indirect
    github.com/hajimehoshi/oto v0.3.1 // indirect
)

I really don't see where gopherjs comes into the dance. Oto doesn't seems to use it, neither Beep...

So, because I had installed (and never used) gopherjs : rm -rf gopherjs ~/go/bin directory and rm -rf gopherjs ~/go/pkg/mod/github.com/gopherjs

And issuing a GOOS=js GOARCH=wasm go build -o tstbeep

resurrected ~/go/pkg/mod/github.com/gopherjs

Any clue ?

cgimenez commented 3 years ago

Ok, got it. I didn't noticed that my go.mod was targeting an old version of Oto.

Fixing it to require github.com/hajimehoshi/oto v0.6.1

What I don't get is that I followed the procedure described here : https://github.com/faiface/beep/wiki/Hello,-Beep!

when go run complained, I go got github.com/hajimehoshi/oto and ended with an old version of Oto.

Go modules dependencies are still obscure to me ;-)

makew0rld commented 3 years ago

This should be fixed now.