加入10s心跳
This commit is contained in:
parent
c369404e28
commit
b20e67b951
@ -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) {
|
||||
|
||||
11
main.go
11
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)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user