diff --git a/application/source/server/inject.go b/application/source/server/inject.go index dbd8bb83a805e19616f57d5ad791d17c967546fa..dfa594a4de4c36e6aa3b685a61f0335c17b31e7a 100644 --- a/application/source/server/inject.go +++ b/application/source/server/inject.go @@ -54,6 +54,7 @@ func init() { <script type="module"> try { + let died = false; let counter = 0; let socket let url = "" @@ -79,6 +80,11 @@ func init() { socket = new WebSocket(url) socket.onopen = function (e) { + + if (died===true ){ + window.location.reload(); + } + console.log("[conan] Connection established"); counter = 0 }; @@ -97,12 +103,13 @@ func init() { console.log("[conan] Connection closed cleanly, code=" + event?.code + " reason=" + event?.reason + ""); } else { console.error("[conan] Connection died"); + died = true setTimeout(connectWebsocket, 3000*counter) } }; socket.onerror = function (error) { - console.error("[conan] " + error?.message); + console.error("[conan] error", error); }; } diff --git a/application/source/watch/resources.go b/application/source/watch/resources.go index e004f0652f99ac2c80cc1175ad66772cab28e2a0..340b476b28e94f4e27befc971824752dc5691f0d 100644 --- a/application/source/watch/resources.go +++ b/application/source/watch/resources.go @@ -116,8 +116,6 @@ func executeWatchAction(watchPath string) { r, err := result.String() logging.LogDebug("%s", r) - websocket.SendReloadMessage() - if err != nil { logging.LogError("watching: execute watch action error: %v", err.Error()) continue @@ -201,9 +199,13 @@ func InitWatch() { }) } - watchList = append(watchList, configuration.Watch{ - Path: path.Join(configuration.GetConfigurationPath(), constants.ConfigFileName), - }) + c := path.Join(configuration.GetConfigurationPath(), constants.ConfigFileName) + + if _, err := os.Stat(c); err == nil { + watchList = append(watchList, configuration.Watch{ + Path: path.Join(configuration.GetConfigurationPath(), constants.ConfigFileName), + }) + } for _, w := range watchList { scanPath(w.Path) diff --git a/application/source/websocket/connection.go b/application/source/websocket/connection.go index 52d61276407179c10878e2863425a03a8e58b659..a079fc614478a026dc6560eed143b5e94fcb84b1 100644 --- a/application/source/websocket/connection.go +++ b/application/source/websocket/connection.go @@ -6,6 +6,8 @@ import ( "gitlab.schukai.com/oss/utilities/conan/logging" "log" "net/http" + "sync" + "time" ) var ( @@ -14,7 +16,7 @@ var ( ) func SendMessageToAll(message []byte) { - + logging.LogInfo("sending message to all") for _, conn := range connections { conn.WriteMessage(websocket.TextMessage, message) } @@ -30,8 +32,35 @@ func closeConnection(session string) error { return nil } -func SendReloadMessage() { +var timerMutex *sync.Mutex +var waitForReload bool + +func init() { + timerMutex = &sync.Mutex{} + waitForReload = false +} + +func doReload() { + timerMutex.Lock() + defer timerMutex.Unlock() + SendMessageToAll([]byte("reload")) + waitForReload = false +} + +func SendReloadMessage() { + + timerMutex.Lock() + defer timerMutex.Unlock() + + if waitForReload { + return + } + + time.AfterFunc(time.Second*2, doReload) + logging.LogInfo("timer ...") + waitForReload = true + } func GetWebsocketHandler() http.Handler { @@ -49,7 +78,6 @@ func GetWebsocketHandler() http.Handler { conn.SetCloseHandler(func(code int, text string) error { return closeConnection(session) - }) connections[session] = conn diff --git a/development/examples/e1/web/hello.html b/development/examples/e1/web/hello.html index 7c0da150b253c95623b1b6d9ad2964037b6351ca..b26c12f5c6cf7b11b5610db2d512017aade16812 100644 --- a/development/examples/e1/web/hello.html +++ b/development/examples/e1/web/hello.html @@ -7,6 +7,9 @@ </head> <body> <h1>Hello ...ddd</h1> - <div id="app"></div> </body> +1 +1 +1 +1 diff --git a/release.json b/release.json index 0bea138f6c32e41d798596f3a9f3f999bfa301bd..72d452f8176370572efafc7b2a59a656b0a64a48 100644 --- a/release.json +++ b/release.json @@ -1 +1 @@ -{"version":"0.1.19"} +{"version":"0.1.29"}