diff --git a/index.html b/index.html index ce9df4b..e3c1cc6 100644 --- a/index.html +++ b/index.html @@ -113,6 +113,10 @@ const protocol = window.location.protocol === 'https:' ? 'wss://' : 'ws://'; const socket = new WebSocket(protocol + window.location.host + "/ws"); socket.onmessage = event => { + if (event.data === 'heartbeat') { + // 心跳消息,忽略处理 + return; + } const feed = JSON.parse(event.data); const existingFeed = this.feeds.find(f => f.link === feed.link); if (existingFeed) { diff --git a/main.go b/main.go index d129695..5d45dc5 100644 --- a/main.go +++ b/main.go @@ -72,6 +72,17 @@ func wsHandler(w http.ResponseWriter, r *http.Request) { return } defer conn.Close() + if rssUrls.AutoUpdatePush > 0 { + go func() { + for { + if err := conn.WriteMessage(websocket.TextMessage, []byte("heartbeat")); err != nil { + log.Printf("heartbeat Write error: %v", err) + return + } + time.Sleep(time.Duration(10) * time.Second) + } + }() + } for { for _, url := range rssUrls.Values { feedJSON, err := get(url)