|
@@ -15,7 +15,6 @@ export class RoomController extends BasicController {
|
|
this.userId = null;
|
|
this.userId = null;
|
|
this.roomConfigId = null;
|
|
this.roomConfigId = null;
|
|
this.debugger = true;
|
|
this.debugger = true;
|
|
- this.sysUsers = [];
|
|
|
|
this.user = {
|
|
this.user = {
|
|
sig: null,
|
|
sig: null,
|
|
roomId: null,
|
|
roomId: null,
|
|
@@ -34,8 +33,10 @@ export class RoomController extends BasicController {
|
|
};
|
|
};
|
|
}
|
|
}
|
|
// 以小程序user信息作为主要信息
|
|
// 以小程序user信息作为主要信息
|
|
- get currentUser() {
|
|
|
|
- return this.sysUsers.find((item) => Number(item.from) === 2);
|
|
|
|
|
|
+ async currentUser() {
|
|
|
|
+ const data = await getCurrentUser(this.userId, FROMTYPE.MiniAPP);
|
|
|
|
+ const user = data ? JSON.parse(data) : this.user;
|
|
|
|
+ return user;
|
|
}
|
|
}
|
|
|
|
|
|
async run() {
|
|
async run() {
|
|
@@ -52,7 +53,7 @@ export class RoomController extends BasicController {
|
|
|
|
|
|
async init() {
|
|
async init() {
|
|
let user = this.socket.handshake.query;
|
|
let user = this.socket.handshake.query;
|
|
-
|
|
|
|
|
|
+ this.logger.info("init-user-query:", this.socket.handshake.query);
|
|
if (user) {
|
|
if (user) {
|
|
this.user = Object.assign({}, user, {
|
|
this.user = Object.assign({}, user, {
|
|
roomType: user.roomType || "",
|
|
roomType: user.roomType || "",
|
|
@@ -64,7 +65,7 @@ export class RoomController extends BasicController {
|
|
const userObj = { ...this.user, isConnected: true };
|
|
const userObj = { ...this.user, isConnected: true };
|
|
|
|
|
|
updateUser(this.userId, userObj);
|
|
updateUser(this.userId, userObj);
|
|
- this.sysUsers.push(this.user);
|
|
|
|
|
|
+ // this.sysUsers.push(this.user);
|
|
|
|
|
|
// 只有来源于小程序用户信息才记录到redis
|
|
// 只有来源于小程序用户信息才记录到redis
|
|
if (this.isHoster(this.user.role)) {
|
|
if (this.isHoster(this.user.role)) {
|
|
@@ -123,9 +124,9 @@ export class RoomController extends BasicController {
|
|
});
|
|
});
|
|
|
|
|
|
this.socket.on(EVENT.startCall, async () => {
|
|
this.socket.on(EVENT.startCall, async () => {
|
|
- const currentUser = await getCurrentUser(this.userId, FROMTYPE.MiniAPP);
|
|
|
|
- const user = JSON.parse(currentUser) || this.user;
|
|
|
|
|
|
+ const user = await this.currentUser();
|
|
this.roomAssistant.startCall(this.roomId, this.userId, user);
|
|
this.roomAssistant.startCall(this.roomId, this.userId, user);
|
|
|
|
+ // console.log("startCall-from", this.user.from);
|
|
if (this.isHoster(this.user.role)) {
|
|
if (this.isHoster(this.user.role)) {
|
|
// 以startCall做为真正的进入房间
|
|
// 以startCall做为真正的进入房间
|
|
await updateRoomConfigByKey(this.roomId, "isStart", true);
|
|
await updateRoomConfigByKey(this.roomId, "isStart", true);
|
|
@@ -152,21 +153,33 @@ export class RoomController extends BasicController {
|
|
|
|
|
|
this.socket.on(EVENT.changeOnlineStatus, async (data) => {
|
|
this.socket.on(EVENT.changeOnlineStatus, async (data) => {
|
|
try {
|
|
try {
|
|
- this.user.onlineStatus = data.status;
|
|
|
|
|
|
+ const user = await this.currentUser();
|
|
|
|
+ user.onlineStatus = data.status;
|
|
const AllRoomUsers = await getAllRoomUsers(this.roomId);
|
|
const AllRoomUsers = await getAllRoomUsers(this.roomId);
|
|
- await updateRoomUser(this.roomId, this.userId, this.user);
|
|
|
|
|
|
+ await updateRoomUser(this.roomId, this.userId, user);
|
|
let actionName = this.user.onlineStatus ? "inRoom" : "leaveRoom";
|
|
let actionName = this.user.onlineStatus ? "inRoom" : "leaveRoom";
|
|
- this.logger.info("changeOnlineStatus", JSON.stringify(this.user));
|
|
|
|
|
|
+ this.logger.info("changeOnlineStatus", JSON.stringify(user));
|
|
this.socket.broadcast.to(this.roomId).emit(EVENT.roomPersonChange, {
|
|
this.socket.broadcast.to(this.roomId).emit(EVENT.roomPersonChange, {
|
|
roomsPerson: AllRoomUsers,
|
|
roomsPerson: AllRoomUsers,
|
|
actionName,
|
|
actionName,
|
|
- user: this.user,
|
|
|
|
|
|
+ user: user,
|
|
});
|
|
});
|
|
} catch (error) {
|
|
} catch (error) {
|
|
this.logger.error("event:changeOnlineStatus", error);
|
|
this.logger.error("event:changeOnlineStatus", error);
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
|
|
|
|
+ this.socket.on(EVENT.kickUser, async ({ data, from }) => {
|
|
|
|
+ const userId = `user:${data.userId}`;
|
|
|
|
+ const roomId = `room:${data.sceneNumber}:${data.roomId}`;
|
|
|
|
+ this.logger.info("kickUser", data.userId, data.roomId);
|
|
|
|
+ this.roomAssistant.kickPersion(roomId, userId);
|
|
|
|
+ const currentUser = await getCurrentUser(userId, FROMTYPE.MiniAPP);
|
|
|
|
+ this.roomAssistant.notifyUsersChange(roomId, currentUser);
|
|
|
|
+ //TODO 如果踢人后 如何通知?
|
|
|
|
+ this.socket.broadcast.to(roomId).emit(EVENT.beKicked, data);
|
|
|
|
+ });
|
|
|
|
+
|
|
if (this.debugger) {
|
|
if (this.debugger) {
|
|
this.socket.onAny((event, data) => {
|
|
this.socket.onAny((event, data) => {
|
|
if (event !== "webSyncAction") {
|
|
if (event !== "webSyncAction") {
|