|
@@ -52,7 +52,7 @@ export class RoomAssistant {
|
|
|
* @param {*} roomId
|
|
|
* @param {*} userId
|
|
|
*/
|
|
|
- async setAssistant(roomId, userId, callback) {
|
|
|
+ async setAssistant(roomId, userId, cancel) {
|
|
|
try {
|
|
|
const userRes = await getCurrentUser(roomId, userId, FROMTYPE.MiniAPP);
|
|
|
const user = JSON.parse(userRes);
|
|
@@ -61,19 +61,70 @@ export class RoomAssistant {
|
|
|
console.log("不能设置自己为助理!");
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
- // 0是助手,1不是助手
|
|
|
- const userObj = Object.assign({}, user, { isAssistant: 0 });
|
|
|
+ const role = cancel ? "customer" : "assistant";
|
|
|
+ // assistant是助手,customer是普通角色,操作role会好些
|
|
|
+ const userObj = Object.assign({}, user, { role: role });
|
|
|
const roomObj = Object.assign({}, roomConfigRes, { assistantId: user.userId });
|
|
|
// console.log("setAssistant", userObj, roomObj);
|
|
|
// console.error("roomObj", roomObj);
|
|
|
await updateRoomUser(roomId, userId, userObj);
|
|
|
// // 更新roomConfig 设置助手id
|
|
|
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);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ // console.log("AllRoomUsers", AllRoomUsers);
|
|
|
// callback(user);
|
|
|
- this.room.notify.notifyBeAssistant(roomId, userId, user);
|
|
|
+ this.room.notify.notifyBeAssistant(roomId, userObj, this.room.userId);
|
|
|
+ } catch (error) {
|
|
|
+ this.room.logger.error("setAssistant:error", error);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 设置MIC权 LEADER(权限) 房主或助手
|
|
|
+ * 主要
|
|
|
+ * @param {*} roomId
|
|
|
+ * @param {*} userId
|
|
|
+ */
|
|
|
+ async setMicRight(roomId, userId, isAllowMic) {
|
|
|
+ try {
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+
|
|
|
+ const reveseMic = Number(isAllowMic) === 0 ? 1 : 0;
|
|
|
+ console.log("设置MIC权当前用户:: %s 新MIC权", user, reveseMic);
|
|
|
+ const userObj = Object.assign({}, user, { isAllowMic: reveseMic });
|
|
|
+ const roomObj = Object.assign({}, roomConfigRes, { allowMicId: user.userId });
|
|
|
+
|
|
|
+ await updateRoomUser(roomId, userId, userObj);
|
|
|
+ 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);
|
|
|
} catch (error) {
|
|
|
- this.room.logger.error("setAssistant", error);
|
|
|
+ this.room.logger.error("setMicRight::error", error);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -199,7 +250,9 @@ export class RoomAssistant {
|
|
|
if (checkIsRoomMaster) {
|
|
|
this.room.logger.info("房主已存在房间 :", { roomId, userId, from: user.from });
|
|
|
// await this.joinRoom(roomId, userId, user);
|
|
|
- this.notifyUserJitter(roomId);
|
|
|
+ // this.notifyUserJitter(roomId);
|
|
|
+ } else {
|
|
|
+ this.room.logger.error("存在非法房主", userId);
|
|
|
}
|
|
|
}
|
|
|
}
|