浏览代码

feat(socket-v4): update socket-v4

gemercheung 3 年之前
父节点
当前提交
d84f7194a0
共有 6 个文件被更改,包括 332 次插入315 次删除
  1. 1 1
      config.js
  2. 1 1
      pages/webview/index.js
  3. 256 256
      project.config.json
  4. 10 0
      socket.io-v4.js
  5. 63 56
      socket.js
  6. 1 1
      utils/util.js

+ 1 - 1
config.js

@@ -14,7 +14,7 @@ const dev = {
 //目前没有区分正式服测试服
 const mal = {
   env: 'pro',
-  socketHost: 'wss://shop.4dkankan.com',
+  socketHost: 'wss://test-socket.4dkankan.com',
   // socketHost: 'wss://192.168.0.79:3031',
   requestHost: 'https://plaza-cszfb.4dkankan.com', // 测试环境
   viewChildHost: 'https://cszfb.4dkankan.com', //测试环境

+ 1 - 1
pages/webview/index.js

@@ -233,7 +233,7 @@ Page({
     } else if (this.token !== wx.getStorageSync('token')) {
       if (this.data.join) {
         let res = await util.request(api.UserInfo)
-        if (res.errno === 401) {
+        if (res.code === 401) {
           return getApp().setLoginProps(false)
         }
       }

+ 256 - 256
project.config.json

@@ -1,266 +1,266 @@
 {
-    "description": "项目配置文件。",
-    "setting": {
-        "urlCheck": false,
-        "es6": true,
-        "enhance": true,
-        "postcss": true,
-        "preloadBackgroundData": false,
-        "minified": true,
-        "newFeature": true,
-        "coverView": true,
-        "nodeModules": false,
-        "autoAudits": false,
-        "showShadowRootInWxmlPanel": true,
-        "scopeDataCheck": false,
-        "uglifyFileName": false,
-        "checkInvalidKey": true,
-        "checkSiteMap": true,
-        "uploadWithSourceMap": true,
-        "compileHotReLoad": false,
-        "lazyloadPlaceholderEnable": false,
-        "useMultiFrameRuntime": true,
-        "useApiHook": true,
-        "useApiHostProcess": true,
-        "babelSetting": {
-            "ignore": [],
-            "disablePlugins": [],
-            "outputPath": ""
-        },
-        "enableEngineNative": false,
-        "useIsolateContext": true,
-        "userConfirmedBundleSwitch": false,
-        "packNpmManually": false,
-        "packNpmRelationList": [],
-        "minifyWXSS": true,
-        "disableUseStrict": false,
-        "minifyWXML": true,
-        "showES6CompileOption": false,
-        "useCompilerPlugins": false
+  "description": "项目配置文件。",
+  "setting": {
+    "urlCheck": false,
+    "es6": true,
+    "enhance": true,
+    "postcss": true,
+    "preloadBackgroundData": false,
+    "minified": true,
+    "newFeature": true,
+    "coverView": true,
+    "nodeModules": false,
+    "autoAudits": false,
+    "showShadowRootInWxmlPanel": true,
+    "scopeDataCheck": false,
+    "uglifyFileName": false,
+    "checkInvalidKey": true,
+    "checkSiteMap": true,
+    "uploadWithSourceMap": true,
+    "compileHotReLoad": false,
+    "lazyloadPlaceholderEnable": false,
+    "useMultiFrameRuntime": true,
+    "useApiHook": true,
+    "useApiHostProcess": true,
+    "babelSetting": {
+      "ignore": [],
+      "disablePlugins": [],
+      "outputPath": ""
+    },
+    "enableEngineNative": false,
+    "useIsolateContext": false,
+    "userConfirmedBundleSwitch": false,
+    "packNpmManually": false,
+    "packNpmRelationList": [],
+    "minifyWXSS": true,
+    "disableUseStrict": false,
+    "minifyWXML": true,
+    "showES6CompileOption": false,
+    "useCompilerPlugins": false
+  },
+  "compileType": "miniprogram",
+  "libVersion": "2.19.3",
+  "appid": "wx564b12f68f5e4feb",
+  "projectname": "FDshop",
+  "simulatorType": "wechat",
+  "simulatorPluginLibVersion": {},
+  "condition": {
+    "search": {
+      "list": []
+    },
+    "conversation": {
+      "list": []
+    },
+    "plugin": {
+      "list": []
     },
-    "compileType": "miniprogram",
-    "libVersion": "2.19.3",
-    "appid": "wx564b12f68f5e4feb",
-    "projectname": "FDshop",
-    "simulatorType": "wechat",
-    "simulatorPluginLibVersion": {},
-    "condition": {
-        "search": {
-            "list": []
+    "game": {
+      "list": []
+    },
+    "gamePlugin": {
+      "list": []
+    },
+    "miniprogram": {
+      "list": [
+        {
+          "id": 0,
+          "name": "选择优惠券",
+          "pathName": "pages/shopping/selCoupon/selCoupon",
+          "query": "isBuy=false"
+        },
+        {
+          "id": -1,
+          "name": "订单界面",
+          "pathName": "pages/shopping/checkout/checkout",
+          "query": "isBuy=true"
+        },
+        {
+          "id": -1,
+          "name": "我的优惠券",
+          "pathName": "pages/ucenter/coupon/coupon",
+          "query": "isBuy=true"
+        },
+        {
+          "id": -1,
+          "name": "我的订单",
+          "pathName": "pages/ucenter/order/order",
+          "query": ""
+        },
+        {
+          "id": 4,
+          "name": "pages/goods/goods",
+          "pathName": "pages/goods/goods",
+          "query": "id=1181015",
+          "scene": null
+        },
+        {
+          "id": -1,
+          "name": "pages/ucenter/index/index",
+          "pathName": "pages/ucenter/index/index",
+          "query": "",
+          "scene": null
+        },
+        {
+          "id": -1,
+          "name": "pages/cart/cart",
+          "pathName": "pages/cart/cart",
+          "query": "id=1181015",
+          "scene": null
+        },
+        {
+          "id": -1,
+          "name": "pages/catalog/catalog",
+          "pathName": "pages/catalog/catalog",
+          "query": "id=1181015",
+          "scene": null
+        },
+        {
+          "id": -1,
+          "name": "pages/category/category",
+          "pathName": "pages/category/category",
+          "query": "id=1036009",
+          "scene": null
+        },
+        {
+          "id": -1,
+          "name": "pages/ucenter/orderDetail/orderDetail",
+          "pathName": "pages/ucenter/orderDetail/orderDetail",
+          "query": "id=142",
+          "scene": null
+        },
+        {
+          "id": 10,
+          "name": "pages/payResult/payResult",
+          "pathName": "pages/payResult/payResult",
+          "query": "status=1",
+          "scene": null
+        },
+        {
+          "id": -1,
+          "name": "pages/cart/cart",
+          "pathName": "pages/cart/cart",
+          "query": "",
+          "scene": null
+        },
+        {
+          "id": 12,
+          "name": "pages/ucenter/addressAdd/addressAdd",
+          "pathName": "pages/ucenter/addressAdd/addressAdd",
+          "query": "",
+          "scene": null
+        },
+        {
+          "id": -1,
+          "name": "pages/logistics/index",
+          "pathName": "pages/logistics/index",
+          "query": "no=75326914125277&id=157",
+          "scene": null
+        },
+        {
+          "id": 14,
+          "name": "pages/ucenter/order/order",
+          "pathName": "pages/ucenter/order/order",
+          "query": "",
+          "scene": null
+        },
+        {
+          "id": -1,
+          "name": "pages/ucenter/feedback/feedback",
+          "pathName": "pages/ucenter/feedback/feedback",
+          "query": "",
+          "scene": null
+        },
+        {
+          "id": -1,
+          "name": "pages/ucenter/feedback/feedback",
+          "pathName": "pages/ucenter/feedback/feedback",
+          "query": "",
+          "scene": null
+        },
+        {
+          "id": -1,
+          "name": "pages/shopping/checkout/checkout",
+          "pathName": "pages/shopping/checkout/checkout",
+          "query": "",
+          "scene": null
+        },
+        {
+          "id": -1,
+          "name": "pages/ucenter/address/address",
+          "pathName": "pages/ucenter/address/address",
+          "query": "",
+          "scene": null
+        },
+        {
+          "id": -1,
+          "name": "pages/shopping/address/address",
+          "pathName": "pages/shopping/address/address",
+          "query": "",
+          "scene": null
+        },
+        {
+          "id": -1,
+          "name": "pages/shopping/address/address",
+          "pathName": "pages/shopping/address/address",
+          "query": "",
+          "scene": null
+        },
+        {
+          "id": -1,
+          "name": "pages/search/search",
+          "pathName": "pages/search/search",
+          "query": "",
+          "scene": null
+        },
+        {
+          "id": -1,
+          "name": "pages/webview/index",
+          "pathName": "pages/webview/index",
+          "query": "url=gu6HmTLKp",
+          "scene": null
+        },
+        {
+          "id": -1,
+          "name": "pages/auth/btnAuth/btnAuth",
+          "pathName": "pages/auth/btnAuth/btnAuth",
+          "query": "",
+          "scene": null
         },
-        "conversation": {
-            "list": []
+        {
+          "id": -1,
+          "name": "pages/brandDetail/brandDetail",
+          "pathName": "pages/brandDetail/brandDetail",
+          "query": "id=1046017",
+          "scene": null
         },
-        "plugin": {
-            "list": []
+        {
+          "id": 25,
+          "name": "pages/ucenter/orderDetail/orderDetail",
+          "pathName": "pages/ucenter/orderDetail/orderDetail",
+          "query": "id=412",
+          "scene": null
         },
-        "game": {
-            "list": []
+        {
+          "id": -1,
+          "name": "pages/webview/index",
+          "pathName": "pages/webview/index",
+          "query": "",
+          "scene": null
         },
-        "gamePlugin": {
-            "list": []
+        {
+          "id": -1,
+          "name": "dataReport/pages/data-report/data-report",
+          "pathName": "dataReport/pages/data-report/data-report",
+          "query": "",
+          "scene": null
         },
-        "miniprogram": {
-            "list": [
-                {
-                    "id": 0,
-                    "name": "选择优惠券",
-                    "pathName": "pages/shopping/selCoupon/selCoupon",
-                    "query": "isBuy=false"
-                },
-                {
-                    "id": -1,
-                    "name": "订单界面",
-                    "pathName": "pages/shopping/checkout/checkout",
-                    "query": "isBuy=true"
-                },
-                {
-                    "id": -1,
-                    "name": "我的优惠券",
-                    "pathName": "pages/ucenter/coupon/coupon",
-                    "query": "isBuy=true"
-                },
-                {
-                    "id": -1,
-                    "name": "我的订单",
-                    "pathName": "pages/ucenter/order/order",
-                    "query": ""
-                },
-                {
-                    "id": 4,
-                    "name": "pages/goods/goods",
-                    "pathName": "pages/goods/goods",
-                    "query": "id=1181015",
-                    "scene": null
-                },
-                {
-                    "id": -1,
-                    "name": "pages/ucenter/index/index",
-                    "pathName": "pages/ucenter/index/index",
-                    "query": "",
-                    "scene": null
-                },
-                {
-                    "id": -1,
-                    "name": "pages/cart/cart",
-                    "pathName": "pages/cart/cart",
-                    "query": "id=1181015",
-                    "scene": null
-                },
-                {
-                    "id": -1,
-                    "name": "pages/catalog/catalog",
-                    "pathName": "pages/catalog/catalog",
-                    "query": "id=1181015",
-                    "scene": null
-                },
-                {
-                    "id": -1,
-                    "name": "pages/category/category",
-                    "pathName": "pages/category/category",
-                    "query": "id=1036009",
-                    "scene": null
-                },
-                {
-                    "id": -1,
-                    "name": "pages/ucenter/orderDetail/orderDetail",
-                    "pathName": "pages/ucenter/orderDetail/orderDetail",
-                    "query": "id=142",
-                    "scene": null
-                },
-                {
-                    "id": 10,
-                    "name": "pages/payResult/payResult",
-                    "pathName": "pages/payResult/payResult",
-                    "query": "status=1",
-                    "scene": null
-                },
-                {
-                    "id": -1,
-                    "name": "pages/cart/cart",
-                    "pathName": "pages/cart/cart",
-                    "query": "",
-                    "scene": null
-                },
-                {
-                    "id": 12,
-                    "name": "pages/ucenter/addressAdd/addressAdd",
-                    "pathName": "pages/ucenter/addressAdd/addressAdd",
-                    "query": "",
-                    "scene": null
-                },
-                {
-                    "id": -1,
-                    "name": "pages/logistics/index",
-                    "pathName": "pages/logistics/index",
-                    "query": "no=75326914125277&id=157",
-                    "scene": null
-                },
-                {
-                    "id": 14,
-                    "name": "pages/ucenter/order/order",
-                    "pathName": "pages/ucenter/order/order",
-                    "query": "",
-                    "scene": null
-                },
-                {
-                    "id": -1,
-                    "name": "pages/ucenter/feedback/feedback",
-                    "pathName": "pages/ucenter/feedback/feedback",
-                    "query": "",
-                    "scene": null
-                },
-                {
-                    "id": -1,
-                    "name": "pages/ucenter/feedback/feedback",
-                    "pathName": "pages/ucenter/feedback/feedback",
-                    "query": "",
-                    "scene": null
-                },
-                {
-                    "id": -1,
-                    "name": "pages/shopping/checkout/checkout",
-                    "pathName": "pages/shopping/checkout/checkout",
-                    "query": "",
-                    "scene": null
-                },
-                {
-                    "id": -1,
-                    "name": "pages/ucenter/address/address",
-                    "pathName": "pages/ucenter/address/address",
-                    "query": "",
-                    "scene": null
-                },
-                {
-                    "id": -1,
-                    "name": "pages/shopping/address/address",
-                    "pathName": "pages/shopping/address/address",
-                    "query": "",
-                    "scene": null
-                },
-                {
-                    "id": -1,
-                    "name": "pages/shopping/address/address",
-                    "pathName": "pages/shopping/address/address",
-                    "query": "",
-                    "scene": null
-                },
-                {
-                    "id": -1,
-                    "name": "pages/search/search",
-                    "pathName": "pages/search/search",
-                    "query": "",
-                    "scene": null
-                },
-                {
-                    "id": -1,
-                    "name": "pages/webview/index",
-                    "pathName": "pages/webview/index",
-                    "query": "url=gu6HmTLKp",
-                    "scene": null
-                },
-                {
-                    "id": -1,
-                    "name": "pages/auth/btnAuth/btnAuth",
-                    "pathName": "pages/auth/btnAuth/btnAuth",
-                    "query": "",
-                    "scene": null
-                },
-                {
-                    "id": -1,
-                    "name": "pages/brandDetail/brandDetail",
-                    "pathName": "pages/brandDetail/brandDetail",
-                    "query": "id=1046017",
-                    "scene": null
-                },
-                {
-                    "id": 25,
-                    "name": "pages/ucenter/orderDetail/orderDetail",
-                    "pathName": "pages/ucenter/orderDetail/orderDetail",
-                    "query": "id=412",
-                    "scene": null
-                },
-                {
-                    "id": -1,
-                    "name": "pages/webview/index",
-                    "pathName": "pages/webview/index",
-                    "query": "",
-                    "scene": null
-                },
-                {
-                    "id": -1,
-                    "name": "dataReport/pages/data-report/data-report",
-                    "pathName": "dataReport/pages/data-report/data-report",
-                    "query": "",
-                    "scene": null
-                },
-                {
-                    "id": -1,
-                    "name": "首页",
-                    "pathName": "pages/index/index",
-                    "scene": null
-                }
-            ]
+        {
+          "id": -1,
+          "name": "首页",
+          "pathName": "pages/index/index",
+          "scene": null
         }
+      ]
     }
+  }
 }

文件差异内容过多而无法显示
+ 10 - 0
socket.io-v4.js


+ 63 - 56
socket.js

@@ -1,4 +1,7 @@
-const io = require('./socket.io-mp')
+// const io = require('./socket.io-mp');
+const {
+  io
+} = require('./socket.io-v4')
 var user = require('./services/user.js');
 const api = require('/config/api.js');
 const util = require('/utils/util.js');
@@ -68,12 +71,12 @@ export default {
     let hostUrl
     if (options.url.indexOf('www.4dkankan.com') != -1) {
       hostUrl = 'https://www.4dkankan.com/shop-container-zfb/'
-    } else if(options.url.indexOf('test.4dkankan.com') != -1){
+    } else if (options.url.indexOf('test.4dkankan.com') != -1) {
       hostUrl = 'https://test.4dkankan.com/shop-container-zfb/'
-    }else
-    {
+    } else {
       // hostUrl = 'https://zfb.4dkankan.com/shop-container/'
-      hostUrl = remote.viewHost+'/shop-container/'
+      hostUrl = remote.viewHost + '/shop-container-v4/';
+      // hostUrl = remote.viewHost + '/test-gemer/';
     }
     // let base = remote.viewHost + '/shop-container/fashilong.html?env=' + remote.env + '&sponsor=' + sponsor + '&many=' + this.data.many
     let base = hostUrl + 'fashilong.html?time=' + Date.now() + '&env=' + remote.env + '&sponsor=' + sponsor + '&many=' + this.data.many
@@ -165,7 +168,7 @@ export default {
   async agetUserInfo() {
     const res = await util.request(api.UserInfo)
 
-    if (res.errno === 401) {
+    if (res.code === 401) {
       return {
         userId: UNLOGIN,
         avatar: ''
@@ -264,7 +267,7 @@ export default {
     // wx.showToast({
     //   title: this.data.peopleCount.toString(),
     // })
-   
+
     return {
       role: this.role || 'leader',
       userId: userInfo.userId,
@@ -292,9 +295,11 @@ export default {
     console.log('小程序参数', options)
     let socket = io(remote.socketHost, {
       path: '/fsl-node',
+      transport:['websocket'],
       query: {
         ...options,
-        isClient: true
+        isClient: true,
+        from: 1
       }
     })
 
@@ -341,12 +346,12 @@ export default {
       let enableTalk = config.roomsConfig.enableTalk !== false
       let noMute = getApp().globalData.voiceProps.noMute
       getApp().globalData.voiceProps.force = enableTalk
-     
+
       if (!enableTalk && !noMute) {
         if (this.role !== 'leader') {
           // this.mic()
         }
-       
+
       }
     })
 
@@ -500,50 +505,50 @@ export default {
 
   async startCall(data) {
     // if( this.role =='leader'){
-      this.setData({
-        shareStatus: 1
-      })
-      if (!data) return;
-  
-      this.setData({
-        surplus: this.data.peopleCount - data.roomsPerson.length
-      })
-      if (!this.isAuthorizeRecord) {
-        const voiceStatus = Number(await this.authorizeRecord())
-        this.isAuthorizeRecord = true
-  
-        // getApp().setVoiceProps({
-        //   noMute: !voiceStatus
-        // })
-  
-        // console.log(getApp().globalData.voiceProps.noMute)
-        // this.socketSendMessage('changeVoiceStatus', {
-        //   status: getApp().globalData.voiceProps.noMute ? 0 : 2
-        // })
-        // this.data.socketOptions.voiceStatus = 1
-        // this.socketSendMessage('changeVoiceStatus', {status: noMute ? 0 : 2})
-      }
-  
-      const socketOptions = this.data.socketOptions
-      getApp().globalData.roomId = socketOptions.roomId
-      const user = data.roomsPerson.find(user => user.userId == socketOptions.userId)
-      if (!user) {
-        return
-      }
-      //屏蔽有人进来才开麦克风
-      // if (data.roomsPerson.length <= 1) {
-      //   return
-      // }
-      user.noMute = getApp().globalData.voiceProps.noMute
-      getApp().setVoiceProps({
-        ...user,
-        action: 'startCall'
-      })
+    this.setData({
+      shareStatus: 1
+    })
+    if (!data) return;
+
+    this.setData({
+      surplus: this.data.peopleCount - data.roomsPerson.length
+    })
+    if (!this.isAuthorizeRecord) {
+      const voiceStatus = Number(await this.authorizeRecord())
+      this.isAuthorizeRecord = true
+
+      // getApp().setVoiceProps({
+      //   noMute: !voiceStatus
+      // })
+
+      // console.log(getApp().globalData.voiceProps.noMute)
       // this.socketSendMessage('changeVoiceStatus', {
       //   status: getApp().globalData.voiceProps.noMute ? 0 : 2
       // })
+      // this.data.socketOptions.voiceStatus = 1
+      // this.socketSendMessage('changeVoiceStatus', {status: noMute ? 0 : 2})
+    }
+
+    const socketOptions = this.data.socketOptions
+    getApp().globalData.roomId = socketOptions.roomId
+    const user = data.roomsPerson.find(user => user.userId == socketOptions.userId)
+    if (!user) {
+      return
+    }
+    //屏蔽有人进来才开麦克风
+    // if (data.roomsPerson.length <= 1) {
+    //   return
     // }
-    
+    user.noMute = getApp().globalData.voiceProps.noMute
+    getApp().setVoiceProps({
+      ...user,
+      action: 'startCall'
+    })
+    // this.socketSendMessage('changeVoiceStatus', {
+    //   status: getApp().globalData.voiceProps.noMute ? 0 : 2
+    // })
+    // }
+
   },
 
   stopCall() {
@@ -594,7 +599,7 @@ export default {
       this.wssSuccess = false
       this.socketStop && this.socketStop()
       this.data.many = !!this.data.canShow
-     
+
       this.setData({
         // peopleCount: this.data.many ? manyCount : 5
         peopleCount: this.data.many ? manyCount : 2
@@ -658,7 +663,7 @@ export default {
   },
 
   async mic() {
-    
+
     let noMute = getApp().globalData.voiceProps.noMute
 
 
@@ -712,7 +717,7 @@ export default {
       newPicUrl
     } = this.data
 
-   
+
     if (res.from === 'button') {
       this.setData({
         sendShare: false
@@ -921,8 +926,10 @@ export default {
 
   async getCouponList(id) {
     const success = (res) => {
+    
+      const data = res.data || res.message 
       this.setData({
-        coupons: res.data.list.map(item => {
+        coupons: data.list.map(item => {
           item.typeMoney = item.typeMoney.toString()
           item.fontSize = item.typeMoney.length === 3 ? '90rpx' :
             item.typeMoney.length === 4 ? '70rpx' : '130rpx'
@@ -1108,11 +1115,11 @@ export default {
           contractPhone: res.data.brand.contractPhone
 
         })
-     
+
         if (this.data.many === void 0) {
           this.data.many = !!res.data.brand.canShow
         }
-        
+
         this.setData({
           // peopleCount: this.data.many ? manyCount : 5,
           peopleCount: this.data.many ? manyCount : 2,

+ 1 - 1
utils/util.js

@@ -61,7 +61,7 @@ function request(url, data = {}, method = "POST", header = "application/x-www-fo
                     let pages = getCurrentPages()
                     let currPage = pages[pages.length - 1].route
                     let notLogins = ['pages/index/index', 'pages/catalog/catalog', 'pages/category/category', 'pages/ucenter/index/index']
-                    if (res.data.errno == 401 && !~notLogins.indexOf(currPage)) {
+                    if (res.data.code == 401 && !~notLogins.indexOf(currPage)) {
                         resolve(res.data);
                         gotoLogin()
                     } else {