Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
Signed-off-by: Yuji Ito <llamerada.jp@gmail.com>
  • Loading branch information
llamerada-jp committed Aug 16, 2022
1 parent 1c14e88 commit 9665e7b
Show file tree
Hide file tree
Showing 34 changed files with 9,749 additions and 9,093 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@
/bin/seed
/build/
/coverage
/dist/*.wasm
/dist/colonio_golang.js
/dist/colonio.js
/dist/colonio.wasm
/dist/index.html
/dist/index.js
/dist/*.wasm
/dist/test.js
/dist/wasm_exec.js
/dist/worker.js
/keys.json
/node_modules
/src/colonio_golang.d.ts
/src/colonio.js
/src/keys.ts
20 changes: 13 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

COLONIO_BRANCH := add-headers-option
COLONIO_FILES := src/colonio.js dist/colonio.wasm
COLONIO_BRANCH := main
COLONIO_FILES := dist/colonio.js dist/colonio_golang.js dist/colonio.wasm
GO_FILES := $(shell find . -name *.go)
OINARI_FILES := dist/wasm_exec.js

Expand All @@ -16,28 +16,34 @@ setup:
$(MAKE) -C build/colonio build
npm install

build: $(COLONIO_FILES) $(GO_FILES) $(OINARI_FILES) bin/seed dist/index.html src/keys.ts
GOOS=js GOARCH=wasm go build -o dist/oinari.wasm ./cmd/agent/*.go
build: $(COLONIO_FILES) $(GO_FILES) $(OINARI_FILES) bin/seed dist/index.html src/keys.ts src/colonio_golang.d.ts
GOOS=js GOARCH=wasm go build -o ./dist/oinari.wasm ./cmd/agent/*.go
GOOS=js GOARCH=wasm go test -o ./dist/test_crosslink.wasm -c ./internal/crosslink/*
npm run build

test: $(COLONIO_FILES) $(GO_FILES) $(OINARI_FILES) bin/seed src/keys.ts
GOOS=js GOARCH=wasm go build -o dist/test_js.wasm ./cmd/test_js/*.go
npm t

bin/seed: $(GO_FILES)
go build -o $@ ./cmd/seed

dist/colonio.js: build/colonio/output/colonio.js
cp $< $@

dist/colonio.wasm: build/colonio/output/colonio.wasm
cp $< $@

dist/colonio_golang.js: build/colonio/src/js/colonio_golang.js
cp $< $@

dist/index.html: src/index.html keys.json
go run ./cmd/tool template -i src/index.html -v keys.json > $@

dist/wasm_exec.js: $(shell go env GOROOT)/misc/wasm/wasm_exec.js
cp $< $@

src/colonio.js: build/colonio/output/colonio.js
cp $< $@
src/colonio_golang.d.ts: dist/colonio_golang.js
./node_modules/typescript/bin/tsc --allowJs --declaration --emitDeclarationOnly --outDir src dist/colonio_golang.js

src/keys.ts: src/keys.temp keys.json
go run ./cmd/tool template -i src/keys.temp -v keys.json > $@
33 changes: 30 additions & 3 deletions cmd/agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ import (
"fmt"
"syscall/js"
"time"

"github.com/llamerada-jp/colonio/go/colonio"
"github.com/llamerada-jp/oinari/internal/crosslink"
"github.com/llamerada-jp/oinari/internal/system"
)

const (
Expand Down Expand Up @@ -102,19 +106,42 @@ func (o *object) tryBind() bool {
return true
}

func initCrosslink() (crosslink.Crosslink, crosslink.MultiPlexer) {
mpxRoot := crosslink.NewMultiPlexer()
cl := crosslink.NewCrosslink("crosslink", mpxRoot)

return cl, mpxRoot
}

func main() {
ticker := time.NewTicker(1 * time.Second)
ctx, _ := context.WithTimeout(context.Background(), 100*time.Second)

defer ticker.Stop()

ctx, _ := context.WithCancel(context.Background())

cl, mpxRoot := initCrosslink()
col, err := colonio.NewColonio(colonio.DefaultLogger)
if err != nil {
panic(err)
}

system.InitSystemHandler(mpxRoot, col)

// send a message that initialization complete
cl.Call("", map[string]string{
crosslink.TAG_PATH: "system/initializationComplete",
}, func(result string, err error) {
if err != nil {
panic(err)
}
})

for {
select {
case <-ctx.Done():
return

case <-ticker.C:
fmt.Println("hello")
}
}
}
5 changes: 4 additions & 1 deletion cmd/seed/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ var cmd = &cobra.Command{
if err != nil {
return err
}
mux.Handle("/seed", seed)
mux.Handle("/seed", &headerWrapper{
handler: seed,
headers: headers,
})
if err := seed.Start(); err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/seed/oinari.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
},
"host": "",
"port": 8080,
"path": "/ws",
"path": "/seed",
"pingInterval": 10000,
"timeout": 30000,
"node": {
Expand Down Expand Up @@ -36,4 +36,4 @@
}
}
}
}
}
36 changes: 0 additions & 36 deletions cmd/test_js/main.go

This file was deleted.

15 changes: 15 additions & 0 deletions dist/test.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>

<head>
<title>test</title>
<script src="https://polyfill.io/v3/polyfill.min.js?features=default" crossorigin="anonymous"></script>
<script src="./wasm_exec.js"></script>
<script src="./test.js"></script>
<link rel="stylesheet" type="text/css" href="./style.css" />
</head>

<body>
</body>

</html>
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.18
require (
github.com/fsnotify/fsnotify v1.4.9
github.com/llamerada-jp/colonio v0.0.0-20220308232451-8b943b0f894b
github.com/onsi/gomega v1.10.1
github.com/spf13/cobra v1.4.0
github.com/spf13/pflag v1.0.5
golang.org/x/crypto v0.0.0-20220315160706-3147a52a75dd
Expand All @@ -18,5 +19,7 @@ require (
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 // indirect
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 // indirect
golang.org/x/text v0.3.6 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
google.golang.org/protobuf v1.27.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)
Loading

0 comments on commit 9665e7b

Please sign in to comment.