|
@@ -20,6 +20,13 @@ export class UsersService {
|
|
|
|
|
|
return res > 0 ? true : false;
|
|
|
}
|
|
|
+ async isMaxRoom(RoomId: string, max?: number): Promise<boolean> {
|
|
|
+ const config = await this.getRoomConfig(RoomId);
|
|
|
+ const newMax = max ? max : config ? Number(config['limit']) : 50;
|
|
|
+ const res = await this.redis.hvals(`kankan:socket:rooms:${RoomId}`);
|
|
|
+ console.log('newMax', res.length);
|
|
|
+ return Promise.resolve(res.length >= newMax);
|
|
|
+ }
|
|
|
async isValidRoom(RoomId: string): Promise<boolean> {
|
|
|
const isRoomHasConfig = await this.redis.hexists(
|
|
|
`kankan:socket:roomConfig`,
|
|
@@ -104,11 +111,21 @@ export class UsersService {
|
|
|
RoomId: string,
|
|
|
RoomConfig: RoomConfigType,
|
|
|
): Promise<void> {
|
|
|
- this.redis.hset(
|
|
|
- `kankan:socket:roomConfig`,
|
|
|
- RoomId,
|
|
|
- JSON.stringify(RoomConfig),
|
|
|
- );
|
|
|
+ const isExist = await this.redis.hget(`kankan:socket:roomConfig`, RoomId);
|
|
|
+ // console.log('setRoomConfig', isExist);
|
|
|
+ if (isExist) {
|
|
|
+ const config = JSON.parse(isExist);
|
|
|
+ const obj = Object.assign({}, config, RoomConfig);
|
|
|
+ const updateString = JSON.stringify(obj);
|
|
|
+ // console.log('setRoomConfig-obj', RoomId, updateString);
|
|
|
+ await this.redis.hset(`kankan:socket:roomConfig`, RoomId, updateString);
|
|
|
+ } else {
|
|
|
+ await this.redis.hset(
|
|
|
+ `kankan:socket:roomConfig`,
|
|
|
+ RoomId,
|
|
|
+ JSON.stringify(RoomConfig),
|
|
|
+ );
|
|
|
+ }
|
|
|
}
|
|
|
async isRoomMaster(RoomId: string, userId: string): Promise<boolean> {
|
|
|
try {
|
|
@@ -209,4 +226,13 @@ export class UsersService {
|
|
|
return Promise.resolve(false);
|
|
|
}
|
|
|
}
|
|
|
+ async getRoomConfig(RoomId: string): Promise<JSONValue> {
|
|
|
+ const isExist = await this.redis.hget(`kankan:socket:roomConfig`, RoomId);
|
|
|
+ if (isExist) {
|
|
|
+ const updater = JSON.parse(isExist);
|
|
|
+ return Promise.resolve(updater);
|
|
|
+ } else {
|
|
|
+ return Promise.resolve(false);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|