Skip to content

Commit

Permalink
Merge pull request #184 from goplus/main
Browse files Browse the repository at this point in the history
fix audiorecord js bug...add runweb.sh
  • Loading branch information
xushiwei authored Dec 20, 2021
2 parents e84cd34 + bd07b99 commit 648ba1f
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 4 deletions.
9 changes: 5 additions & 4 deletions internal/audiorecord/audiorecord_js.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package audiorecord

import (
"strings"
"github.com/goplus/spx/internal/coroutine"
"syscall/js"
)

Expand All @@ -15,8 +15,8 @@ func initScript() {
}
scriptInited = true

window = js.Global().Get("window")
document = js.Global().Get("document")
window := js.Global().Get("window")
document := js.Global().Get("document")

// docuemnt is undefined on node.js
if !document.Truthy() {
Expand Down Expand Up @@ -46,7 +46,8 @@ func Open(gco *coroutine.Coroutines) *Recorder {
initScript()
audioRecorder := js.Global().Get("GopAudioRecorder")
audioRecorder.Call("start", js.FuncOf(func(this js.Value, args []js.Value) interface{} {
volume = args[0].Float()
volume := args[0].Float()
p.volume = volume
return nil
}))
return p
Expand Down
40 changes: 40 additions & 0 deletions test/Bananas/runweb.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@

mkdir res/
GOEXPERIMENT=noregabi GOOS=js GOARCH=wasm go build --tags canvas -o test.wasm
cp -f "$(go env GOROOT)/misc/wasm/wasm_exec.js" ./
cp -f "$(go env GOROOT)/misc/wasm/wasm_exec.html" ./
cp -f -p ../res/* ./res/


echo '// test.go
package main
import (
"flag"
"log"
"net/http"
"strings"
)
var (
listen = flag.String("listen", ":8080", "listen address")
dir = flag.String("dir", ".", "directory to serve")
)
func main() {
flag.Parse()
log.Printf("listening on %q...", *listen)
log.Fatal(http.ListenAndServe(*listen, http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
if strings.HasSuffix(req.URL.Path, ".wasm") {
resp.Header().Set("content-type", "application/wasm")
}
http.FileServer(http.Dir(*dir)).ServeHTTP(resp, req)
})))
}'> server.go
go run server.go
rm -rf wasm_exec.js
rm -rf wasm_exec.html
rm -rf server.go
rm -rf res/
rm -rf *.wasm

0 comments on commit 648ba1f

Please sign in to comment.