Browse Source

heartbeat

andy 1 year ago
parent
commit
0edb1e375b
2 changed files with 12 additions and 0 deletions
  1. 8 0
      App.vue
  2. 4 0
      server.js

+ 8 - 0
App.vue

@@ -9,12 +9,20 @@ export default {
     console.log('App Show')
     console.log(this.$fileBasUrl, 'appppp$fileBasUrl')
     this.connectSocket()
+
+    this.timer = setInterval(() => {
+      wx.request({
+        url: 'http://192.168.0.109:3000/heartbeat?userId=' + wx.getStorageSync('userId'),
+      })
+    }, 5000)
+
     // uni.hideTabBar()
   },
   onHide: function () {
     console.log('App Hide')
     // close socket
     wx.closeSocket()
+    clearInterval(this.timer)
   },
   globalData: {
     fileBasUrl: 'https://mall.rongtongh.cn/storage/img',

+ 4 - 0
server.js

@@ -23,6 +23,10 @@ wss.on('connection', ws => {
   })
 })
 
+app.get('/heartbeat', (req, res) => {
+  console.log('Heartbeat', req.query)
+})
+
 // 每隔5秒打印在线用户
 setInterval(() => {
   console.log(new Date())