<template>
  <div id="app">
    <router-view/>
  </div>
</template>

<script>
export default {
  name: 'App',
  methods:{
    localSocket() {
      let that = this;
      if ("WebSocket" in window) {
        console.log("您的浏览器支持 WebSocket!");
        that.ws = new WebSocket(`ws:http://132.232.92.186:8888/api/chatHub`);
        that.$websocket.setWs(that.ws);
        that.ws.onopen = function() {
          console.log('开始连接')
          that.$websocket.ws.send('给后端必要的参数')
        };
        that.ws.onclose = function() {
          // 防链接超时，（websocket在一定时间内没有数据交互，就会断开），关闭后重启
          console.log("连接已关闭...");
          setTimeout(() => {
            that.localSocket();
          }, 2000);
        };
      } else {
        // 浏览器不支持 WebSocket
        console.log("您的浏览器不支持 WebSocket!");
      }
    }
  },
  created() {
    //websocket
    // this.localSocket()
  },
  mounted(){
    console.log(this.$route.meta.keepAlive==undefined);
  }
}
</script>

<style>
#app {
  margin: 0px;
  padding: 0px;
  font-family:"微软雅黑";
}
</style>
