|
@@ -63,7 +63,7 @@ export class RoomAssistant {
|
|
|
}
|
|
|
const role = cancel ? "customer" : "assistant";
|
|
|
// assistant是助手,customer是普通角色,操作role会好些
|
|
|
- const userObj = Object.assign({}, user, { role: role });
|
|
|
+ const userObj = Object.assign({}, user, { role: role, order: 1 });
|
|
|
const roomObj = Object.assign({}, roomConfigRes, { assistantId: user.userId });
|
|
|
// console.log("setAssistant", userObj, roomObj);
|
|
|
// console.error("roomObj", roomObj);
|
|
@@ -72,18 +72,23 @@ export class RoomAssistant {
|
|
|
await setRoomConfig(roomId, roomObj);
|
|
|
const AllRoomUsers = await getAllRoomUsers(roomId);
|
|
|
|
|
|
- // 已存在的设置为false
|
|
|
- Array.from(AllRoomUsers)
|
|
|
- .filter((i) => i.role !== "leader")
|
|
|
- .forEach(async (assistant) => {
|
|
|
- if (assistant.userId !== userObj.userId) {
|
|
|
- const unsetUserObj = Object.assign({}, assistant, { role: "customer" });
|
|
|
- await updateRoomUser(roomId, userId, unsetUserObj);
|
|
|
- }
|
|
|
+ // 同房间的其他人重置
|
|
|
+ const resetOther = Array.from(AllRoomUsers)
|
|
|
+ .filter((i) => i.role !== "leader" && i.userId !== userObj.userId)
|
|
|
+ .map((roomer) => {
|
|
|
+ const userKey = `user:${roomer.userId}`;
|
|
|
+ const unsetUserObj = Object.assign({}, roomer, { role: "customer", order: 2 });
|
|
|
+ // console.log("同房间的其他人重置", userKey, unsetUserObj);
|
|
|
+ return updateRoomUser(roomId, userKey, unsetUserObj);
|
|
|
});
|
|
|
+ //总处理完成
|
|
|
+
|
|
|
+ Promise.all(resetOther).then(() => {
|
|
|
+ this.room.notify.notifyBeAssistant(roomId, userObj, this.room.userId);
|
|
|
+ });
|
|
|
+
|
|
|
// console.log("AllRoomUsers", AllRoomUsers);
|
|
|
// callback(user);
|
|
|
- this.room.notify.notifyBeAssistant(roomId, userObj, this.room.userId);
|
|
|
} catch (error) {
|
|
|
this.room.logger.error("setAssistant:error", error);
|
|
|
}
|
|
@@ -99,11 +104,10 @@ export class RoomAssistant {
|
|
|
const userRes = await getCurrentUser(roomId, userId, FROMTYPE.MiniAPP);
|
|
|
const user = JSON.parse(userRes);
|
|
|
const roomConfigRes = await getRoomConfig(roomId);
|
|
|
- if (this.room.userId == userId) {
|
|
|
- console.log("不用设置自己的MIC!");
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
+ // if (this.room.userId == userId && this.room.isHoster(this.room.user.role)) {
|
|
|
+ // console.log("房主不用设置自己的MIC!");
|
|
|
+ // return;
|
|
|
+ // }
|
|
|
const reveseMic = Number(isAllowMic) === 0 ? 1 : 0;
|
|
|
console.log("设置MIC权当前用户:: %s 新MIC权", user, reveseMic);
|
|
|
const userObj = Object.assign({}, user, { isAllowMic: reveseMic });
|
|
@@ -113,16 +117,17 @@ export class RoomAssistant {
|
|
|
await setRoomConfig(roomId, roomObj);
|
|
|
const AllRoomUsers = await getAllRoomUsers(roomId);
|
|
|
// 已存在的设置为false
|
|
|
- Array.from(AllRoomUsers)
|
|
|
- .filter((i) => i.role !== "leader")
|
|
|
- .forEach(async (assistant) => {
|
|
|
- if (assistant.userId !== userObj.userId) {
|
|
|
- const unsetUserObj = Object.assign({}, assistant, { isAllowMic: 0 });
|
|
|
- await updateRoomUser(roomId, userId, unsetUserObj);
|
|
|
- }
|
|
|
- });
|
|
|
|
|
|
- this.room.notify.notifyBeHasMic(roomId, userObj, this.room.userId);
|
|
|
+ const resetOther = Array.from(AllRoomUsers)
|
|
|
+ .filter((i) => i.role !== "leader" && i.userId !== userObj.userId)
|
|
|
+ .map((roomer) => {
|
|
|
+ const userKey = `user:${roomer.userId}`;
|
|
|
+ const unsetUserObj = Object.assign({}, roomer, { isAllowMic: 0 });
|
|
|
+ return updateRoomUser(roomId, userKey, unsetUserObj);
|
|
|
+ });
|
|
|
+ Promise.all(resetOther).then(() => {
|
|
|
+ this.room.notify.notifyBeHasMic(roomId, userObj, this.room.userId);
|
|
|
+ });
|
|
|
} catch (error) {
|
|
|
this.room.logger.error("setMicRight::error", error);
|
|
|
}
|
|
@@ -249,7 +254,7 @@ export class RoomAssistant {
|
|
|
console.log("isRoomMaster", checkIsRoomMaster);
|
|
|
if (checkIsRoomMaster) {
|
|
|
this.room.logger.info("房主已存在房间 :", { roomId, userId, from: user.from });
|
|
|
- // await this.joinRoom(roomId, userId, user);
|
|
|
+ await this.joinRoom(roomId, userId, user);
|
|
|
// this.notifyUserJitter(roomId);
|
|
|
} else {
|
|
|
this.room.logger.error("存在非法房主", userId);
|