Explorar el Código

websocket 连接时根据 http 协议选择 ws 或 wss 前缀

reghao hace 1 año
padre
commit
7229846776
Se han modificado 2 ficheros con 12 adiciones y 3 borrados
  1. 10 1
      src/utils/ws/socket-instance.js
  2. 2 2
      src/views/user/Home.vue

+ 10 - 1
src/utils/ws/socket-instance.js

@@ -19,8 +19,17 @@ class SocketInstance {
   constructor() {
     this.socket = new WsSocket(
       () => {
+        const protocol = location.protocol
+        let prefix
+        if (protocol === 'https') {
+          prefix = 'wss://'
+        } else {
+          prefix = 'ws://'
+        }
+
         const token = getAccessToken()
-        var url = 'wss:' + process.env.VUE_APP_SERVER_URL + '/ws/progress?token=' + token
+        // var url = 'wss:' + process.env.VUE_APP_SERVER_URL + '/ws/progress?token=' + token
+        const url = prefix + process.env.VUE_APP_SERVER_URL + '/ws/progress?token=' + token
         return url
       },
       {

+ 2 - 2
src/views/user/Home.vue

@@ -85,7 +85,7 @@
               </el-col>
             </div>
           </el-tab-pane>
-          <el-tab-pane name="audio">
+<!--          <el-tab-pane name="audio">
             <span slot="label">
               音频<el-badge :value="userContentData.audioCount" :max="9999" class="item" type="warning" />
             </span>
@@ -104,7 +104,7 @@
                 <article-card :article="article" />
               </el-col>
             </div>
-          </el-tab-pane>
+          </el-tab-pane>-->
           <!--          <el-tab-pane name="status">
             <span slot="label">
               状态<el-badge :value="userContentData.statusCount" :max="9999" class="item" type="warning"/>