|
@@ -18,6 +18,21 @@ wx.getSystemInfo({
|
|
|
}
|
|
|
})
|
|
|
|
|
|
+const debounce = (fn, wait) => {
|
|
|
+ let callback = fn;
|
|
|
+ let timerId = null;
|
|
|
+
|
|
|
+ function debounced() {
|
|
|
+ let context = this;
|
|
|
+ let args = arguments;
|
|
|
+ clearTimeout(timerId);
|
|
|
+ timerId = setTimeout(function () {
|
|
|
+ callback.apply(context, args);
|
|
|
+ }, wait);
|
|
|
+ }
|
|
|
+ return debounced;
|
|
|
+}
|
|
|
+
|
|
|
|
|
|
let urlToJson = (url = window.location.href) => { // 箭头函数默认传值为当前页面url
|
|
|
|
|
@@ -263,6 +278,7 @@ export default {
|
|
|
businessId: roomId
|
|
|
}, 'POST', 'application/json')
|
|
|
|
|
|
+
|
|
|
if (result.code !== 200) {
|
|
|
wx.showModal({
|
|
|
content: result.error,
|
|
@@ -277,7 +293,13 @@ export default {
|
|
|
}
|
|
|
|
|
|
|
|
|
- const capacities = !!result ? result.capacities : 50 // 房间限制人数
|
|
|
+ const capacities = !!result ? result.message.capacities : 50 // 房间限制人数
|
|
|
+
|
|
|
+ const {
|
|
|
+ isAnchor,
|
|
|
+ assistant,
|
|
|
+ } = !!result ? result.message : {}
|
|
|
+
|
|
|
let userInfo = await this.getUserInfo()
|
|
|
|
|
|
// console.log('---', userInfo)
|
|
@@ -292,7 +314,7 @@ export default {
|
|
|
// this.role !== 'leader'
|
|
|
let roomType
|
|
|
if ((!this.data.canShow && !this.data.join) || (this.data.join && !this.options.join)) {
|
|
|
- roomType = '1v1'
|
|
|
+ // roomType = '1v1'
|
|
|
if (this.options.roomId) {
|
|
|
this.role = 'leader'
|
|
|
}
|
|
@@ -303,8 +325,19 @@ export default {
|
|
|
// title: this.data.peopleCount.toString(),
|
|
|
// })
|
|
|
|
|
|
+ if (Number(isAnchor) === 1) {
|
|
|
+ this.role = "leader"
|
|
|
+ } else {
|
|
|
+ this.role = 'customer'
|
|
|
+ }
|
|
|
+
|
|
|
+ if (assistant && assistant.userId && assistant.userId == userInfo.userId) {
|
|
|
+ this.role = 'assistant'
|
|
|
+ }
|
|
|
+ console.log('进入房间角色,', this.role);
|
|
|
+
|
|
|
return {
|
|
|
- role: this.role || 'leader',
|
|
|
+ role: this.role,
|
|
|
userId: userInfo.userId,
|
|
|
roomType,
|
|
|
avatar: userInfo.avatarUrl,
|
|
@@ -342,7 +375,7 @@ export default {
|
|
|
from: 2
|
|
|
}
|
|
|
})
|
|
|
-
|
|
|
+
|
|
|
console.error('新建socket Room', options.roomId)
|
|
|
this.setData({
|
|
|
socketStatus: 0
|
|
@@ -430,7 +463,10 @@ export default {
|
|
|
console.log('on stopCall')
|
|
|
this.stopCall(data)
|
|
|
})
|
|
|
- socket.on('someOneInRoom', this.startCall.bind(this))
|
|
|
+
|
|
|
+ this.handleSomeOneInRoom = this.handleSomeOneInRoom.bind(this)
|
|
|
+ // socket.on('someOneInRoom', debounce(this.handleSomeOneInRoom, 100))
|
|
|
+ socket.on('someOneInRoom', debounce(this.handleSomeOneInRoom, 100))
|
|
|
socket.on('someOneLeaveRoom', (user, data) => {
|
|
|
this.handleSomeOneLeave(user)
|
|
|
})
|
|
@@ -470,7 +506,7 @@ export default {
|
|
|
}
|
|
|
});
|
|
|
|
|
|
-
|
|
|
+
|
|
|
this.socketStop = () => {
|
|
|
if (socket) {
|
|
|
socket.close()
|
|
@@ -539,8 +575,6 @@ export default {
|
|
|
|
|
|
getUrl(url, socketOptions, isJoin) {
|
|
|
url += '&room_id=' + socketOptions.roomId + '&user_id=' + socketOptions.userId + '&origin=fashilong'
|
|
|
-
|
|
|
-
|
|
|
if (isJoin) {
|
|
|
url += '&role=' + this.role + '&shopping'
|
|
|
} else {
|
|
@@ -574,8 +608,15 @@ export default {
|
|
|
},
|
|
|
})
|
|
|
},
|
|
|
+ async handleSomeOneInRoom(data) {
|
|
|
+ if (data && data.user) {
|
|
|
+ console.log('handleSomeOneInRoom', data)
|
|
|
+ this.startCall(data)
|
|
|
+ }
|
|
|
+ },
|
|
|
|
|
|
async startCall(data) {
|
|
|
+ //TODO 触发三次
|
|
|
console.log('startCall-data', data)
|
|
|
// if( this.role =='leader'){
|
|
|
this.setData({
|
|
@@ -586,29 +627,44 @@ export default {
|
|
|
this.setData({
|
|
|
surplus: this.data.peopleCount - data.roomsPerson.length
|
|
|
})
|
|
|
- //限制只有主持人才可以开麦
|
|
|
- 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})
|
|
|
+
|
|
|
+ //undefined是未授权,状态为3
|
|
|
+ let voiceStatus
|
|
|
+ if (!this.isAuthorizeRecord) {
|
|
|
+ const unAuth = await this.authorizeRecord();
|
|
|
+ if (typeof unAuth === 'undefined') {
|
|
|
+ // debugger
|
|
|
+ voiceStatus = 3
|
|
|
+ } else {
|
|
|
+ voiceStatus = Number(unAuth)
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
+ //限制只有主持人才可以开麦
|
|
|
+ // 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)
|
|
|
+
|
|
|
if (!user) {
|
|
|
return
|
|
|
}
|