Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 648ba1f

Browse files
authoredDec 20, 2021
Merge pull request #184 from goplus/main
fix audiorecord js bug...add runweb.sh
2 parents e84cd34 + bd07b99 commit 648ba1f

File tree

2 files changed

+45
-4
lines changed

2 files changed

+45
-4
lines changed
 

‎internal/audiorecord/audiorecord_js.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package audiorecord
22

33
import (
4-
"strings"
4+
"github.com/goplus/spx/internal/coroutine"
55
"syscall/js"
66
)
77

@@ -15,8 +15,8 @@ func initScript() {
1515
}
1616
scriptInited = true
1717

18-
window = js.Global().Get("window")
19-
document = js.Global().Get("document")
18+
window := js.Global().Get("window")
19+
document := js.Global().Get("document")
2020

2121
// docuemnt is undefined on node.js
2222
if !document.Truthy() {
@@ -46,7 +46,8 @@ func Open(gco *coroutine.Coroutines) *Recorder {
4646
initScript()
4747
audioRecorder := js.Global().Get("GopAudioRecorder")
4848
audioRecorder.Call("start", js.FuncOf(func(this js.Value, args []js.Value) interface{} {
49-
volume = args[0].Float()
49+
volume := args[0].Float()
50+
p.volume = volume
5051
return nil
5152
}))
5253
return p

‎test/Bananas/runweb.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
2+
mkdir res/
3+
GOEXPERIMENT=noregabi GOOS=js GOARCH=wasm go build --tags canvas -o test.wasm
4+
cp -f "$(go env GOROOT)/misc/wasm/wasm_exec.js" ./
5+
cp -f "$(go env GOROOT)/misc/wasm/wasm_exec.html" ./
6+
cp -f -p ../res/* ./res/
7+
8+
9+
echo '// test.go
10+
package main
11+
12+
import (
13+
"flag"
14+
"log"
15+
"net/http"
16+
"strings"
17+
)
18+
19+
var (
20+
listen = flag.String("listen", ":8080", "listen address")
21+
dir = flag.String("dir", ".", "directory to serve")
22+
)
23+
24+
func main() {
25+
flag.Parse()
26+
log.Printf("listening on %q...", *listen)
27+
log.Fatal(http.ListenAndServe(*listen, http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
28+
if strings.HasSuffix(req.URL.Path, ".wasm") {
29+
resp.Header().Set("content-type", "application/wasm")
30+
}
31+
32+
http.FileServer(http.Dir(*dir)).ServeHTTP(resp, req)
33+
})))
34+
}'> server.go
35+
go run server.go
36+
rm -rf wasm_exec.js
37+
rm -rf wasm_exec.html
38+
rm -rf server.go
39+
rm -rf res/
40+
rm -rf *.wasm

0 commit comments

Comments
 (0)
Please sign in to comment.