diff --git a/backend/ats/package.json b/backend/ats/package.json
index 165193a9..8de38735 100644
--- a/backend/ats/package.json
+++ b/backend/ats/package.json
@@ -14,7 +14,7 @@
"ts-jest": "^29.0.3",
"ts-node": "^10.9.1",
"ts-protoc-gen": "0.15.0",
- "typescript": "4.9.3"
+ "typescript": "4.8.4"
},
"dependencies": {
"@grpc/grpc-js": "^1.7.2",
diff --git a/backend/ats/spec/block_pb.d.ts b/backend/ats/spec/block_pb.d.ts
index 956a5061..4c5994af 100644
--- a/backend/ats/spec/block_pb.d.ts
+++ b/backend/ats/spec/block_pb.d.ts
@@ -129,7 +129,7 @@ export interface BlockIdMap {
HASHIMOTO_B1: 31;
HASHIMOTO_B2: 32;
HACHIOJI_B1: 41;
- HASHIOJI_B2: 42;
+ HACHIOJI_B2: 42;
}
export const BlockId: BlockIdMap;
diff --git a/backend/ats/spec/block_pb.js b/backend/ats/spec/block_pb.js
index a1f29699..86d12774 100644
--- a/backend/ats/spec/block_pb.js
+++ b/backend/ats/spec/block_pb.js
@@ -821,7 +821,7 @@ proto.BlockId = {
HASHIMOTO_B1: 31,
HASHIMOTO_B2: 32,
HACHIOJI_B1: 41,
- HASHIOJI_B2: 42
+ HACHIOJI_B2: 42
};
goog.object.extend(exports, proto);
diff --git a/backend/ats/yarn.lock b/backend/ats/yarn.lock
index 9992ad9d..eb447448 100644
--- a/backend/ats/yarn.lock
+++ b/backend/ats/yarn.lock
@@ -2509,10 +2509,10 @@ type-fest@^0.21.3:
resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.21.3.tgz#d260a24b0198436e133fa26a524a6d65fa3b2e37"
integrity sha512-t0rzBq87m3fVcduHDUFhKmyyX+9eo6WQjZvf51Ea/M0Q7+T374Jp1aUiyUl0GKxp8M/OETVHSDvmkyPgvX+X2w==
-typescript@4.9.3:
- version "4.9.3"
- resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.9.3.tgz#3aea307c1746b8c384435d8ac36b8a2e580d85db"
- integrity sha512-CIfGzTelbKNEnLpLdGFgdyKhG23CKdKgQPOBc+OUNrkJ2vr+KSzsSV5kq5iWhEQbok+quxgGzrAtGWCyU7tHnA==
+typescript@4.8.4:
+ version "4.8.4"
+ resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.8.4.tgz#c464abca159669597be5f96b8943500b238e60e6"
+ integrity sha512-QCh+85mCy+h0IGff8r5XWzOVSbBO+KfeYrMQh7NJ58QujwcE22u+NUSmUxqF+un70P9GXKxa2HCNiTTMJknyjQ==
update-browserslist-db@^1.0.9:
version "1.0.10"
diff --git a/backend/auto_operation/requirements.txt b/backend/auto_operation/requirements.txt
index 078158d8..51aae66a 100644
--- a/backend/auto_operation/requirements.txt
+++ b/backend/auto_operation/requirements.txt
@@ -1,7 +1,7 @@
bidict==0.22.0
click==8.1.3
dnspython==2.2.1
-eventlet==0.33.1
+eventlet==0.33.2
Flask==2.2.2
Flask-Cors==3.0.10
Flask-SocketIO==5.3.1
@@ -22,5 +22,5 @@ types-protobuf==3.20.4.5
types-Flask-Cors
Werkzeug==2.2.2
zope.event==4.5.0
-zope.interface==5.5.1
+zope.interface==5.5.2
grpcio-tools==1.50.0
diff --git a/backend/auto_operation/spec/block_pb2.py b/backend/auto_operation/spec/block_pb2.py
index f061ec7b..b7b651ef 100644
--- a/backend/auto_operation/spec/block_pb2.py
+++ b/backend/auto_operation/spec/block_pb2.py
@@ -13,7 +13,7 @@
-DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x0b\x62lock.proto\"J\n\rBlockAndState\x12\x19\n\x07\x62lockId\x18\x03 \x01(\x0e\x32\x08.BlockId\x12\x1e\n\x05state\x18\x02 \x01(\x0e\x32\x0f.BlockStateEnum\"8\n\x17UpdateBlockStateRequest\x12\x1d\n\x05state\x18\x01 \x01(\x0b\x32\x0e.BlockAndState\"\x1a\n\x18UpdateBlockStateResponse\"8\n\x17NotifyBlockStateRequest\x12\x1d\n\x05state\x18\x01 \x01(\x0b\x32\x0e.BlockAndState\"\x1a\n\x18NotifyBlockStateResponse*S\n\x0e\x42lockStateEnum\x12\x16\n\x12\x42LOCKSTATE_UNKNOWN\x10\x00\x12\x13\n\x0f\x42LOCKSTATE_OPEN\x10\x01\x12\x14\n\x10\x42LOCKSTATE_CLOSE\x10\x02*\xbc\x02\n\x07\x42lockId\x12\x0b\n\x07unknown\x10\x00\x12\x0f\n\x0bshinjuku_b1\x10\x01\x12\x0f\n\x0bshinjuku_b2\x10\x02\x12\x12\n\x0esakurajosui_b1\x10\x0b\x12\x12\n\x0esakurajosui_b2\x10\x0c\x12\x12\n\x0esakurajosui_b3\x10\r\x12\x12\n\x0esakurajosui_b4\x10\x0e\x12\x12\n\x0esakurajosui_b5\x10\x0f\x12\x12\n\x0esakurajosui_b6\x10\x10\x12\x0c\n\x08\x63hofu_b1\x10\x15\x12\x0c\n\x08\x63hofu_b2\x10\x16\x12\x0c\n\x08\x63hofu_b3\x10\x17\x12\x0c\n\x08\x63hofu_b4\x10\x18\x12\x0c\n\x08\x63hofu_b5\x10\x19\x12\x10\n\x0chashimoto_b1\x10\x1f\x12\x10\n\x0chashimoto_b2\x10 \x12\x0f\n\x0bhachioji_b1\x10)\x12\x0f\n\x0bhashioji_b2\x10*2^\n\x11\x42lockStateManager\x12I\n\x10UpdateBlockState\x12\x18.UpdateBlockStateRequest\x1a\x19.UpdateBlockStateResponse\"\x00\x32\x63\n\x16\x42lockStateNotification\x12I\n\x10NotifyBlockState\x12\x18.NotifyBlockStateRequest\x1a\x19.NotifyBlockStateResponse\"\x00\x42\x08Z\x06./specb\x06proto3')
+DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x0b\x62lock.proto\"J\n\rBlockAndState\x12\x19\n\x07\x62lockId\x18\x03 \x01(\x0e\x32\x08.BlockId\x12\x1e\n\x05state\x18\x02 \x01(\x0e\x32\x0f.BlockStateEnum\"8\n\x17UpdateBlockStateRequest\x12\x1d\n\x05state\x18\x01 \x01(\x0b\x32\x0e.BlockAndState\"\x1a\n\x18UpdateBlockStateResponse\"8\n\x17NotifyBlockStateRequest\x12\x1d\n\x05state\x18\x01 \x01(\x0b\x32\x0e.BlockAndState\"\x1a\n\x18NotifyBlockStateResponse*S\n\x0e\x42lockStateEnum\x12\x16\n\x12\x42LOCKSTATE_UNKNOWN\x10\x00\x12\x13\n\x0f\x42LOCKSTATE_OPEN\x10\x01\x12\x14\n\x10\x42LOCKSTATE_CLOSE\x10\x02*\xbc\x02\n\x07\x42lockId\x12\x0b\n\x07unknown\x10\x00\x12\x0f\n\x0bshinjuku_b1\x10\x01\x12\x0f\n\x0bshinjuku_b2\x10\x02\x12\x12\n\x0esakurajosui_b1\x10\x0b\x12\x12\n\x0esakurajosui_b2\x10\x0c\x12\x12\n\x0esakurajosui_b3\x10\r\x12\x12\n\x0esakurajosui_b4\x10\x0e\x12\x12\n\x0esakurajosui_b5\x10\x0f\x12\x12\n\x0esakurajosui_b6\x10\x10\x12\x0c\n\x08\x63hofu_b1\x10\x15\x12\x0c\n\x08\x63hofu_b2\x10\x16\x12\x0c\n\x08\x63hofu_b3\x10\x17\x12\x0c\n\x08\x63hofu_b4\x10\x18\x12\x0c\n\x08\x63hofu_b5\x10\x19\x12\x10\n\x0chashimoto_b1\x10\x1f\x12\x10\n\x0chashimoto_b2\x10 \x12\x0f\n\x0bhachioji_b1\x10)\x12\x0f\n\x0bhachioji_b2\x10*2^\n\x11\x42lockStateManager\x12I\n\x10UpdateBlockState\x12\x18.UpdateBlockStateRequest\x1a\x19.UpdateBlockStateResponse\"\x00\x32\x63\n\x16\x42lockStateNotification\x12I\n\x10NotifyBlockState\x12\x18.NotifyBlockStateRequest\x1a\x19.NotifyBlockStateResponse\"\x00\x42\x08Z\x06./specb\x06proto3')
_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, globals())
_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'block_pb2', globals())
diff --git a/backend/auto_operation/spec/block_pb2.pyi b/backend/auto_operation/spec/block_pb2.pyi
index 65f0a999..a6117e3a 100644
--- a/backend/auto_operation/spec/block_pb2.pyi
+++ b/backend/auto_operation/spec/block_pb2.pyi
@@ -13,9 +13,9 @@ chofu_b3: BlockId
chofu_b4: BlockId
chofu_b5: BlockId
hachioji_b1: BlockId
+hachioji_b2: BlockId
hashimoto_b1: BlockId
hashimoto_b2: BlockId
-hashioji_b2: BlockId
sakurajosui_b1: BlockId
sakurajosui_b2: BlockId
sakurajosui_b3: BlockId
diff --git a/backend/external/internal/embed/stationInit.yml b/backend/external/internal/embed/stationInit.yml
index 50b47bd0..d8342727 100644
--- a/backend/external/internal/embed/stationInit.yml
+++ b/backend/external/internal/embed/stationInit.yml
@@ -1,86 +1,86 @@
stations:
- name: motoyawata_s1
- state: ON
+ state: POINTSTATE_ON
- name: motoyawata_s2
- state: ON
+ state: POINTSTATE_ON
- name: iwamotocho_s1
- state: ON
+ state: POINTSTATE_ON
- name: iwamotocho_s2
- state: ON
+ state: POINTSTATE_ON
- name: iwamotocho_s4
- state: ON
+ state: POINTSTATE_ON
- name: iwamotocho_b1
- state: ON
+ state: POINTSTATE_ON
- name: iwamotocho_b4
- state: ON
+ state: POINTSTATE_ON
- name: kudanshita_s5
- state: ON
+ state: POINTSTATE_ON
- name: kudanshita_s6
- state: ON
+ state: POINTSTATE_ON
- name: sasazuka_b1
- state: ON
+ state: POINTSTATE_ON
- name: sasazuka_b2
- state: ON
+ state: POINTSTATE_ON
- name: sasazuka_s1
- state: ON
+ state: POINTSTATE_ON
- name: sasazuka_s2
- state: ON
+ state: POINTSTATE_ON
- name: sasazuka_s3
- state: ON
+ state: POINTSTATE_ON
- name: sasazuka_s4
- state: ON
+ state: POINTSTATE_ON
- name: sasazuka_s5
- state: ON
+ state: POINTSTATE_ON
- name: meidaimae_s1
- state: ON
+ state: POINTSTATE_ON
- name: meidaimae_s2
- state: ON
+ state: POINTSTATE_ON
- name: chofu_s1
- state: ON
+ state: POINTSTATE_ON
- name: chofu_s2
- state: OFF
+ state: POINTSTATE_OFF
- name: chofu_s3
- state: ON
+ state: POINTSTATE_ON
- name: chofu_s4
- state: ON
+ state: POINTSTATE_ON
- name: chofu_s5
- state: ON
+ state: POINTSTATE_ON
- name: chofu_s6
- state: ON
+ state: POINTSTATE_ON
- name: chofu_b1
- state: ON
+ state: POINTSTATE_ON
- name: chofu_b2
- state: OFF
+ state: POINTSTATE_OFF
- name: chofu_b3
- state: ON
+ state: POINTSTATE_ON
- name: chofu_b4
- state: ON
+ state: POINTSTATE_ON
- name: chofu_b5
- state: ON
+ state: POINTSTATE_ON
- name: kitano_b1
- state: ON
+ state: POINTSTATE_ON
- name: kitano_b2
- state: ON
+ state: POINTSTATE_ON
- name: kitano_s1
- state: ON
+ state: POINTSTATE_ON
- name: kitano_s2
- state: ON
+ state: POINTSTATE_ON
- name: kitano_s3
- state: ON
+ state: POINTSTATE_ON
- name: kitano_s4
- state: ON
+ state: POINTSTATE_ON
- name: kitano_s5
- state: ON
+ state: POINTSTATE_ON
- name: kitano_s6
- state: ON
+ state: POINTSTATE_ON
- name: takao_s1
- state: ON
+ state: POINTSTATE_ON
- name: takao_s2
- state: ON
+ state: POINTSTATE_ON
diff --git a/backend/external/internal/grpc.go b/backend/external/internal/grpc.go
index 9c11f740..3e329398 100644
--- a/backend/external/internal/grpc.go
+++ b/backend/external/internal/grpc.go
@@ -116,3 +116,42 @@ func GRPCListenAndServe(ctx context.Context, logger *zap.Logger, port uint, hand
logger.Panic("failed to server", zap.Error(err))
}
}
+
+// GrpcStateHandler is a handler for gRPC.
+type GrpcStateHandlerForInternal struct {
+ logger *zap.Logger
+ env *envStore.Env
+ stateInput <-chan synccontroller.KV[spec.StationId, spec.PointStateEnum]
+}
+
+// / handleInput transmits changes received in channel to ATS.
+func (g GrpcStateHandlerForInternal) handleInput(ctx context.Context) {
+ con, err := grpc.DialContext(ctx, g.env.InternalServer.Addr.String(),
+ grpc.WithTransportCredentials(insecure.NewCredentials()),
+ )
+ if err != nil {
+ g.logger.Error("failed to connect ATS", zap.Error(err))
+ }
+ defer con.Close()
+ for d := range g.stateInput {
+ client := spec.NewPointStateNotificationClient(con)
+ req := &spec.NotifyPointStateRequest{
+ State: &spec.PointAndState{
+ Station: &spec.Station{StationId: d.Key},
+ State: d.Value,
+ },
+ }
+ _, err := client.NotifyPointState(ctx, req)
+ if err != nil {
+ g.logger.Error("failed to send data to ATS", zap.Any("payload", req), zap.Error(err))
+ }
+ }
+}
+
+func NewGrpcHandlerForInternal(logger *zap.Logger, env *envStore.Env, stateInput <-chan synccontroller.KV[spec.StationId, spec.PointStateEnum]) *GrpcStateHandlerForInternal {
+ return &GrpcStateHandlerForInternal{logger, env, stateInput}
+}
+
+func (g GrpcStateHandlerForInternal) Run(ctx context.Context) {
+ g.handleInput(ctx)
+}
diff --git a/backend/external/internal/root.go b/backend/external/internal/root.go
index 88b1755f..90d89d68 100644
--- a/backend/external/internal/root.go
+++ b/backend/external/internal/root.go
@@ -2,9 +2,16 @@ package internal
import (
"context"
+ "fmt"
+ "net/http"
+ "time"
+
+ "github.com/gorilla/mux"
+ "github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/ueckoken/plarail2022/backend/external/pkg/envStore"
"github.com/ueckoken/plarail2022/backend/external/pkg/httphandler"
"github.com/ueckoken/plarail2022/backend/external/pkg/synccontroller"
+ "github.com/ueckoken/plarail2022/backend/external/pkg/websockethandler"
"github.com/ueckoken/plarail2022/backend/external/spec"
"go.uber.org/zap"
@@ -14,17 +21,18 @@ import (
func Run(logger *zap.Logger) {
ctx := context.Background()
synccontrollerInput := make(chan synccontroller.KV[spec.StationId, spec.PointStateEnum])
- synccontrollerOutput := make(chan synccontroller.KV[spec.StationId, spec.PointStateEnum])
+ synccontrollerOutput := make(chan synccontroller.KV[spec.StationId, spec.PointStateEnum], 32)
grpcHandlerInput := make(chan synccontroller.KV[spec.StationId, spec.PointStateEnum])
- main2grpcHandler := make(chan synccontroller.KV[spec.StationId, spec.PointStateEnum])
- httpInputKV := make(chan synccontroller.KV[spec.StationId, spec.PointStateEnum])
+ main2autooperation := make(chan synccontroller.KV[spec.StationId, spec.PointStateEnum])
+ main2internal := make(chan synccontroller.KV[spec.StationId, spec.PointStateEnum], 32)
+ httpInputKV := make(chan synccontroller.KV[spec.StationId, spec.PointStateEnum], 32)
httpInput := make(chan *spec.PointAndState)
httpOutput := make(chan *spec.PointAndState)
go func() {
for c := range synccontrollerOutput {
select {
- case main2grpcHandler <- c:
+ case main2autooperation <- c:
default:
logger.Info("buffer full", zap.String("buffer", "main2grpcHandler"))
}
@@ -33,36 +41,119 @@ func Run(logger *zap.Logger) {
default:
logger.Info("buffer full", zap.String("buffer", "httpInputKV"))
}
+ select {
+ case main2internal <- c:
+ default:
+ logger.Info("buffer full", zap.String("buffer", "internal"))
+ }
}
}()
+
go func() {
for c := range httpInputKV {
- httpInput <- &spec.PointAndState{Station: &spec.Station{StationId: c.Key}, State: c.Value}
+ select {
+ case httpInput <- &spec.PointAndState{Station: &spec.Station{StationId: c.Key}, State: c.Value}:
+ default:
+ logger.Info("buffer full", zap.String("buffer", "httpInput"))
+ }
}
}()
go func() {
for c := range httpOutput {
- synccontrollerInput <- synccontroller.KV[spec.StationId, spec.PointStateEnum]{Key: c.GetStation().GetStationId(), Value: c.GetState()}
+ select {
+ case synccontrollerInput <- synccontroller.KV[spec.StationId, spec.PointStateEnum]{Key: c.GetStation().GetStationId(), Value: c.GetState()}:
+ default:
+ logger.Info("buffer full", zap.String("buffer", "synccontrollerInput-httpoutput"))
+ }
+ }
+ }()
+
+ go func() {
+ for c := range grpcHandlerInput {
+ select {
+ case synccontrollerInput <- c:
+ default:
+ logger.Info("buffer full", zap.String("buffer", "synccontrollerInput-grpchandler"))
+ }
}
}()
envVal := envStore.GetEnv()
httpServer := httphandler.NewHTTPServer(
- logger.Named("sync-controller"),
+ logger.Named("http-state"),
httpOutput,
httpInput,
envVal,
+ "httppointserver",
)
+
StartStationSync(logger.Named("station-sync"), synccontrollerInput, synccontrollerOutput)
- grpcHandler := NewGrpcHandler(logger.Named("grpc-handler"), envVal, main2grpcHandler, grpcHandlerInput)
+ grpcHandler := NewGrpcHandler(logger.Named("grpc-handler"), envVal, main2autooperation, grpcHandlerInput)
+ internalHandler := NewGrpcHandlerForInternal(logger.Named("grpc-internal"), envVal, main2internal)
+ go internalHandler.Run(ctx)
+
+ httpBlockInput := make(chan *spec.BlockAndState)
+ httpBlockOutput := make(chan *spec.BlockAndState)
+ blocksyncInput := make(chan synccontroller.KV[spec.BlockId, spec.BlockStateEnum])
+ blocksyncOutput := make(chan synccontroller.KV[spec.BlockId, spec.BlockStateEnum])
+ grpcBlockHandlerInput := make(chan synccontroller.KV[spec.BlockId, spec.BlockStateEnum])
+ grpcBlockHandlerOutput := make(chan synccontroller.KV[spec.BlockId, spec.BlockStateEnum])
+
+ httpBlockServer := httphandler.NewHTTPServer(
+ logger.Named("http-block"),
+ httpBlockOutput,
+ httpBlockInput,
+ envVal,
+ "httpblockserver",
+ )
- client2blocksync := make(chan synccontroller.KV[spec.BlockId, spec.BlockStateEnum])
- blocksync2client := make(chan synccontroller.KV[spec.BlockId, spec.BlockStateEnum])
- startBlockSync(logger.Named("blocksync"), client2blocksync, blocksync2client)
- grpcBlockHandl := NewGrpcBlockHandler(logger.Named("grpc-block-handler"), envVal, client2blocksync, blocksync2client)
+ go func() {
+ for c := range grpcBlockHandlerOutput {
+ select {
+ case blocksyncInput <- synccontroller.KV[spec.BlockId, spec.BlockStateEnum]{Key: c.Key, Value: c.Value}:
+ default:
+ logger.Info("buffer full", zap.String("buffer", "blocksyncInput-grpchandler"))
+ }
+ }
+ }()
+
+ go func() {
+ for c := range blocksyncOutput {
+ select {
+ case grpcBlockHandlerInput <- c:
+ default:
+ logger.Info("buffer full", zap.String("buffer", "grpcblockhandlerinput-blocksync"))
+ }
+ select {
+ case httpBlockInput <- &spec.BlockAndState{BlockId: c.Key, State: c.Value}:
+ default:
+ logger.Info("buffer full", zap.String("buffer", "httpblockinput-blocksync"))
+ }
+ }
+ }()
+
+ startBlockSync(logger.Named("blocksync"), blocksyncInput, blocksyncOutput)
+ grpcBlockHandl := NewGrpcBlockHandler(logger.Named("grpc-block-handler"), envVal, grpcBlockHandlerOutput, grpcBlockHandlerInput)
go GRPCListenAndServe(ctx, logger, uint(envVal.ClientSideServer.GrpcPort), grpcHandler, grpcBlockHandl)
- httpServer.StartServer()
+ r := mux.NewRouter()
+ r.HandleFunc("/", websockethandler.HandleStatic)
+ r.Handle("/metrics", promhttp.Handler())
+ httpBlockServer.RegisterServer(r, "/blockws")
+ httpServer.RegisterServer(r, "/pointws")
+
+ srv := &http.Server{
+ Handler: r,
+ Addr: fmt.Sprintf("0.0.0.0:%d", int(envVal.ClientSideServer.Port)),
+ ReadHeaderTimeout: 5 * time.Second,
+ ReadTimeout: 5 * time.Second,
+ WriteTimeout: 5 * time.Second,
+ }
+
+ logger.Info("start listening")
+ if err := srv.ListenAndServe(); err != nil {
+ logger.Panic("failed to serve", zap.Error(err))
+ }
}
diff --git a/backend/external/internal/stationsync.go b/backend/external/internal/stationsync.go
index 44639b5f..65a6f53b 100644
--- a/backend/external/internal/stationsync.go
+++ b/backend/external/internal/stationsync.go
@@ -29,7 +29,11 @@ func initStationSync(logger *zap.Logger, r *InitRule, initializer chan<- synccon
logger.Error("unknown state", zap.String("state", sta.State))
continue
}
- initializer <- synccontroller.KV[spec.StationId, spec.PointStateEnum]{Key: spec.StationId(id), Value: spec.PointStateEnum(state)}
+ select {
+ case initializer <- synccontroller.KV[spec.StationId, spec.PointStateEnum]{Key: spec.StationId(id), Value: spec.PointStateEnum(state)}:
+ default:
+ logger.Error("failed to initialize sync controller, buffer full")
+ }
time.Sleep(500 * time.Millisecond)
}
}
diff --git a/backend/external/pkg/httphandler/httphandler.go b/backend/external/pkg/httphandler/httphandler.go
index 66f1571d..cd29b253 100644
--- a/backend/external/pkg/httphandler/httphandler.go
+++ b/backend/external/pkg/httphandler/httphandler.go
@@ -1,16 +1,12 @@
package httphandler
import (
- "fmt"
"github.com/ueckoken/plarail2022/backend/external/pkg/envStore"
"github.com/ueckoken/plarail2022/backend/external/pkg/websockethandler"
- "net/http"
"sync"
- "time"
"github.com/gorilla/mux"
"github.com/prometheus/client_golang/prometheus"
- "github.com/prometheus/client_golang/prometheus/promhttp"
"go.uber.org/zap"
"google.golang.org/protobuf/proto"
)
@@ -28,8 +24,7 @@ type HTTPServer[T proto.Message] struct {
}
// NewHTTPServer creates HTTP server.
-func NewHTTPServer[T proto.Message](logger *zap.Logger, httpOutput chan<- T, httpInput <-chan T, env *envStore.Env) *HTTPServer[T] {
- const namespace = "plarailexternal"
+func NewHTTPServer[T proto.Message](logger *zap.Logger, httpOutput chan<- T, httpInput <-chan T, env *envStore.Env, namespace string) *HTTPServer[T] {
clientConn := prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: namespace,
@@ -76,31 +71,16 @@ type ClientsCollection[T proto.Message] struct {
}
// StartServer starts HTTP server and websocket server.
-func (h *HTTPServer[T]) StartServer() {
+func (h *HTTPServer[T]) RegisterServer(r *mux.Router, endpoint string) {
clientChannelSend := make(chan websockethandler.ClientChannel[T])
handlerInput := make(chan T)
go h.registerClient(clientChannelSend)
go h.broadcastChanges()
go h.unregisterClients()
- r := mux.NewRouter()
prometheus.MustRegister(h.numberOfClientConnection)
prometheus.MustRegister(h.totalClientConnection)
prometheus.MustRegister(h.totalCLientCommands)
- r.HandleFunc("/", websockethandler.HandleStatic)
- r.Handle("/ws", websockethandler.NewClientHandler(h.logger.Named("ws-handler"), handlerInput, clientChannelSend))
- r.Handle("/metrics", promhttp.Handler())
- srv := &http.Server{
- Handler: r,
- Addr: fmt.Sprintf("0.0.0.0:%d", h.environment.ClientSideServer.Port),
- ReadHeaderTimeout: 5 * time.Second,
- ReadTimeout: 5 * time.Second,
- WriteTimeout: 5 * time.Second,
- }
-
- h.logger.Info("start listening")
- if err := srv.ListenAndServe(); err != nil {
- h.logger.Panic("failed to serve", zap.Error(err))
- }
+ r.Handle(endpoint, websockethandler.NewClientHandler(h.logger.Named("ws-handler"), handlerInput, clientChannelSend))
}
// broadcastChanges receives the change from main channel and broadcast it to clients.
diff --git a/backend/external/pkg/synccontroller/syncController.go b/backend/external/pkg/synccontroller/syncController.go
index 3821e291..17367b48 100644
--- a/backend/external/pkg/synccontroller/syncController.go
+++ b/backend/external/pkg/synccontroller/syncController.go
@@ -96,7 +96,6 @@ func (s *SyncController[T, U]) periodicallySync() {
}
}
s.kvs.mtx.Unlock()
- s.logger.Info("unlocked")
}()
}
}
diff --git a/backend/external/pkg/websockethandler/embed/index.html b/backend/external/pkg/websockethandler/embed/index.html
index d9b2b711..61decbc5 100644
--- a/backend/external/pkg/websockethandler/embed/index.html
+++ b/backend/external/pkg/websockethandler/embed/index.html
@@ -11,7 +11,7 @@
p1.innerHTML = data;
};
window.onload = function () {
- sock = new WebSocket("ws://" + location.host + "/ws");
+ sock = new WebSocket("wss://" + location.host + "/ws");
sock.onmessage = function (event) {
var data = JSON.parse(event.data);
sock.send(`{"station": {"stationId":26}, "state": 1}`);
diff --git a/backend/external/pkg/websockethandler/websockethandler.go b/backend/external/pkg/websockethandler/websockethandler.go
index 9733f1a7..9c33cad1 100644
--- a/backend/external/pkg/websockethandler/websockethandler.go
+++ b/backend/external/pkg/websockethandler/websockethandler.go
@@ -60,7 +60,7 @@ func (m ClientHandler[T]) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return c.SetReadDeadline(time.Now().Add(20 * time.Second))
})
c.SetCloseHandler(func(code int, text string) error {
- m.logger.Info("connection closed")
+ m.logger.Info("connection closed", zap.Int("code", code), zap.String("text", text))
cancel()
return nil
})
diff --git a/backend/external/spec/block.pb.go b/backend/external/spec/block.pb.go
index b8ce9f16..d3ca52cb 100644
--- a/backend/external/spec/block.pb.go
+++ b/backend/external/spec/block.pb.go
@@ -89,7 +89,7 @@ const (
BlockId_hashimoto_b1 BlockId = 31
BlockId_hashimoto_b2 BlockId = 32
BlockId_hachioji_b1 BlockId = 41
- BlockId_hashioji_b2 BlockId = 42
+ BlockId_hachioji_b2 BlockId = 42
)
// Enum value maps for BlockId.
@@ -112,7 +112,7 @@ var (
31: "hashimoto_b1",
32: "hashimoto_b2",
41: "hachioji_b1",
- 42: "hashioji_b2",
+ 42: "hachioji_b2",
}
BlockId_value = map[string]int32{
"unknown": 0,
@@ -132,7 +132,7 @@ var (
"hashimoto_b1": 31,
"hashimoto_b2": 32,
"hachioji_b1": 41,
- "hashioji_b2": 42,
+ "hachioji_b2": 42,
}
)
@@ -434,7 +434,7 @@ var file_proto_block_proto_rawDesc = []byte{
0x6d, 0x6f, 0x74, 0x6f, 0x5f, 0x62, 0x31, 0x10, 0x1f, 0x12, 0x10, 0x0a, 0x0c, 0x68, 0x61, 0x73,
0x68, 0x69, 0x6d, 0x6f, 0x74, 0x6f, 0x5f, 0x62, 0x32, 0x10, 0x20, 0x12, 0x0f, 0x0a, 0x0b, 0x68,
0x61, 0x63, 0x68, 0x69, 0x6f, 0x6a, 0x69, 0x5f, 0x62, 0x31, 0x10, 0x29, 0x12, 0x0f, 0x0a, 0x0b,
- 0x68, 0x61, 0x73, 0x68, 0x69, 0x6f, 0x6a, 0x69, 0x5f, 0x62, 0x32, 0x10, 0x2a, 0x32, 0x5e, 0x0a,
+ 0x68, 0x61, 0x63, 0x68, 0x69, 0x6f, 0x6a, 0x69, 0x5f, 0x62, 0x32, 0x10, 0x2a, 0x32, 0x5e, 0x0a,
0x11, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x53, 0x74, 0x61, 0x74, 0x65, 0x4d, 0x61, 0x6e, 0x61, 0x67,
0x65, 0x72, 0x12, 0x49, 0x0a, 0x10, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x42, 0x6c, 0x6f, 0x63,
0x6b, 0x53, 0x74, 0x61, 0x74, 0x65, 0x12, 0x18, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x42,
diff --git a/backend/proto/block.proto b/backend/proto/block.proto
index ffb65a70..02369187 100644
--- a/backend/proto/block.proto
+++ b/backend/proto/block.proto
@@ -42,7 +42,7 @@ enum BlockId {
hashimoto_b2 = 32;
hachioji_b1 = 41;
- hashioji_b2 = 42;
+ hachioji_b2 = 42;
}
message BlockAndState {
diff --git a/debug/auto_operation_visualizer/package-lock.json b/debug/auto_operation_visualizer/package-lock.json
index 91a4f4f6..2fffb59c 100644
--- a/debug/auto_operation_visualizer/package-lock.json
+++ b/debug/auto_operation_visualizer/package-lock.json
@@ -18,7 +18,7 @@
"react": "18.2.0",
"react-dom": "18.2.0",
"socket.io-client": "^4.5.3",
- "typescript": "4.9.3"
+ "typescript": "4.8.4"
}
},
"node_modules/@babel/runtime": {
@@ -2882,9 +2882,9 @@
}
},
"node_modules/typescript": {
- "version": "4.9.3",
- "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.3.tgz",
- "integrity": "sha512-CIfGzTelbKNEnLpLdGFgdyKhG23CKdKgQPOBc+OUNrkJ2vr+KSzsSV5kq5iWhEQbok+quxgGzrAtGWCyU7tHnA==",
+ "version": "4.8.4",
+ "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.8.4.tgz",
+ "integrity": "sha512-QCh+85mCy+h0IGff8r5XWzOVSbBO+KfeYrMQh7NJ58QujwcE22u+NUSmUxqF+un70P9GXKxa2HCNiTTMJknyjQ==",
"bin": {
"tsc": "bin/tsc",
"tsserver": "bin/tsserver"
@@ -4962,9 +4962,9 @@
"integrity": "sha512-Ne+eE4r0/iWnpAxD852z3A+N0Bt5RN//NjJwRd2VFHEmrywxf5vsZlh4R6lixl6B+wz/8d+maTSAkN1FIkI3LQ=="
},
"typescript": {
- "version": "4.9.3",
- "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.3.tgz",
- "integrity": "sha512-CIfGzTelbKNEnLpLdGFgdyKhG23CKdKgQPOBc+OUNrkJ2vr+KSzsSV5kq5iWhEQbok+quxgGzrAtGWCyU7tHnA=="
+ "version": "4.8.4",
+ "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.8.4.tgz",
+ "integrity": "sha512-QCh+85mCy+h0IGff8r5XWzOVSbBO+KfeYrMQh7NJ58QujwcE22u+NUSmUxqF+un70P9GXKxa2HCNiTTMJknyjQ=="
},
"unbox-primitive": {
"version": "1.0.2",
diff --git a/debug/auto_operation_visualizer/package.json b/debug/auto_operation_visualizer/package.json
index b49dbf58..909514d6 100644
--- a/debug/auto_operation_visualizer/package.json
+++ b/debug/auto_operation_visualizer/package.json
@@ -19,6 +19,6 @@
"react": "18.2.0",
"react-dom": "18.2.0",
"socket.io-client": "^4.5.3",
- "typescript": "4.9.3"
+ "typescript": "4.8.4"
}
}
diff --git a/frontend/camera_sender/index.html b/frontend/camera_sender/index.html
index 40b97f24..25484450 100644
--- a/frontend/camera_sender/index.html
+++ b/frontend/camera_sender/index.html
@@ -22,6 +22,9 @@
Room example
+
+
+
diff --git a/frontend/camera_sender/index.js b/frontend/camera_sender/index.js
index 7cff67e2..d00ea6e3 100644
--- a/frontend/camera_sender/index.js
+++ b/frontend/camera_sender/index.js
@@ -2,10 +2,27 @@ const Peer = window.Peer
;
(async function main() {
+ var sel = document.getElementById('select');
+ const devices = (await navigator.mediaDevices.enumerateDevices())
+ .filter((device) => device.kind === 'videoinput')
+ .map((device) => {
+ return {
+ text: device.label,
+ value: device.deviceId,
+ };
+ });
+ for (var i = 0; i < devices.length; i++) {
+ var opt = document.createElement("option");
+ opt.value = devices[i].value;
+ opt.text = devices[i].text;
+ sel.add(opt, null);
+ }
+ console.log(devices);
const localVideo = document.getElementById("js-local-stream")
const joinTrigger = document.getElementById("js-join-trigger")
const leaveTrigger = document.getElementById("js-leave-trigger")
const remoteVideos = document.getElementById("js-remote-streams")
+ const setCameraTrigger = document.getElementById("set-camera-trigger")
const roomId = document.getElementById("js-room-id")
const roomMode = document.getElementById("js-room-mode")
const localText = document.getElementById("js-local-text")
@@ -27,16 +44,34 @@ const Peer = window.Peer
() => (roomMode.textContent = getRoomModeByHash())
)
- const localStream = await navigator.mediaDevices
+ let localStream = await navigator.mediaDevices
.getUserMedia({
- video: true,
+ video: {
+ deviceId: document.getElementById('select').value
+ }
})
- .catch(console.error)
+ .catch(console.error);
+
+ setCameraTrigger.addEventListener("click", async () => {
+ localStream = await navigator.mediaDevices
+ .getUserMedia({
+ video: {
+ deviceId: document.getElementById('select').value
+ }
+ })
+ .catch(console.error)
+ // Render local stream
+ localVideo.muted = true;
+ localVideo.srcObject = localStream;
+ localVideo.playsInline = true;
+ await localVideo.play().catch(console.error)
+ });
+
// Render local stream
- localVideo.muted = true
- localVideo.srcObject = localStream
- localVideo.playsInline = true
+ localVideo.muted = true;
+ localVideo.srcObject = localStream;
+ localVideo.playsInline = true;
await localVideo.play().catch(console.error)
// eslint-disable-next-line require-atomic-updates
diff --git a/frontend/site/components/RailRoadMap.tsx b/frontend/site/components/RailRoadMap.tsx
index 8c5886da..a77935e2 100644
--- a/frontend/site/components/RailRoadMap.tsx
+++ b/frontend/site/components/RailRoadMap.tsx
@@ -4,13 +4,19 @@ import Platform from "./svgParts/Platform"
import SwitchPoint from "./svgParts/SwitchPoint"
import StopPoint from "./svgParts/StopPoint"
import { Point, TrainData } from "../types/svgPartsTypes"
-import { BunkiRailId, StationId, StopRailId } from "../types/control-messages"
+import {
+ BlocklId,
+ BunkiRailId,
+ StationId,
+ StopRailId,
+} from "../types/control-messages"
interface Prop {
datas: {
stop: Record
switchState: Record
train1: TrainData
+ blockState: Record
}
onStopPointOrSwitchPointClick?: (stationId: StationId) => any
}
@@ -27,33 +33,23 @@ type MapRange = {
}
const STOP_PONINTS: StopPointPosition[] = [
- { position: { x: 940, y: 560 }, id: "motoyawata_s1" },
- { position: { x: 1000, y: 560 }, id: "motoyawata_s2" },
- { position: { x: 120, y: 20 }, id: "kitano_s6" },
- { position: { x: 240, y: 20 }, id: "kitano_s4" },
- { position: { x: 240, y: 60 }, id: "kitano_s3" },
- { position: { x: 240, y: 80 }, id: "kitano_s2" },
- { position: { x: 240, y: 120 }, id: "kitano_s1" },
- { position: { x: 520, y: 20 }, id: "chofu_s4" },
- { position: { x: 520, y: 60 }, id: "chofu_s3" },
- { position: { x: 520, y: 120 }, id: "chofu_s2" },
- { position: { x: 520, y: 160 }, id: "chofu_s1" },
- { position: { x: 700, y: 60 }, id: "meidaimae_s2" },
- { position: { x: 700, y: 80 }, id: "meidaimae_s1" },
- { position: { x: 800, y: 70 }, id: "sasazuka_s5" },
- { position: { x: 880, y: 20 }, id: "sasazuka_s4" },
- { position: { x: 880, y: 60 }, id: "sasazuka_s3" },
- { position: { x: 880, y: 80 }, id: "sasazuka_s2" },
- { position: { x: 880, y: 120 }, id: "sasazuka_s1" },
- { position: { x: 120, y: 140 }, id: "kitano_s5" },
- { position: { x: 180, y: 200 }, id: "takao_s1" },
- { position: { x: 120, y: 380 }, id: "takao_s2" },
- { position: { x: 320, y: 180 }, id: "chofu_s5" },
- { position: { x: 940, y: 180 }, id: "kudanshita_s5" },
- { position: { x: 1000, y: 180 }, id: "kudanshita_s6" },
- { position: { x: 880, y: 380 }, id: "iwamotocho_s1" },
- { position: { x: 940, y: 380 }, id: "iwamotocho_s2" },
- { position: { x: 1000, y: 380 }, id: "iwamotocho_s4" },
+ { position: { x: 700, y: 40 }, id: "shinjuku_s1" },
+ { position: { x: 700, y: 100 }, id: "shinjuku_s2" },
+ { position: { x: 950, y: 250 }, id: "sakurajosui_s0" },
+ { position: { x: 1000, y: 400 }, id: "sakurajosui_s1" },
+ { position: { x: 950, y: 400 }, id: "sakurajosui_s2" },
+ { position: { x: 900, y: 400 }, id: "sakurajosui_s3" },
+ { position: { x: 850, y: 400 }, id: "sakurajosui_s4" },
+ { position: { x: 900, y: 500 }, id: "sakurajosui_s5" },
+ { position: { x: 350, y: 550 }, id: "chofu_s0" },
+ { position: { x: 350, y: 400 }, id: "chofu_s1" },
+ { position: { x: 400, y: 400 }, id: "chofu_s2" },
+ { position: { x: 300, y: 400 }, id: "chofu_s4" },
+ { position: { x: 240, y: 400 }, id: "chofu_s3" },
+ { position: { x: 90, y: 40 }, id: "hachioji_s2" },
+ { position: { x: 90, y: 100 }, id: "hachioji_s1" },
+ { position: { x: 90, y: 300 }, id: "hashimoto_s1" },
+ { position: { x: 90, y: 240 }, id: "hashimoto_s2" },
]
type SwitchPointPotiionAndAngle = {
@@ -65,81 +61,18 @@ type SwitchPointPotiionAndAngle = {
}
const SWITCH_POINTS: SwitchPointPotiionAndAngle[] = [
{
- position: { x: 160, y: 20 },
- fromAngle: 180,
- leftOutAngle: 0,
- rightOutAngle: 45,
- id: "kitano_b2",
- },
- {
- position: { x: 320, y: 120 },
- fromAngle: 0,
- leftOutAngle: 180,
- rightOutAngle: 225,
- id: "kitano_b1",
- },
- {
- position: { x: 380, y: 20 },
- fromAngle: 180,
- leftOutAngle: 45,
- rightOutAngle: 0,
- id: "chofu_b5",
- },
- {
- position: { x: 440, y: 60 },
- fromAngle: 180,
- leftOutAngle: -45,
- rightOutAngle: 0,
- id: "chofu_b4",
- },
- {
- position: { x: 420, y: 160 },
- fromAngle: 0,
- leftOutAngle: 225,
- rightOutAngle: 180,
- id: "chofu_b3",
- },
- {
- position: { x: 480, y: 120 },
- fromAngle: 0,
- leftOutAngle: 180,
- rightOutAngle: 135,
- id: "chofu_b2",
- },
- {
- position: { x: 600, y: 120 },
- fromAngle: 0,
- leftOutAngle: 135,
- rightOutAngle: 180,
- id: "chofu_b1",
- },
- {
- position: { x: 800, y: 20 },
- fromAngle: 180,
- leftOutAngle: 0,
- rightOutAngle: 45,
- id: "sasazuka_b2",
- },
- {
- position: { x: 840, y: 80 },
- fromAngle: 0,
- leftOutAngle: 180,
- rightOutAngle: 135,
- id: "sasazuka_b1",
- },
- {
- position: { x: 1000, y: 280 },
+ position: { x: 950, y: 300 },
fromAngle: 270,
leftOutAngle: 90,
- rightOutAngle: 135,
- id: "iwamotocho_b4",
+ rightOutAngle: 0,
+ id: "sakurajosui_p1",
},
{
- position: { x: 940, y: 480 },
+ position: { x: 350, y: 500 },
fromAngle: 90,
leftOutAngle: 270,
- rightOutAngle: 225,
- id: "iwamotocho_b1",
+ rightOutAngle: 0,
+ id: "chofu_p1",
},
]
@@ -160,111 +93,47 @@ const MAP_RANGES: MapRange[] = [
{
range: {
leftUp: { x: 0, y: 0 },
- rightDown: { x: 180, y: 140 },
+ rightDown: { x: 360, y: 140 },
},
id: "keiohachioji",
name: "京王八王子付近",
},
{
range: {
- leftUp: { x: 120, y: 0 },
- rightDown: { x: 360, y: 140 },
+ leftUp: { x: 0, y: 200 },
+ rightDown: { x: 360, y: 350 },
},
id: "kitano",
- name: "北野付近",
+ name: "橋本付近",
},
{
range: {
- leftUp: { x: 360, y: 0 },
- rightDown: { x: 620, y: 180 },
+ leftUp: { x: 200, y: 300 },
+ rightDown: { x: 620, y: 600 },
},
id: "chofu",
name: "調布付近",
},
{
range: {
- leftUp: { x: 620, y: 0 },
- rightDown: { x: 800, y: 140 },
+ leftUp: { x: 800, y: 200 },
+ rightDown: { x: 1200, y: 540 },
},
id: "meidaimae",
- name: "明大前付近",
+ name: "桜上水付近",
},
{
range: {
- leftUp: { x: 780, y: 0 },
+ leftUp: { x: 500, y: 0 },
rightDown: { x: 1020, y: 140 },
},
id: "sasazuka",
- name: "笹塚付近",
- },
- {
- range: {
- leftUp: { x: 780, y: 0 },
- rightDown: { x: 1020, y: 140 },
- },
- id: "shinjuku",
name: "新宿付近",
},
- {
- range: {
- leftUp: { x: 100, y: 100 },
- rightDown: { x: 200, y: 280 },
- },
- id: "takao",
- name: "高尾付近",
- },
- {
- range: {
- leftUp: { x: 100, y: 300 },
- rightDown: { x: 200, y: 440 },
- },
- id: "takaosanguchi",
- name: "高尾山口付近",
- },
- {
- range: {
- leftUp: { x: 300, y: 140 },
- rightDown: { x: 400, y: 340 },
- },
- id: "wakabadai",
- name: "若葉台付近",
- },
- {
- range: {
- leftUp: { x: 300, y: 320 },
- rightDown: { x: 400, y: 440 },
- },
- id: "hashimoto",
- name: "橋本付近",
- },
- {
- range: {
- leftUp: { x: 920, y: 140 },
- rightDown: { x: 1020, y: 260 },
- },
- id: "kudanshita",
- name: "九段下付近",
- },
- {
- range: {
- leftUp: { x: 860, y: 260 },
- rightDown: { x: 1020, y: 500 },
- },
- id: "iwamotocho",
- name: "岩本町付近",
- },
- {
- range: {
- leftUp: { x: 920, y: 500 },
- rightDown: { x: 1020, y: 620 },
- },
- id: "motoyawata",
- name: "本八幡付近",
- },
]
const RailroadMap: FC = ({
- datas: { stop, switchState, train1 },
+ datas: { stop, switchState, train1, blockState },
onStopPointOrSwitchPointClick,
}) => {
const [mapRange, setMapRange] = useState(MAP_RANGES[0])
@@ -278,411 +147,220 @@ const RailroadMap: FC = ({
>
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
{STOP_PONINTS.map(({ position, id }) => (
diff --git a/frontend/site/components/VideoCast.tsx b/frontend/site/components/VideoCast.tsx
index 2ee17d6d..e5596abf 100644
--- a/frontend/site/components/VideoCast.tsx
+++ b/frontend/site/components/VideoCast.tsx
@@ -15,45 +15,54 @@ interface Prop {
roomIds: string[]
styles: CSSProperties[]
}
-const SW_WSURL = "wss://webrtc.chofufes2022.ueckoken.club/"
+
const SKYWAY_APIKEY =
process.env.SKYWAY_APIKEY === undefined
? "2eb379e0-0374-4e3c-9674-d7415b0b7f27"
: process.env.SKYWAY_APIKEY
const SKYWAY_DEBUG_LEVEL = 2
-const skyWayPeer: Peer = new Peer({
- key: SKYWAY_APIKEY,
- debug: SKYWAY_DEBUG_LEVEL,
-})
-
const VideoCast: FC = ({ roomIds, styles }) => {
const [isPeerAvailable, setIsPeerAvailable] = useState(false)
+ const skyWayPeer = useRef()
useEffect(() => {
- skyWayPeer?.on("open", (id) => {
- console.log(`opened skyway peer id:${id}`)
- setIsPeerAvailable(true)
+ skyWayPeer.current = new Peer({
+ key: SKYWAY_APIKEY,
+ debug: SKYWAY_DEBUG_LEVEL,
})
- skyWayPeer?.on("close", () => {
- console.log("closed skyway peer")
+ function onPeerOpen(id: string) {
+ console.log(`opened skyway peer id: ${id}`)
+ setIsPeerAvailable(true)
+ }
+ function onPeerClose() {
+ console.log(`closed skyway peer id: ${skyWayPeer.current?.id}`)
setIsPeerAvailable(false)
- })
+ }
+ skyWayPeer.current.on("open", onPeerOpen)
+ skyWayPeer.current.on("close", onPeerClose)
return () => {
- skyWayPeer?.destroy()
- setIsPeerAvailable(false)
+ console.log("clean up skyway peer")
+ if (skyWayPeer.current === undefined) {
+ return
+ }
+ skyWayPeer.current.off("open", onPeerOpen)
+ skyWayPeer.current.off("close", onPeerClose)
+ skyWayPeer.current.destroy()
+ skyWayPeer.current = undefined
}
- }, [])
+ }, [setIsPeerAvailable])
return (
{roomIds.map((roomId, index) => {
- if (skyWayPeer === undefined || !isPeerAvailable) {
+ console.log("skyway peer", skyWayPeer.current)
+ if (!skyWayPeer.current || !isPeerAvailable) {
return Peer not available
}
return (
@@ -75,6 +84,8 @@ const RoomViewer: FC = ({ roomId, peer, style }) => {
useEffect(() => {
console.log("joinroom ", roomId)
+ console.log("peerinfo", peer)
+ while (!peer.open) {}
const skywayRoom = peer.joinRoom(roomId, {
mode: "sfu",
})
diff --git a/frontend/site/components/svgParts/Rail.tsx b/frontend/site/components/svgParts/Rail.tsx
index bbe624e0..ed9112e3 100644
--- a/frontend/site/components/svgParts/Rail.tsx
+++ b/frontend/site/components/svgParts/Rail.tsx
@@ -4,9 +4,10 @@ import { Point, TrainData } from "../../types/svgPartsTypes"
interface Props {
positions: [Point, Point, ...Point[]]
trains: TrainData[]
+ isClosed: boolean
}
-const Rail: FC = ({ positions, trains }) => {
+const Rail: FC = ({ positions, trains, isClosed }) => {
const pointsText = positions
.map((point: Point) => `${point.x}, ${point.y}`)
.join("\n")
@@ -14,7 +15,8 @@ const Rail: FC = ({ positions, trains }) => {
diff --git a/frontend/site/next.config.js b/frontend/site/next.config.js
index 8b61df4e..3a4b6577 100644
--- a/frontend/site/next.config.js
+++ b/frontend/site/next.config.js
@@ -1,4 +1,4 @@
/** @type {import('next').NextConfig} */
module.exports = {
- reactStrictMode: true,
+ reactStrictMode: false,
}
diff --git a/frontend/site/package.json b/frontend/site/package.json
index a6138dfb..87478299 100644
--- a/frontend/site/package.json
+++ b/frontend/site/package.json
@@ -26,6 +26,6 @@
"eslint-config-next": "12.3.3",
"eslint-config-prettier": "8.5.0",
"prettier": "2.7.1",
- "typescript": "4.9.3"
+ "typescript": "4.8.4"
}
}
diff --git a/frontend/site/pages/index.tsx b/frontend/site/pages/index.tsx
index 1facf082..d126aefa 100644
--- a/frontend/site/pages/index.tsx
+++ b/frontend/site/pages/index.tsx
@@ -5,6 +5,7 @@ import RailroadMap from "../components/RailRoadMap"
import VideoCast from "../components/VideoCast"
import { useEffect, useRef, useState } from "react"
import {
+ BlocklId,
bunkiRailId,
BunkiRailId,
Message,
@@ -13,120 +14,54 @@ import {
StopRailId,
stopRailId,
} from "../types/control-messages"
-import SpeedMeter from "../components/svgParts/SpeedMeter"
-import { SpeedMessage, TrainId } from "../types/speed-messages"
-import ReverseHandle from "../components/svgParts/ReverseHandle"
// OFF: false, ON: trueと対応
type StopPointState = Record
const INITIAL_STOP_POINT_STATE: StopPointState = {
- motoyawata_s1: false,
- motoyawata_s2: false,
- iwamotocho_s1: false,
- iwamotocho_s2: false,
- iwamotocho_s4: false,
- kudanshita_s5: false,
- kudanshita_s6: false,
- sasazuka_s1: false,
- sasazuka_s2: false,
- sasazuka_s3: false,
- sasazuka_s4: false,
- sasazuka_s5: false,
- meidaimae_s1: false,
- meidaimae_s2: false,
+ shinjuku_s1: false,
+ shinjuku_s2: false,
+ sakurajosui_s0: false,
+ sakurajosui_s1: false,
+ sakurajosui_s2: false,
+ sakurajosui_s3: false,
+ sakurajosui_s4: false,
+ sakurajosui_s5: false,
+ chofu_s0: false,
chofu_s1: false,
chofu_s2: false,
chofu_s3: false,
chofu_s4: false,
- chofu_s5: false,
- chofu_s6: false,
- kitano_s1: false,
- kitano_s2: false,
- kitano_s3: false,
- kitano_s4: false,
- kitano_s5: false,
- kitano_s6: false,
- kitano_s7: false,
- takao_s1: false,
- takao_s2: false,
+ hachioji_s1: false,
+ hachioji_s2: false,
+ hashimoto_s1: false,
+ hashimoto_s2: false,
}
-type SwitchPointState = Record
-const INITIAL_SWITCH_POINT_STATE: SwitchPointState = {
- iwamotocho_b1: false,
- iwamotocho_b2: false,
- iwamotocho_b3: false,
- iwamotocho_b4: false,
- sasazuka_b1: false,
- sasazuka_b2: false,
+type BlockState = Record
+const INITIAL_BLOCK_STATE: BlockState = {
+ shinjuku_b1: false,
+ shinjuku_b2: false,
+ sakurajosui_b1: false,
+ sakurajosui_b2: false,
+ sakurajosui_b3: false,
+ sakurajosui_b4: false,
+ sakurajosui_b5: false,
+ sakurajosui_b6: false,
chofu_b1: false,
chofu_b2: false,
chofu_b3: false,
chofu_b4: false,
chofu_b5: false,
- kitano_b1: false,
- kitano_b2: false,
- kitano_b3: false,
-}
-
-type SpeedState = Record
-const INITIAL_SPEED_STATE: SpeedState = {
- TAKAO: 0,
- CHICHIBU: 0,
- HAKONE: 0,
- OKUTAMA: 0,
- NIKKO: 0,
- ENOSHIMA: 0,
- KAMAKURA: 0,
- YOKOSUKA: 0,
+ hashimoto_b1: false,
+ hashimoto_b2: false,
+ hachioji_b1: false,
+ hachioji_b2: false,
}
-const INITIAL_SELECTED_TRAIN_ID: TrainId = "TAKAO"
-const stationIdAndTextMap: Record = {
- motoyawata_s1: "本八幡1番線",
- motoyawata_s2: "本八幡2番線",
- iwamotocho_s1: "岩本町1番線",
- iwamotocho_s2: "岩本町2, 3番線",
- iwamotocho_s4: "岩本町4番線",
- kudanshita_s5: "九段下1番線",
- kudanshita_s6: "九段下2番線",
- sasazuka_s1: "笹塚1番線",
- sasazuka_s2: "笹塚2番線",
- sasazuka_s3: "笹塚3番線",
- sasazuka_s4: "笹塚4番線",
- sasazuka_s5: "笹塚新線",
- meidaimae_s1: "明大前1番線",
- meidaimae_s2: "明大前2番線",
- chofu_s1: "調布1番線",
- chofu_s2: "調布2番線",
- chofu_s3: "調布3番線",
- chofu_s4: "調布4番線",
- chofu_s5: "調布-若葉台",
- chofu_s6: "unknown",
- kitano_s1: "北野1番線",
- kitano_s2: "北野2番線",
- kitano_s3: "北野3番線",
- kitano_s4: "北野4番線",
- kitano_s5: "北野-高尾",
- kitano_s6: "北野-京王八王子",
- kitano_s7: "unknown",
- takao_s1: "高尾",
- takao_s2: "高尾山口",
- iwamotocho_b1: "岩本町1-2,3番線分岐",
- iwamotocho_b2: "unknown",
- iwamotocho_b3: "unknown",
- iwamotocho_b4: "岩本町2,3-4番線分岐",
- sasazuka_b1: "笹塚新線-明大前分岐",
- sasazuka_b2: "笹塚3-4番線分岐",
- chofu_b1: "調布1-2番線分岐",
- chofu_b2: "調布2番線若葉台-北野分岐",
- chofu_b3: "若葉台-北野分岐",
- chofu_b4: "調布3-4番線分岐2",
- chofu_b5: "調布3-4番線分岐1",
- kitano_b1: "北野-高尾分岐",
- kitano_b2: "北野3-4番線分岐",
- kitano_b3: "unknown",
- unknown: "unknown",
+type SwitchPointState = Record
+const INITIAL_SWITCH_POINT_STATE: SwitchPointState = {
+ chofu_p1: false,
+ sakurajosui_p1: false,
}
const Home: NextPage = () => {
@@ -137,17 +72,14 @@ const Home: NextPage = () => {
const [switchPointState, setSwitchPointState] = useState(
INITIAL_SWITCH_POINT_STATE
)
+ useEffect(() => {
+ setSwitchPointState(INITIAL_SWITCH_POINT_STATE)
+ })
+ const [blockState, setBlockState] = useState(INITIAL_BLOCK_STATE)
const [selectedStationId, setSelectedStationId] =
useState("unknown")
const [trainPosition1, setTrainPosition1] = useState(0.4)
- const speedWs = useRef()
- const [speedState, setSpeedState] = useState(INITIAL_SPEED_STATE)
- const [selectedTrainId, setSelectedTrainId] = useState(
- INITIAL_SELECTED_TRAIN_ID
- )
- const [isBack, setIsBack] = useState(false)
-
const [roomIds, setRoomIds] = useState(["chofu", "train"])
const changeStopPointOrSwtichPointState = (
@@ -173,33 +105,6 @@ const Home: NextPage = () => {
changeStopPointOrSwtichPointState(stationId, nextState)
}
- useEffect(() => {
- const ws = new WebSocket("wss://speed.chofufes2022.ueckoken.club/speed")
- speedWs.current = ws
- ws.addEventListener("open", (e) => {
- console.log("opened")
- })
- ws.addEventListener("message", (e) => {
- const message: SpeedMessage = JSON.parse(e.data)
- console.log(message)
- setSpeedState((previousState) => ({
- ...previousState,
- [message.train_name]: message.speed,
- }))
- })
- ws.addEventListener("error", (e) => {
- console.log("error occured")
- console.log(e)
- })
- ws.addEventListener("close", (e) => {
- console.log("closed")
- console.log(e)
- })
- return () => {
- ws.close()
- }
- }, [])
-
useEffect(() => {
const ws = new WebSocket("wss://control.chofufes2022.ueckoken.club/ws")
stationWs.current = ws
@@ -253,15 +158,13 @@ const Home: NextPage = () => {
return (
-
工研×鉄研プラレール展示 操作ページ
+ 工研×鉄研プラレール展示 管理画面
-
- 工研×鉄研プラレール展示 操作ページ
-
+ 工研×鉄研プラレール展示 管理画面
@@ -295,49 +198,42 @@ const Home: NextPage = () => {
-