| to be tested
This commit is contained in:
parent
10c82104d2
commit
aebbdccd03
13 changed files with 509 additions and 385 deletions
BIN
backend.light/backend.light
Executable file
BIN
backend.light/backend.light
Executable file
Binary file not shown.
|
@ -67,12 +67,3 @@ func (app *App) RegisterWebRoutes() {
|
|||
app.Engine.ForwardedByClientIP = true
|
||||
app.Engine.SetTrustedProxies([]string{"127.0.0.1"})
|
||||
}
|
||||
|
||||
func (app *App) RegisterApiRoutes() {
|
||||
|
||||
api := app.Engine.Group("/api")
|
||||
|
||||
api.GET("/sse", app.Stream.SseHeadersMiddleware(), app.Stream.Stream)
|
||||
api.GET("/priority", app.GetPriority)
|
||||
api.POST("/priority", app.SetPriority)
|
||||
}
|
||||
|
|
50
backend.light/http_api.go
Normal file
50
backend.light/http_api.go
Normal file
|
@ -0,0 +1,50 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func (app *App) RegisterApiRoutes() {
|
||||
|
||||
api := app.Engine.Group("/api")
|
||||
|
||||
api.GET("/sse", app.Stream.SseHeadersMiddleware(), app.Stream.Stream)
|
||||
api.GET("/priority", app.GetPriority)
|
||||
api.POST("/priority", app.SetPriority)
|
||||
}
|
||||
|
||||
func (app *App) GetPriority(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, app.Stream.Data)
|
||||
|
||||
log.Printf("priority: %+v", app.Stream.Data)
|
||||
}
|
||||
|
||||
func (app *App) SetPriority(c *gin.Context) {
|
||||
var priority = &Priority{}
|
||||
|
||||
body, _ := io.ReadAll(c.Request.Body)
|
||||
log.Printf("set priority %s", string(body))
|
||||
|
||||
c.Request.Body = io.NopCloser(bytes.NewReader(body))
|
||||
|
||||
c.ShouldBind(priority)
|
||||
log.Printf("priority: %+v", priority)
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": http.StatusOK,
|
||||
"message": priority,
|
||||
})
|
||||
|
||||
var msg = Message{
|
||||
Event: "priority",
|
||||
Data: priority,
|
||||
}
|
||||
|
||||
app.Stream.Send(msg)
|
||||
|
||||
app.Stream.Data = priority
|
||||
}
|
12
backend.light/priority.go
Normal file
12
backend.light/priority.go
Normal file
|
@ -0,0 +1,12 @@
|
|||
package main
|
||||
|
||||
type Priority struct {
|
||||
Surfers []Surfer `json:"surfers"`
|
||||
Count int `json:"count"`
|
||||
}
|
||||
|
||||
type Surfer struct {
|
||||
Name string `json:"name"`
|
||||
Color string `json:"color"`
|
||||
Priority string `json:"priority"`
|
||||
}
|
|
@ -13,29 +13,6 @@ import (
|
|||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
var events = []string{"message", "timer", "priority", "cmd"}
|
||||
|
||||
type Message struct {
|
||||
Event string `json:"event"`
|
||||
Data string `json:"data"`
|
||||
Id string `json:"id"`
|
||||
}
|
||||
|
||||
type ClientChan chan Message
|
||||
|
||||
type Client struct {
|
||||
Id string `json:"id"`
|
||||
Ip string `json:"ip"`
|
||||
Chan ClientChan `json:"chan"`
|
||||
Events []string `json:"events"`
|
||||
}
|
||||
|
||||
type SseStream struct {
|
||||
Clients []Client `json:"clients"`
|
||||
MsgId map[string]int `json:"msgid"`
|
||||
Events []string `json:"events"`
|
||||
}
|
||||
|
||||
func InitSse() *SseStream {
|
||||
sse := &SseStream{
|
||||
Clients: make([]Client, 0),
|
||||
|
@ -79,7 +56,7 @@ func (sse *SseStream) Stream(c *gin.Context) {
|
|||
log.Printf("Client %s disconnected", client.Ip)
|
||||
}()
|
||||
|
||||
log.Printf("Client %s connected", client.Ip)
|
||||
log.Printf("Client %s connected - TOT %+v", client.Ip, sse.Clients)
|
||||
|
||||
c.Stream(func(w io.Writer) bool {
|
||||
msg, ok := <-client.Chan
|
25
backend.light/sse_struct.go
Normal file
25
backend.light/sse_struct.go
Normal file
|
@ -0,0 +1,25 @@
|
|||
package main
|
||||
|
||||
var events = []string{"message", "timer", "priority", "cmd"}
|
||||
|
||||
type Message struct {
|
||||
Event string `json:"event"`
|
||||
Data interface{} `json:"data"`
|
||||
Id string `json:"id"`
|
||||
}
|
||||
|
||||
type ClientChan chan Message
|
||||
|
||||
type Client struct {
|
||||
Id string `json:"id"`
|
||||
Ip string `json:"ip"`
|
||||
Chan ClientChan `json:"chan"`
|
||||
Events []string `json:"events"`
|
||||
}
|
||||
|
||||
type SseStream struct {
|
||||
Clients []Client `json:"clients"`
|
||||
MsgId map[string]int `json:"msgid"`
|
||||
Events []string `json:"events"`
|
||||
Data interface{} `json:"data"`
|
||||
}
|
|
@ -1,7 +1 @@
|
|||
package main
|
||||
|
||||
type Surfers struct {
|
||||
Name string `json:"name"`
|
||||
Color string `json:"color"`
|
||||
Priority string `json:"priority"`
|
||||
}
|
||||
|
|
|
@ -10,18 +10,18 @@
|
|||
"format": "prettier --write ."
|
||||
},
|
||||
"devDependencies": {
|
||||
"@sveltejs/adapter-auto": "^3.0.0",
|
||||
"@sveltejs/adapter-auto": "^3.1.0",
|
||||
"@sveltejs/adapter-static": "^3.0.1",
|
||||
"@sveltejs/kit": "^2.0.0",
|
||||
"@sveltejs/vite-plugin-svelte": "^3.0.0",
|
||||
"@sveltejs/kit": "^2.3.0",
|
||||
"@sveltejs/vite-plugin-svelte": "^3.0.1",
|
||||
"@types/eslint": "8.56.0",
|
||||
"eslint": "^8.56.0",
|
||||
"eslint-config-prettier": "^9.1.0",
|
||||
"eslint-plugin-svelte": "^2.35.1",
|
||||
"prettier": "^3.1.1",
|
||||
"prettier-plugin-svelte": "^3.1.2",
|
||||
"svelte": "^4.2.7",
|
||||
"vite": "^5.0.3"
|
||||
"svelte": "^4.2.8",
|
||||
"vite": "^5.0.11"
|
||||
},
|
||||
"type": "module"
|
||||
}
|
||||
|
|
118
frontend.light/pnpm-lock.yaml
generated
118
frontend.light/pnpm-lock.yaml
generated
|
@ -6,17 +6,17 @@ settings:
|
|||
|
||||
devDependencies:
|
||||
'@sveltejs/adapter-auto':
|
||||
specifier: ^3.0.0
|
||||
version: 3.0.0(@sveltejs/kit@2.0.0)
|
||||
specifier: ^3.1.0
|
||||
version: 3.1.0(@sveltejs/kit@2.3.0)
|
||||
'@sveltejs/adapter-static':
|
||||
specifier: ^3.0.1
|
||||
version: 3.0.1(@sveltejs/kit@2.0.0)
|
||||
version: 3.0.1(@sveltejs/kit@2.3.0)
|
||||
'@sveltejs/kit':
|
||||
specifier: ^2.0.0
|
||||
version: 2.0.0(@sveltejs/vite-plugin-svelte@3.0.0)(svelte@4.2.7)(vite@5.0.3)
|
||||
specifier: ^2.3.0
|
||||
version: 2.3.0(@sveltejs/vite-plugin-svelte@3.0.1)(svelte@4.2.8)(vite@5.0.11)
|
||||
'@sveltejs/vite-plugin-svelte':
|
||||
specifier: ^3.0.0
|
||||
version: 3.0.0(svelte@4.2.7)(vite@5.0.3)
|
||||
specifier: ^3.0.1
|
||||
version: 3.0.1(svelte@4.2.8)(vite@5.0.11)
|
||||
'@types/eslint':
|
||||
specifier: 8.56.0
|
||||
version: 8.56.0
|
||||
|
@ -28,19 +28,19 @@ devDependencies:
|
|||
version: 9.1.0(eslint@8.56.0)
|
||||
eslint-plugin-svelte:
|
||||
specifier: ^2.35.1
|
||||
version: 2.35.1(eslint@8.56.0)(svelte@4.2.7)
|
||||
version: 2.35.1(eslint@8.56.0)(svelte@4.2.8)
|
||||
prettier:
|
||||
specifier: ^3.1.1
|
||||
version: 3.1.1
|
||||
prettier-plugin-svelte:
|
||||
specifier: ^3.1.2
|
||||
version: 3.1.2(prettier@3.1.1)(svelte@4.2.7)
|
||||
version: 3.1.2(prettier@3.1.1)(svelte@4.2.8)
|
||||
svelte:
|
||||
specifier: ^4.2.7
|
||||
version: 4.2.7
|
||||
specifier: ^4.2.8
|
||||
version: 4.2.8
|
||||
vite:
|
||||
specifier: ^5.0.3
|
||||
version: 5.0.3
|
||||
specifier: ^5.0.11
|
||||
version: 5.0.11
|
||||
|
||||
packages:
|
||||
|
||||
|
@ -301,11 +301,11 @@ packages:
|
|||
engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0}
|
||||
dev: true
|
||||
|
||||
/@humanwhocodes/config-array@0.11.13:
|
||||
resolution: {integrity: sha512-JSBDMiDKSzQVngfRjOdFXgFfklaXI4K9nLF49Auh21lmBWRLIK3+xTErTWD4KU54pb6coM6ESE7Awz/FNU3zgQ==}
|
||||
/@humanwhocodes/config-array@0.11.14:
|
||||
resolution: {integrity: sha512-3T8LkOmg45BV5FICb15QQMsyUSWrQ8AygVfC7ZG32zOalnqrilm018ZVCw0eapXux8FtA33q8PSRSstjee3jSg==}
|
||||
engines: {node: '>=10.10.0'}
|
||||
dependencies:
|
||||
'@humanwhocodes/object-schema': 2.0.1
|
||||
'@humanwhocodes/object-schema': 2.0.2
|
||||
debug: 4.3.4
|
||||
minimatch: 3.1.2
|
||||
transitivePeerDependencies:
|
||||
|
@ -317,8 +317,8 @@ packages:
|
|||
engines: {node: '>=12.22'}
|
||||
dev: true
|
||||
|
||||
/@humanwhocodes/object-schema@2.0.1:
|
||||
resolution: {integrity: sha512-dvuCeX5fC9dXgJn9t+X5atfmgQAzUOWqS1254Gh0m6i8wKd10ebXkfNKiRK+1GWi/yTvvLDHpoxLr0xxxeslWw==}
|
||||
/@humanwhocodes/object-schema@2.0.2:
|
||||
resolution: {integrity: sha512-6EwiSjwWYP7pTckG6I5eyFANjPhmPjUX9JRLUSfNPC7FX7zK9gyZAfUEaECL6ALTpGX5AjnBq3C9XmVWPitNpw==}
|
||||
dev: true
|
||||
|
||||
/@jridgewell/gen-mapping@0.3.3:
|
||||
|
@ -480,25 +480,25 @@ packages:
|
|||
dev: true
|
||||
optional: true
|
||||
|
||||
/@sveltejs/adapter-auto@3.0.0(@sveltejs/kit@2.0.0):
|
||||
resolution: {integrity: sha512-UNWSs/rOReBRfI/xFwSO2WYF1a7PT74SrWOHJmSNLY3Lq+zbH0uuvnlP+TmrTUBvOTkou3WJDjL6lK3n6aOUgQ==}
|
||||
/@sveltejs/adapter-auto@3.1.0(@sveltejs/kit@2.3.0):
|
||||
resolution: {integrity: sha512-igS5hqCwdiXWb8NoWzThKCVQQj9tKgUkbTtzfxBPgSLOyFjkiGNDX0SgCoY2QIUWBqOkfGTOqGlrW5Ynw9oUvw==}
|
||||
peerDependencies:
|
||||
'@sveltejs/kit': ^2.0.0
|
||||
dependencies:
|
||||
'@sveltejs/kit': 2.0.0(@sveltejs/vite-plugin-svelte@3.0.0)(svelte@4.2.7)(vite@5.0.3)
|
||||
'@sveltejs/kit': 2.3.0(@sveltejs/vite-plugin-svelte@3.0.1)(svelte@4.2.8)(vite@5.0.11)
|
||||
import-meta-resolve: 4.0.0
|
||||
dev: true
|
||||
|
||||
/@sveltejs/adapter-static@3.0.1(@sveltejs/kit@2.0.0):
|
||||
/@sveltejs/adapter-static@3.0.1(@sveltejs/kit@2.3.0):
|
||||
resolution: {integrity: sha512-6lMvf7xYEJ+oGeR5L8DFJJrowkefTK6ZgA4JiMqoClMkKq0s6yvsd3FZfCFvX1fQ0tpCD7fkuRVHsnUVgsHyNg==}
|
||||
peerDependencies:
|
||||
'@sveltejs/kit': ^2.0.0
|
||||
dependencies:
|
||||
'@sveltejs/kit': 2.0.0(@sveltejs/vite-plugin-svelte@3.0.0)(svelte@4.2.7)(vite@5.0.3)
|
||||
'@sveltejs/kit': 2.3.0(@sveltejs/vite-plugin-svelte@3.0.1)(svelte@4.2.8)(vite@5.0.11)
|
||||
dev: true
|
||||
|
||||
/@sveltejs/kit@2.0.0(@sveltejs/vite-plugin-svelte@3.0.0)(svelte@4.2.7)(vite@5.0.3):
|
||||
resolution: {integrity: sha512-/GFxvit+q7PztRbgGTFXhVB6jvb0fZSeWuz5f4siQ2r/5BVhxYh7++Bw3/ZUjiOuyoZFiNBmOPcRNQbkzEce0g==}
|
||||
/@sveltejs/kit@2.3.0(@sveltejs/vite-plugin-svelte@3.0.1)(svelte@4.2.8)(vite@5.0.11):
|
||||
resolution: {integrity: sha512-A6/aQTVFONDDv8nRLINNiXrERq6VeAdHT+/gHPBUSDt4+b6oBKTEF3oiGzNmxspcWDgHzBpypFO7NWtkoUK67g==}
|
||||
engines: {node: '>=18.13'}
|
||||
hasBin: true
|
||||
requiresBuild: true
|
||||
|
@ -507,23 +507,24 @@ packages:
|
|||
svelte: ^4.0.0 || ^5.0.0-next.0
|
||||
vite: ^5.0.3
|
||||
dependencies:
|
||||
'@sveltejs/vite-plugin-svelte': 3.0.0(svelte@4.2.7)(vite@5.0.3)
|
||||
'@sveltejs/vite-plugin-svelte': 3.0.1(svelte@4.2.8)(vite@5.0.11)
|
||||
'@types/cookie': 0.6.0
|
||||
cookie: 0.6.0
|
||||
devalue: 4.3.2
|
||||
esm-env: 1.0.0
|
||||
import-meta-resolve: 4.0.0
|
||||
kleur: 4.1.5
|
||||
magic-string: 0.30.5
|
||||
mrmime: 1.0.1
|
||||
mrmime: 2.0.0
|
||||
sade: 1.8.1
|
||||
set-cookie-parser: 2.6.0
|
||||
sirv: 2.0.4
|
||||
svelte: 4.2.7
|
||||
svelte: 4.2.8
|
||||
tiny-glob: 0.2.9
|
||||
vite: 5.0.3
|
||||
vite: 5.0.11
|
||||
dev: true
|
||||
|
||||
/@sveltejs/vite-plugin-svelte-inspector@2.0.0(@sveltejs/vite-plugin-svelte@3.0.0)(svelte@4.2.7)(vite@5.0.3):
|
||||
/@sveltejs/vite-plugin-svelte-inspector@2.0.0(@sveltejs/vite-plugin-svelte@3.0.1)(svelte@4.2.8)(vite@5.0.11):
|
||||
resolution: {integrity: sha512-gjr9ZFg1BSlIpfZ4PRewigrvYmHWbDrq2uvvPB1AmTWKuM+dI1JXQSUu2pIrYLb/QncyiIGkFDFKTwJ0XqQZZg==}
|
||||
engines: {node: ^18.0.0 || >=20}
|
||||
peerDependencies:
|
||||
|
@ -531,30 +532,30 @@ packages:
|
|||
svelte: ^4.0.0 || ^5.0.0-next.0
|
||||
vite: ^5.0.0
|
||||
dependencies:
|
||||
'@sveltejs/vite-plugin-svelte': 3.0.0(svelte@4.2.7)(vite@5.0.3)
|
||||
'@sveltejs/vite-plugin-svelte': 3.0.1(svelte@4.2.8)(vite@5.0.11)
|
||||
debug: 4.3.4
|
||||
svelte: 4.2.7
|
||||
vite: 5.0.3
|
||||
svelte: 4.2.8
|
||||
vite: 5.0.11
|
||||
transitivePeerDependencies:
|
||||
- supports-color
|
||||
dev: true
|
||||
|
||||
/@sveltejs/vite-plugin-svelte@3.0.0(svelte@4.2.7)(vite@5.0.3):
|
||||
resolution: {integrity: sha512-Th0nupxk8hl5Rcg9jm+1xWylwco4bSUAvutWxM4W4bjOAollpXLmrYqSSnYo9pPbZOO6ZGRm6sSqYa/v1d/Saw==}
|
||||
/@sveltejs/vite-plugin-svelte@3.0.1(svelte@4.2.8)(vite@5.0.11):
|
||||
resolution: {integrity: sha512-CGURX6Ps+TkOovK6xV+Y2rn8JKa8ZPUHPZ/NKgCxAmgBrXReavzFl8aOSCj3kQ1xqT7yGJj53hjcV/gqwDAaWA==}
|
||||
engines: {node: ^18.0.0 || >=20}
|
||||
peerDependencies:
|
||||
svelte: ^4.0.0 || ^5.0.0-next.0
|
||||
vite: ^5.0.0
|
||||
dependencies:
|
||||
'@sveltejs/vite-plugin-svelte-inspector': 2.0.0(@sveltejs/vite-plugin-svelte@3.0.0)(svelte@4.2.7)(vite@5.0.3)
|
||||
'@sveltejs/vite-plugin-svelte-inspector': 2.0.0(@sveltejs/vite-plugin-svelte@3.0.1)(svelte@4.2.8)(vite@5.0.11)
|
||||
debug: 4.3.4
|
||||
deepmerge: 4.3.1
|
||||
kleur: 4.1.5
|
||||
magic-string: 0.30.5
|
||||
svelte: 4.2.7
|
||||
svelte-hmr: 0.15.3(svelte@4.2.7)
|
||||
vite: 5.0.3
|
||||
vitefu: 0.2.5(vite@5.0.3)
|
||||
svelte: 4.2.8
|
||||
svelte-hmr: 0.15.3(svelte@4.2.8)
|
||||
vite: 5.0.11
|
||||
vitefu: 0.2.5(vite@5.0.11)
|
||||
transitivePeerDependencies:
|
||||
- supports-color
|
||||
dev: true
|
||||
|
@ -801,7 +802,7 @@ packages:
|
|||
eslint: 8.56.0
|
||||
dev: true
|
||||
|
||||
/eslint-plugin-svelte@2.35.1(eslint@8.56.0)(svelte@4.2.7):
|
||||
/eslint-plugin-svelte@2.35.1(eslint@8.56.0)(svelte@4.2.8):
|
||||
resolution: {integrity: sha512-IF8TpLnROSGy98Z3NrsKXWDSCbNY2ReHDcrYTuXZMbfX7VmESISR78TWgO9zdg4Dht1X8coub5jKwHzP0ExRug==}
|
||||
engines: {node: ^14.17.0 || >=16.0.0}
|
||||
peerDependencies:
|
||||
|
@ -823,8 +824,8 @@ packages:
|
|||
postcss-safe-parser: 6.0.0(postcss@8.4.33)
|
||||
postcss-selector-parser: 6.0.15
|
||||
semver: 7.5.4
|
||||
svelte: 4.2.7
|
||||
svelte-eslint-parser: 0.33.1(svelte@4.2.7)
|
||||
svelte: 4.2.8
|
||||
svelte-eslint-parser: 0.33.1(svelte@4.2.8)
|
||||
transitivePeerDependencies:
|
||||
- supports-color
|
||||
- ts-node
|
||||
|
@ -852,7 +853,7 @@ packages:
|
|||
'@eslint-community/regexpp': 4.10.0
|
||||
'@eslint/eslintrc': 2.1.4
|
||||
'@eslint/js': 8.56.0
|
||||
'@humanwhocodes/config-array': 0.11.13
|
||||
'@humanwhocodes/config-array': 0.11.14
|
||||
'@humanwhocodes/module-importer': 1.0.1
|
||||
'@nodelib/fs.walk': 1.2.8
|
||||
'@ungap/structured-clone': 1.2.0
|
||||
|
@ -1184,11 +1185,6 @@ packages:
|
|||
engines: {node: '>=4'}
|
||||
dev: true
|
||||
|
||||
/mrmime@1.0.1:
|
||||
resolution: {integrity: sha512-hzzEagAgDyoU1Q6yg5uI+AorQgdvMCur3FcKf7NhMKWsaYg+RnbTyHRa/9IlLF9rf455MOCtcqqrQQ83pPP7Uw==}
|
||||
engines: {node: '>=10'}
|
||||
dev: true
|
||||
|
||||
/mrmime@2.0.0:
|
||||
resolution: {integrity: sha512-eu38+hdgojoyq63s+yTpN4XMBdt5l8HhMhc4VKLO9KM5caLIBvUm4thi7fFaxyTmCKeNnXZ5pAlBwCUnhA09uw==}
|
||||
engines: {node: '>=10'}
|
||||
|
@ -1331,14 +1327,14 @@ packages:
|
|||
engines: {node: '>= 0.8.0'}
|
||||
dev: true
|
||||
|
||||
/prettier-plugin-svelte@3.1.2(prettier@3.1.1)(svelte@4.2.7):
|
||||
/prettier-plugin-svelte@3.1.2(prettier@3.1.1)(svelte@4.2.8):
|
||||
resolution: {integrity: sha512-7xfMZtwgAWHMT0iZc8jN4o65zgbAQ3+O32V6W7pXrqNvKnHnkoyQCGCbKeUyXKZLbYE0YhFRnamfxfkEGxm8qA==}
|
||||
peerDependencies:
|
||||
prettier: ^3.0.0
|
||||
svelte: ^3.2.0 || ^4.0.0-next.0 || ^5.0.0-next.0
|
||||
dependencies:
|
||||
prettier: 3.1.1
|
||||
svelte: 4.2.7
|
||||
svelte: 4.2.8
|
||||
dev: true
|
||||
|
||||
/prettier@3.1.1:
|
||||
|
@ -1466,7 +1462,7 @@ packages:
|
|||
has-flag: 4.0.0
|
||||
dev: true
|
||||
|
||||
/svelte-eslint-parser@0.33.1(svelte@4.2.7):
|
||||
/svelte-eslint-parser@0.33.1(svelte@4.2.8):
|
||||
resolution: {integrity: sha512-vo7xPGTlKBGdLH8T5L64FipvTrqv3OQRx9d2z5X05KKZDlF4rQk8KViZO4flKERY+5BiVdOh7zZ7JGJWo5P0uA==}
|
||||
engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0}
|
||||
peerDependencies:
|
||||
|
@ -1480,20 +1476,20 @@ packages:
|
|||
espree: 9.6.1
|
||||
postcss: 8.4.33
|
||||
postcss-scss: 4.0.9(postcss@8.4.33)
|
||||
svelte: 4.2.7
|
||||
svelte: 4.2.8
|
||||
dev: true
|
||||
|
||||
/svelte-hmr@0.15.3(svelte@4.2.7):
|
||||
/svelte-hmr@0.15.3(svelte@4.2.8):
|
||||
resolution: {integrity: sha512-41snaPswvSf8TJUhlkoJBekRrABDXDMdpNpT2tfHIv4JuhgvHqLMhEPGtaQn0BmbNSTkuz2Ed20DF2eHw0SmBQ==}
|
||||
engines: {node: ^12.20 || ^14.13.1 || >= 16}
|
||||
peerDependencies:
|
||||
svelte: ^3.19.0 || ^4.0.0
|
||||
dependencies:
|
||||
svelte: 4.2.7
|
||||
svelte: 4.2.8
|
||||
dev: true
|
||||
|
||||
/svelte@4.2.7:
|
||||
resolution: {integrity: sha512-UExR1KS7raTdycsUrKLtStayu4hpdV3VZQgM0akX8XbXgLBlosdE/Sf3crOgyh9xIjqSYB3UEBuUlIQKRQX2hg==}
|
||||
/svelte@4.2.8:
|
||||
resolution: {integrity: sha512-hU6dh1MPl8gh6klQZwK/n73GiAHiR95IkFsesLPbMeEZi36ydaXL/ZAb4g9sayT0MXzpxyZjR28yderJHxcmYA==}
|
||||
engines: {node: '>=16'}
|
||||
dependencies:
|
||||
'@ampproject/remapping': 2.2.1
|
||||
|
@ -1549,8 +1545,8 @@ packages:
|
|||
resolution: {integrity: sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==}
|
||||
dev: true
|
||||
|
||||
/vite@5.0.3:
|
||||
resolution: {integrity: sha512-WgEq8WEKpZ8c0DL4M1+E+kBZEJyjBmGVrul6z8Ljfhv+PPbNF4aGq014DwNYxGz2FGq6NKL0N8usdiESWd2l2w==}
|
||||
/vite@5.0.11:
|
||||
resolution: {integrity: sha512-XBMnDjZcNAw/G1gEiskiM1v6yzM4GE5aMGvhWTlHAYYhxb7S3/V1s3m2LDHa8Vh6yIWYYB0iJwsEaS523c4oYA==}
|
||||
engines: {node: ^18.0.0 || >=20.0.0}
|
||||
hasBin: true
|
||||
peerDependencies:
|
||||
|
@ -1584,7 +1580,7 @@ packages:
|
|||
fsevents: 2.3.3
|
||||
dev: true
|
||||
|
||||
/vitefu@0.2.5(vite@5.0.3):
|
||||
/vitefu@0.2.5(vite@5.0.11):
|
||||
resolution: {integrity: sha512-SgHtMLoqaeeGnd2evZ849ZbACbnwQCIwRH57t18FxcXoZop0uQu0uzlIhJBlF/eWVzuce0sHeqPcDo+evVcg8Q==}
|
||||
peerDependencies:
|
||||
vite: ^3.0.0 || ^4.0.0 || ^5.0.0
|
||||
|
@ -1592,7 +1588,7 @@ packages:
|
|||
vite:
|
||||
optional: true
|
||||
dependencies:
|
||||
vite: 5.0.3
|
||||
vite: 5.0.11
|
||||
dev: true
|
||||
|
||||
/which@2.0.2:
|
||||
|
|
|
@ -9,9 +9,16 @@
|
|||
console.log('Not dev mode');
|
||||
}
|
||||
|
||||
const events = ['priority'];
|
||||
|
||||
window.document.body.oncontextmenu = function () {
|
||||
return false;
|
||||
};
|
||||
|
||||
onMount(async () => {
|
||||
if (!dev) {
|
||||
const sse = StartSSE();
|
||||
LoadPriority();
|
||||
return sse;
|
||||
}
|
||||
});
|
||||
|
@ -26,22 +33,28 @@
|
|||
console.log(`subscribe: ${sse}`);
|
||||
|
||||
sse.onopen = () => {
|
||||
console.log(`sse open ${now()}`);
|
||||
console.log(`sse open ${Date.now()}`);
|
||||
};
|
||||
|
||||
sse.addEventListener('priority', (e) => {
|
||||
let Msg = JSON.parse(e.data);
|
||||
console.log(JSON.stringify(Msg));
|
||||
console.log(`surfers: ${Msg.data.surfers}`);
|
||||
$surfers = Msg.data.surfers;
|
||||
});
|
||||
|
||||
|
||||
return () => {
|
||||
sse.close();
|
||||
console.log(`sse closing ${Date.now()}`);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
async function LoadPriority() {
|
||||
const res = await fetch(`/api/priority`);
|
||||
const data = await res.json();
|
||||
console.log(`load priority: ${JSON.stringify(data)}`);
|
||||
$surfers = data.surfers;
|
||||
}
|
||||
</script>
|
||||
|
||||
<ul>
|
||||
|
@ -106,5 +119,4 @@
|
|||
.color {
|
||||
width: 100vw;
|
||||
}
|
||||
|
||||
</style>
|
||||
|
|
|
@ -10,46 +10,55 @@
|
|||
console.log('Not dev mode');
|
||||
}
|
||||
|
||||
// let surfers = [
|
||||
// { name: 'Kanoa Igarashi', color: 'red', score: '4.50', priority: '3' },
|
||||
// { name: 'Griffin Colapinto', color: 'white', score: '5.60', priority: 'P' },
|
||||
// { name: 'Jack Robinson', color: 'blue', score: '6.10', priority: '5' },
|
||||
// { name: 'Gabriel Medina', color: 'green', score: '4.30', priority: '2' },
|
||||
// { name: 'Italo Ferreira', color: 'black', score: '6.50', priority: '4' }
|
||||
// ];
|
||||
const events = ['priority'];
|
||||
|
||||
let width;
|
||||
// $: activeUrl = $page.url.pathname;
|
||||
|
||||
const pad2 = (number) => `00${number}`.slice(-2);
|
||||
|
||||
function Subscribe() {
|
||||
const sse = new EventSource(`/api/sse`);
|
||||
console.log('subscribe');
|
||||
sse.onmessage = (e) => {
|
||||
let Msg = JSON.parse(e.data);
|
||||
console.log(`received: ${JSON.stringify(Msg)}`);
|
||||
if (Msg.mode === 'priority') {
|
||||
console.log(`priority: ${Msg.priority}`);
|
||||
for (let i in surfers) {
|
||||
surfers[i].priority = Msg.priority[i];
|
||||
}
|
||||
}
|
||||
window.document.body.oncontextmenu = function () {
|
||||
return false;
|
||||
};
|
||||
|
||||
onMount(async () => {
|
||||
if (!dev) {
|
||||
const sse = StartSSE();
|
||||
LoadPriority();
|
||||
return sse;
|
||||
}
|
||||
});
|
||||
|
||||
function StartSSE() {
|
||||
let url = '/api/sse?';
|
||||
for (let e in events) {
|
||||
url += `event=${events[e]}&`;
|
||||
}
|
||||
console.log(`sse url: ${url}`);
|
||||
const sse = new EventSource(url);
|
||||
console.log(`subscribe: ${sse}`);
|
||||
|
||||
sse.onopen = () => {
|
||||
console.log(`sse open ${Date.now()}`);
|
||||
};
|
||||
|
||||
sse.addEventListener('priority', (e) => {
|
||||
let Msg = JSON.parse(e.data);
|
||||
console.log(JSON.stringify(Msg));
|
||||
console.log(`surfers: ${Msg.data.surfers}`);
|
||||
$surfers = Msg.data.surfers;
|
||||
});
|
||||
|
||||
return () => {
|
||||
sse.close();
|
||||
console.log(`sse closing ${Date.now()}`);
|
||||
};
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
const unsub = Subscribe();
|
||||
return unsub;
|
||||
});
|
||||
|
||||
async function LoadPriority() {
|
||||
const res = await fetch(`/api/priority`);
|
||||
const data = await res.json();
|
||||
console.log(`load priority: ${JSON.stringify(data)}`);
|
||||
$surfers = data.surfers;
|
||||
}
|
||||
</script>
|
||||
|
||||
<svelte:window bind:innerWidth={width} />
|
||||
<!-- <svelte:window bind:innerWidth={width} /> -->
|
||||
|
||||
<div class="header">
|
||||
<!-- <span class="title">{event}</span>
|
||||
|
@ -75,7 +84,6 @@
|
|||
{/each}
|
||||
</ul>
|
||||
|
||||
|
||||
<!-- {#if width < 768}
|
||||
<div class="footer">
|
||||
<div>waiting for scores</div> -->
|
||||
|
@ -152,5 +160,4 @@
|
|||
.color {
|
||||
width: 100vw;
|
||||
}
|
||||
|
||||
</style>
|
||||
|
|
|
@ -9,9 +9,16 @@
|
|||
console.log('Not dev mode');
|
||||
}
|
||||
|
||||
const events = ['priority'];
|
||||
|
||||
window.document.body.oncontextmenu = function () {
|
||||
return false;
|
||||
};
|
||||
|
||||
onMount(async () => {
|
||||
if (!dev) {
|
||||
const sse = StartSSE();
|
||||
LoadPriority();
|
||||
return sse;
|
||||
}
|
||||
});
|
||||
|
@ -26,21 +33,28 @@
|
|||
console.log(`subscribe: ${sse}`);
|
||||
|
||||
sse.onopen = () => {
|
||||
console.log(`sse open ${now()}`);
|
||||
console.log(`sse open ${Date.now()}`);
|
||||
};
|
||||
|
||||
sse.addEventListener('priority', (e) => {
|
||||
let Msg = JSON.parse(e.data);
|
||||
console.log(JSON.stringify(Msg));
|
||||
console.log(`surfers: ${Msg.data.surfers}`);
|
||||
$surfers = Msg.data.surfers;
|
||||
});
|
||||
|
||||
|
||||
return () => {
|
||||
sse.close();
|
||||
console.log(`sse closing ${Date.now()}`);
|
||||
};
|
||||
}
|
||||
|
||||
async function LoadPriority() {
|
||||
const res = await fetch(`/api/priority`);
|
||||
const data = await res.json();
|
||||
console.log(`load priority: ${JSON.stringify(data)}`);
|
||||
$surfers = data.surfers;
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="wall">
|
||||
|
@ -112,5 +126,4 @@
|
|||
.color {
|
||||
flex-grow: 1;
|
||||
}
|
||||
|
||||
</style>
|
||||
|
|
|
@ -10,13 +10,17 @@
|
|||
console.log('Not dev mode');
|
||||
}
|
||||
|
||||
window.document.body.oncontextmenu = function () {
|
||||
return false;
|
||||
};
|
||||
|
||||
const events = ['priority'];
|
||||
|
||||
$: start = false;
|
||||
// $: surfers_tot = 6;
|
||||
|
||||
let footer_height = 8;
|
||||
$: setup_height = ((100 - footer_height) / $surfersCount) - (2.2 / $surfersCount);
|
||||
$: setup_height = (100 - footer_height) / $surfersCount - 2.2 / $surfersCount;
|
||||
|
||||
$: if (start && $surfers) {
|
||||
window.sessionStorage.setItem('priority', JSON.stringify($surfers));
|
||||
|
@ -34,10 +38,10 @@
|
|||
console.log(`loaded: ${JSON.stringify($surfers)}`);
|
||||
}
|
||||
|
||||
if (!dev) {
|
||||
const sse = StartSSE();
|
||||
return sse;
|
||||
}
|
||||
// if (!dev) {
|
||||
// const sse = StartSSE();
|
||||
// return sse;
|
||||
// }
|
||||
});
|
||||
|
||||
function hasDuplicateColors() {
|
||||
|
@ -77,6 +81,8 @@
|
|||
function StopHeat() {
|
||||
window.sessionStorage.clear();
|
||||
start = false;
|
||||
ResetPriority();
|
||||
SendPriority();
|
||||
}
|
||||
|
||||
function AddSurfer() {
|
||||
|
@ -151,45 +157,55 @@
|
|||
}
|
||||
|
||||
if (!dev) {
|
||||
SendPriority();
|
||||
}
|
||||
}
|
||||
|
||||
async function SendPriority() {
|
||||
const res = await fetch(`/api/priority`, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
priority: $surfers.map((obj) => obj.priority)
|
||||
surfers: $surfers,
|
||||
count: $surfersCount
|
||||
}),
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
});
|
||||
console.log(`retval: ${JSON.stringify(res)}`);
|
||||
}
|
||||
}
|
||||
|
||||
function StartSSE() {
|
||||
let url = '/api/sse?';
|
||||
for (let e in events) {
|
||||
url += `event=${events[e]}&`;
|
||||
// function StartSSE() {
|
||||
// let url = '/api/sse?';
|
||||
// for (let e in events) {
|
||||
// url += `event=${events[e]}&`;
|
||||
// }
|
||||
// console.log(`sse url: ${url}`);
|
||||
// const sse = new EventSource(url);
|
||||
// console.log(`subscribe: ${sse}`);
|
||||
|
||||
// sse.onopen = () => {
|
||||
// console.log(`sse open ${now()}`);
|
||||
// };
|
||||
|
||||
// sse.addEventListener('priority', (e) => {
|
||||
// let Msg = JSON.parse(e.data);
|
||||
// console.log(JSON.stringify(Msg));
|
||||
// });
|
||||
|
||||
// return () => {
|
||||
// sse.close();
|
||||
// console.log(`sse closing ${Date.now()}`);
|
||||
// };
|
||||
// }
|
||||
|
||||
function DarkMode() {
|
||||
window.document.body.classList.toggle('dark-mode');
|
||||
if (window.document.body.style.backgroundColor === 'black') {
|
||||
window.document.body.style.backgroundColor = 'white';
|
||||
} else {
|
||||
window.document.body.style.backgroundColor = 'black';
|
||||
}
|
||||
console.log(`sse url: ${url}`);
|
||||
const sse = new EventSource(url);
|
||||
console.log(`subscribe: ${sse}`);
|
||||
|
||||
sse.onopen = () => {
|
||||
console.log(`sse open ${now()}`);
|
||||
};
|
||||
|
||||
sse.addEventListener('priority', (e) => {
|
||||
let Msg = JSON.parse(e.data);
|
||||
console.log(JSON.stringify(Msg));
|
||||
});
|
||||
|
||||
|
||||
return () => {
|
||||
sse.close();
|
||||
console.log(`sse closing ${Date.now()}`);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
{#if start}
|
||||
|
@ -197,12 +213,29 @@
|
|||
{#each Array($surfersCount) as _, id}
|
||||
<li style="--height:{setup_height}vh">
|
||||
{#if $surfers[id].priority == 'P'}
|
||||
<div class="priority" id="p" on:click={() => ChangePriority(id)} on:keypress={() => ChangePriority(id)} role="button" tabindex="-1">{$surfers[id].priority}</div>
|
||||
{:else}
|
||||
<div class="priority" id="n" on:click={() => ChangePriority(id)} on:keypress={() => ChangePriority(id)} role="button" tabindex="-1">{$surfers[id].priority}</div>
|
||||
{/if}
|
||||
<div class="color" style:background-color={$surfers[id].color}>
|
||||
<div
|
||||
class="priority"
|
||||
id="p"
|
||||
on:click={() => ChangePriority(id)}
|
||||
on:keypress={() => ChangePriority(id)}
|
||||
role="button"
|
||||
tabindex="-1"
|
||||
>
|
||||
{$surfers[id].priority}
|
||||
</div>
|
||||
{:else}
|
||||
<div
|
||||
class="priority"
|
||||
id="n"
|
||||
on:click={() => ChangePriority(id)}
|
||||
on:keypress={() => ChangePriority(id)}
|
||||
role="button"
|
||||
tabindex="-1"
|
||||
>
|
||||
{$surfers[id].priority}
|
||||
</div>
|
||||
{/if}
|
||||
<div class="color" style:background-color={$surfers[id].color}></div>
|
||||
</li>
|
||||
{/each}
|
||||
</ul>
|
||||
|
@ -214,9 +247,14 @@
|
|||
{#each Array($surfersCount) as _, id}
|
||||
<li style="--height:{setup_height}vh">
|
||||
<div class="priority" id="color">
|
||||
<select name="color{id}" id="{id}" bind:value={$surfers[id].color} style="background-color: {$surfers[id].color};">
|
||||
<select
|
||||
name="color{id}"
|
||||
{id}
|
||||
bind:value={$surfers[id].color}
|
||||
style="background-color: {$surfers[id].color};"
|
||||
>
|
||||
{#each $colors as color}
|
||||
<option value="{color}" style="background-color: {color}"></option>
|
||||
<option value={color} style="background-color: {color}"></option>
|
||||
{/each}
|
||||
</select>
|
||||
</div>
|
||||
|
@ -224,7 +262,16 @@
|
|||
</li>
|
||||
{/each}
|
||||
</ul>
|
||||
<div class="footer" style="--height:{footer_height}vh">
|
||||
<div
|
||||
class="footer"
|
||||
style="--height:{footer_height}vh"
|
||||
on:contextmenu={(e) => {
|
||||
e.preventDefault();
|
||||
DarkMode();
|
||||
}}
|
||||
role="button"
|
||||
tabindex="-1"
|
||||
>
|
||||
<div class="control">
|
||||
<button class="button" on:click={AddSurfer}>+</button>
|
||||
<button class="display">{$surfersCount}</button>
|
||||
|
|
Loading…
Add table
Reference in a new issue