Kaynağa Gözat

feat:兼容50人

jinx 3 yıl önce
ebeveyn
işleme
562bb75c28
4 değiştirilmiş dosya ile 91 ekleme ve 66 silme
  1. 25 19
      component/voice/voice.js
  2. 2 2
      config.js
  3. 2 2
      project.config.json
  4. 62 43
      socket.js

+ 25 - 19
component/voice/voice.js

@@ -18,12 +18,12 @@ Component({
     trtcConfig: {},
     room: 0
   },
-  
+
 
 
   attached() {
-    this.callback = (user={}) => {
-      console.warn('---user---', user,'---user---')
+    this.callback = (user = {}) => {
+      console.warn('---user---', user, '---user---')
       if (user.action === 'stopCall' && this.hasEnter) {
         this.unpublishLocalAudio()
         this.trtcRoomContext.exitRoom()
@@ -56,7 +56,9 @@ Component({
   },
   pageLifetimes: {
     show() {
-      this.setData({show: true})
+      this.setData({
+        show: true
+      })
       // this.trtcRoomContext = this.selectComponent('#trtcroom')
       // if (getApp().globalData.audioUser) {
       //   this.enterAudioRoom(getApp().globalData.audioUser, true)
@@ -67,7 +69,9 @@ Component({
     },
     hide() {
       clearTimeout(this.time)
-      this.setData({show: false})
+      this.setData({
+        show: false
+      })
     },
   },
   /**
@@ -96,39 +100,41 @@ Component({
           return
         }
         console.log(this.trtcRoomContext, )
-        let EVENT =this.trtcRoomContext.EVENT
-  
+        let EVENT = this.trtcRoomContext.EVENT
+
         if (this.trtcRoomContext) {
           this.trtcRoomContext.on(EVENT.LOCAL_JOIN, (event) => {
             // 进房成功后发布本地音频流和视频流 
             console.error('进入房间')
             this.successEnter = true
-            if (user.noMute) {
-              this.unpublishLocalAudio()
-            } else {
-              this.publishLocalAudio()
+            if (user.role == 'leader') {
+              if (user.noMute) {
+                this.unpublishLocalAudio()
+              } else {
+                this.publishLocalAudio()
+              }
             }
           })
-  
+
           this.trtcRoomContext.on(EVENT.LOCAL_LEAVE, (event) => {
             console.error('离开房间')
           })
 
           // 监听远端用户的音频流的变更事件
-         this.trtcRoomContext.on(EVENT.REMOTE_AUDIO_ADD, (event) => {
+          this.trtcRoomContext.on(EVENT.REMOTE_AUDIO_ADD, (event) => {
             // 订阅(即播放)远端用户的音频流
             let userID = event.data.userID
-           this.trtcRoomContext.subscribeRemoteAudio({
+            this.trtcRoomContext.subscribeRemoteAudio({
               userID: userID
             })
           })
           // this.trtcRoomContext.on(EVENT.LOCAL_AUDIO_VOLUME_UPDATE, event => {
           //   console.log(event)
           // })
-         this.trtcRoomContext.enterRoom({
+          this.trtcRoomContext.enterRoom({
             roomID: getApp().globalData.roomId
           }).then(() => {
-            
+
             console.log('成功进入房间')
           }).catch((res) => {
             console.error('room joinRoom 进房失败:', res)
@@ -153,11 +159,11 @@ Component({
         }
       })
     },
-    unpublishLocalAudio () {
+    unpublishLocalAudio() {
       this.trtcRoomContext && this.trtcRoomContext.unpublishLocalAudio()
     },
-    publishLocalAudio () {
+    publishLocalAudio() {
       this.trtcRoomContext && this.trtcRoomContext.publishLocalAudio()
     }
   }
-})
+})

+ 2 - 2
config.js

@@ -18,5 +18,5 @@ const mal = {
 }
 
 
-// export default dev
-export default mal
+export default dev
+// export default mal

+ 2 - 2
project.config.json

@@ -34,9 +34,9 @@
         "packNpmRelationList": [],
         "minifyWXSS": true,
         "disableUseStrict": false,
+        "minifyWXML": true,
         "showES6CompileOption": false,
-        "useCompilerPlugins": false,
-        "minifyWXML": true
+        "useCompilerPlugins": false
     },
     "compileType": "miniprogram",
     "libVersion": "2.20.2",

+ 62 - 43
socket.js

@@ -5,7 +5,8 @@ const util = require('/utils/util.js');
 const UNLOGIN = 'NO_LOGIN'
 const btoa = require('./utils/btoa')
 
-const manyCount = 30
+// const manyCount = 30
+const manyCount = 50
 
 import remote from './config.js'
 var app = getApp();
@@ -65,7 +66,7 @@ export default {
       sponsor = false
     }
 
-    let base = remote.viewHost + '/shop-container/fashilong.html?env='+remote.env+'&sponsor=' + sponsor + '&many=' + this.data.many
+    let base = remote.viewHost + '/shop-container/fashilong.html?env=' + remote.env + '&sponsor=' + sponsor + '&many=' + this.data.many
     // let base = remote.viewHost + '/shop.html'
 
     this.data.reload = false
@@ -90,12 +91,14 @@ export default {
       isIos,
       showComtypesAllTab: false
     })
-    
+
 
     if (this.socketSendMessage) {
       this.pauseVideo = false
       this.joinUrl()
-      this.socketSendMessage('changeOnlineStatus', { status: true  })
+      this.socketSendMessage('changeOnlineStatus', {
+        status: true
+      })
     }
   },
 
@@ -235,18 +238,18 @@ export default {
     // })
 
 
-    
+
     this.role !== 'leader'
     let roomType
     if ((!this.data.canShow && !this.data.join) || (this.data.join && !this.options.join)) {
-        roomType = '1v1'
+      roomType = '1v1'
     }
     return {
       role: this.role || 'leader',
       userId: userInfo.userId,
       roomType,
       avatar: userInfo.avatarUrl,
-      nickname:  userInfo.nickname,
+      nickname: userInfo.nickname,
       voiceStatus: getApp().globalData.voiceProps.noMute ? 0 : 2,
       enableTalk: this.role === 'leader' ? true : undefined,
       roomId: room,
@@ -301,7 +304,9 @@ export default {
       this.socketSendMessage('changeVoiceStatus', {
         status: noMute ? 0 : 2
       })
-      this.socketSendMessage('changeOnlineStatus', { status: true  })
+      this.socketSendMessage('changeOnlineStatus', {
+        status: true
+      })
     })
     socket.on('reconnect_failed', () => this.setData({
       socketStatus: -1
@@ -401,8 +406,8 @@ export default {
   },
 
   getUrl(url, socketOptions, isJoin) {
-    url += '&room_id=' + socketOptions.roomId + '&user_id=' + socketOptions.userId 
-    
+    url += '&room_id=' + socketOptions.roomId + '&user_id=' + socketOptions.userId
+
 
     if (isJoin) {
       url += '&role=' + this.role + '&shopping'
@@ -411,7 +416,7 @@ export default {
     }
 
     console.error(url)
-      console.log(isJoin)
+    console.log(isJoin)
     return url
   },
 
@@ -442,24 +447,28 @@ export default {
     if (!data) return;
 
     this.setData({
-      surplus: this.data.peopleCount -  data.roomsPerson.length
+      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})
+    //限制只有主持人才可以开麦
+    if (this.role == 'leader') {
+      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)
@@ -470,10 +479,14 @@ export default {
       return
     }
     user.noMute = getApp().globalData.voiceProps.noMute
+    //限制只有主持人才可以开麦
+    // if (this.role == 'leader') {
     getApp().setVoiceProps({
       ...user,
       action: 'startCall'
     })
+    // }
+
     // this.socketSendMessage('changeVoiceStatus', {
     //   status: getApp().globalData.voiceProps.noMute ? 0 : 2
     // })
@@ -508,7 +521,7 @@ export default {
       })
       return;
     }
-    
+
     this.role = this.data.canShow ? 'leader' : 'customer'
     let options = await this.getSocketOptions(this.mcode)
 
@@ -521,7 +534,7 @@ export default {
       this.wssSuccess = false
       this.socketStop && this.socketStop()
       this.data.many = !!this.data.canShow
-      
+
       this.setData({
         peopleCount: this.data.many ? manyCount : 5
       })
@@ -538,9 +551,11 @@ export default {
         socketOptions,
       })
       this.joinUrl()
-      
 
-      this.setData({ socketOptions })
+
+      this.setData({
+        socketOptions
+      })
       this.loadConponSuccess = true
       this.readySendCouponCtrl()
     }, 300)
@@ -583,8 +598,8 @@ export default {
 
   async mic() {
     let noMute = getApp().globalData.voiceProps.noMute
-    
-    
+
+
     // noMute true 静音
     // enableTalk false 静音
     // if (!!getApp().globalData.voiceProps.force === !!noMute) 
@@ -640,7 +655,7 @@ export default {
       this.setData({
         sendShare: false
       })
-      
+
       return {
         title: '【好友推荐】一起来云逛吧',
         imageUrl: newPicUrl,
@@ -682,9 +697,9 @@ export default {
 
     console.log(`/pages/shared/shared?img_url=${btoa(img_url)}&shareImg=${btoa(shareImg)}&companyName=${companyName}&vrLink=${btoa(vrLink)}&id=${this.data.id}`);
 
-  wx.navigateTo({
-    url: `/pages/shared/shared?img_url=${btoa(img_url)}&shareImg=${btoa(shareImg)}&companyName=${companyName}&vrLink=${btoa(vrLink)}&id=${this.data.id}`,
-  })
+    wx.navigateTo({
+      url: `/pages/shared/shared?img_url=${btoa(img_url)}&shareImg=${btoa(shareImg)}&companyName=${companyName}&vrLink=${btoa(vrLink)}&id=${this.data.id}`,
+    })
   },
 
 
@@ -873,11 +888,11 @@ export default {
     this.readySendCouponCtrl()
   },
   readySendCouponCtrl() {
-    
+
 
     if (this.wssSuccess && this.loadConponSuccess) {
       this.loadConponSuccess = false
-      
+
       this.socketSendMessage('clientSyncAction', {
         type: 'showCoupon',
         data: this.data.coupons.length > 0
@@ -1020,7 +1035,7 @@ export default {
           sceneNum: res.data.brand.sceneNum,
           canShow: res.data.brand.canShow,
           contractPhone: res.data.brand.contractPhone
-          
+
         })
         if (this.data.many === void 0) {
           this.data.many = !!res.data.brand.canShow
@@ -1028,10 +1043,12 @@ export default {
         this.setData({
           peopleCount: this.data.many ? manyCount : 5,
         })
-      
+        console.error(this.data.peopleCount)
+
+
         if (!res.data.brand.canShow) {
           this.role = 'customer'
-        } else if (!this.options.join){
+        } else if (!this.options.join) {
           this.role = 'leader'
         }
         cb(url, urlToJson(url).m, )
@@ -1077,8 +1094,10 @@ export default {
   },
 
   onHide() {
-    this.socketSendMessage('changeOnlineStatus', { status: false  })
-    
+    this.socketSendMessage('changeOnlineStatus', {
+      status: false
+    })
+
     this.pauseVideo = true
     this.joinUrl()
   }