gemercheung 3 年之前
父節點
當前提交
ff7979b252
共有 1 個文件被更改,包括 61 次插入20 次删除
  1. 61 20
      socket.js

+ 61 - 20
socket.js

@@ -69,6 +69,14 @@ export default {
     if (this.data.join && !this.options.join) {
       sponsor = false
     }
+
+
+    // 33是从我的房间出来的
+    if (Number(this.data.type) === 33) {
+      sponsor = true;
+    }
+
+    // debugger
     // remote.viewHost
     let hostUrl
     if (options.url.indexOf('www.4dkankan.com') != -1) {
@@ -246,26 +254,30 @@ export default {
 
   async getSocketOptions(sceneId, roomId) {
     //TODO
-    // console.log('this.options.id', this.options.id)
-    debugger;
-    const res = await util.request(api.enterRoom, {
-      businessId: roomId
-    }, 'POST', 'application/json')
-  
-    if (res.code !== 200) {
-      wx.showModal({
-        content: res.error,
-        cancelColor: 'cancelColor',
-        complete: () => {
-          wx.navigateTo({
-            url: '/pages/roomManger/roomManger',
-          })
-        }
-      })
-      return
+    console.log('this.data.type', this.data.type)
+    // debugger;
+
+    let result
+    if (Number(this.data.type) === 33) {
+      result = await util.request(api.enterRoom, {
+        businessId: roomId
+      }, 'POST', 'application/json')
+
+      if (result.code !== 200) {
+        wx.showModal({
+          content: result.error,
+          complete: () => {
+            wx.navigateBack({
+              url: '/pages/roomManger/roomManger',
+            })
+          }
+        })
+        return
+      }
     }
 
-    const capacities = res.capacities  // 房间限制人数
+
+    const capacities = !!result ? result.capacities : 50 // 房间限制人数
     let userInfo = await this.getUserInfo()
 
     // console.log('---', userInfo)
@@ -298,6 +310,7 @@ export default {
       avatar: userInfo.avatarUrl,
       nickname: userInfo.nickname,
       voiceStatus: getApp().globalData.voiceProps.noMute ? 0 : 2,
+      isAuthMic: !!this.isAuthorizeRecord,
       enableTalk: this.role === 'leader' ? true : undefined,
       roomId: roomId,
       sceneNumber: sceneId,
@@ -316,6 +329,9 @@ export default {
     }
 
     console.log('小程序参数', options)
+    if (!options.roomId) {
+      return
+    }
 
     let socket = io(remote.socketHost, {
       path: '/fsl-node',
@@ -326,7 +342,7 @@ export default {
         from: 2
       }
     })
-
+ 
     console.error('新建socket Room', options.roomId)
     this.setData({
       socketStatus: 0
@@ -427,9 +443,34 @@ export default {
       if ('roomId' in data) {
         options.roomId = Number(data.roomId)
       }
-
     })
 
+    socket.on("beKicked", data => {
+      if (data.userId && data.roomId) {
+        const socketOptions = this.data.socketOptions
+        const userId = data.userId
+        const roomId = data.roomId
+        // debugger
+        if (socketOptions.userId == userId && this.options.roomId == roomId) {
+          wx.showToast({
+            title: '您已被踢出房间!',
+            icon: 'none',
+            complete: () => {
+              setTimeout(() => {
+                this.socketStop();
+                wx.redirectTo({
+                  url: '/pages/roomManger/roomManger',
+
+                });
+              }, 1000)
+
+            }
+          })
+        }
+      }
+    });
+
+ 
     this.socketStop = () => {
       if (socket) {
         socket.close()