From b20e67b951845b2f9130127e039a75093dc01163 Mon Sep 17 00:00:00 2001 From: srcrs Date: Wed, 2 Aug 2023 01:46:57 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A0=E5=85=A510s=E5=BF=83=E8=B7=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.html | 4 ++++ main.go | 11 +++++++++++ 2 files changed, 15 insertions(+) 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)