Skip to content

Commit 05c9c4b

Browse files
hyriousvince-hz
andcommitted
fix(v1): rejoin a deleted room causes incorrect rtc uid (#737)
Co-authored-by: xuyunshi <405029644@qq.com>
1 parent ad2a13c commit 05c9c4b

File tree

6 files changed

+137
-54
lines changed

6 files changed

+137
-54
lines changed

src/v1/controller/room/info/__tests__/helpers/createUsersRequest.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,15 @@ export const createUsersRequest = (
2828
} as ControllerClassParams);
2929
};
3030

31-
export const createRoom = async (ownerUUID: string, roomUUID: string): Promise<void> => {
31+
export const createRoom = async (
32+
ownerUUID: string,
33+
roomUUID: string,
34+
roomStatus: RoomStatus = RoomStatus.Stopped,
35+
): Promise<void> => {
3236
await RoomDAO().insert({
3337
room_uuid: roomUUID,
3438
periodic_uuid: "",
35-
room_status: RoomStatus.Stopped,
39+
room_status: roomStatus,
3640
begin_time: new Date(),
3741
end_time: new Date(),
3842
title: "test",

src/v1/controller/room/join/Ordinary.ts

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -43,30 +43,34 @@ export const joinOrdinary = async (
4343
}
4444

4545
const { whiteboard_room_uuid: whiteboardRoomUUID } = roomInfo;
46-
let rtcUID: string;
46+
47+
// Either user is joinning a new room or rejoinning a (maybe deleted) room.
48+
await RoomUserDAO().insert(
49+
{
50+
room_uuid: roomUUID,
51+
user_uuid: userUUID,
52+
rtc_uid: cryptoRandomString({ length: 6, type: "numeric" }),
53+
},
54+
{
55+
orUpdate: {
56+
is_delete: false,
57+
},
58+
},
59+
);
4760

4861
const roomUserInfo = await RoomUserDAO().findOne(["rtc_uid"], {
4962
room_uuid: roomUUID,
5063
user_uuid: userUUID,
5164
});
5265

66+
let rtcUID: string;
5367
if (roomUserInfo !== undefined) {
5468
rtcUID = roomUserInfo.rtc_uid;
5569
} else {
56-
rtcUID = cryptoRandomString({ length: 6, type: "numeric" });
57-
58-
await RoomUserDAO().insert(
59-
{
60-
room_uuid: roomUUID,
61-
user_uuid: userUUID,
62-
rtc_uid: rtcUID,
63-
},
64-
{
65-
orUpdate: {
66-
is_delete: false,
67-
},
68-
},
69-
);
70+
return {
71+
status: Status.Failed,
72+
code: ErrorCode.CurrentProcessFailed,
73+
};
7074
}
7175

7276
return {

src/v1/controller/room/join/Periodic.ts

Lines changed: 40 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -54,52 +54,55 @@ export const joinPeriodic = async (
5454
}
5555

5656
const { room_uuid: roomUUID, whiteboard_room_uuid: whiteboardRoomUUID } = roomInfo;
57-
let rtcUID: string;
57+
58+
await dataSource.transaction(async t => {
59+
const commands: Promise<unknown>[] = [];
60+
61+
commands.push(
62+
RoomUserDAO(t).insert(
63+
{
64+
room_uuid: roomUUID,
65+
user_uuid: userUUID,
66+
rtc_uid: cryptoRandomString({ length: 6, type: "numeric" }),
67+
},
68+
{
69+
orUpdate: {
70+
is_delete: false,
71+
},
72+
},
73+
),
74+
);
75+
76+
commands.push(
77+
RoomPeriodicUserDAO(t).insert(
78+
{
79+
periodic_uuid: periodicUUID,
80+
user_uuid: userUUID,
81+
},
82+
{
83+
orUpdate: {
84+
is_delete: false,
85+
},
86+
},
87+
),
88+
);
89+
90+
return await Promise.all(commands);
91+
});
5892

5993
const roomUserInfo = await RoomUserDAO().findOne(["rtc_uid"], {
6094
room_uuid: roomUUID,
6195
user_uuid: userUUID,
6296
});
6397

98+
let rtcUID: string;
6499
if (roomUserInfo !== undefined) {
65100
rtcUID = roomUserInfo.rtc_uid;
66101
} else {
67-
rtcUID = cryptoRandomString({ length: 6, type: "numeric" });
68-
69-
await dataSource.transaction(async t => {
70-
const commands: Promise<unknown>[] = [];
71-
72-
commands.push(
73-
RoomUserDAO(t).insert(
74-
{
75-
room_uuid: roomUUID,
76-
user_uuid: userUUID,
77-
rtc_uid: rtcUID,
78-
},
79-
{
80-
orUpdate: {
81-
is_delete: false,
82-
},
83-
},
84-
),
85-
);
86-
87-
commands.push(
88-
RoomPeriodicUserDAO(t).insert(
89-
{
90-
periodic_uuid: periodicUUID,
91-
user_uuid: userUUID,
92-
},
93-
{
94-
orUpdate: {
95-
is_delete: false,
96-
},
97-
},
98-
),
99-
);
100-
101-
return await Promise.all(commands);
102-
});
102+
return {
103+
status: Status.Failed,
104+
code: ErrorCode.CurrentProcessFailed,
105+
};
103106
}
104107

105108
return {
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { Logger } from "../../../../../../logger";
2+
import { CancelOrdinary } from "../../../cancel/Ordinary";
3+
4+
export const createCancel = (roomUUID: string, userUUID: string): CancelOrdinary => {
5+
const logger = new Logger<any>("test", {}, []);
6+
return new CancelOrdinary({
7+
logger,
8+
req: {
9+
body: {
10+
roomUUID,
11+
},
12+
user: {
13+
userUUID,
14+
},
15+
},
16+
reply: {},
17+
} as any);
18+
};
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { JoinRoom } from "../..";
2+
import { Logger } from "../../../../../../logger";
3+
4+
export const createJoinRoom = (roomUUID: string, userUUID: string): JoinRoom => {
5+
const logger = new Logger<any>("test", {}, []);
6+
return new JoinRoom({
7+
logger,
8+
req: {
9+
body: {
10+
uuid: roomUUID,
11+
},
12+
user: {
13+
userUUID,
14+
},
15+
},
16+
reply: {},
17+
} as any);
18+
};
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import test from "ava";
2+
import { dataSource } from "../../../../../thirdPartyService/TypeORMService";
3+
import { v4 } from "uuid";
4+
import { createRoom, createRoomUser } from "../../info/__tests__/helpers/createUsersRequest";
5+
import { createCancel } from "./helpers/createCancelOrdinary";
6+
import { createJoinRoom } from "./helpers/createJoinRoom";
7+
import { RoomStatus } from "../../../../../model/room/Constants";
8+
9+
const namespace = "[api][api-v1][api-v1-room][api-v1-room-join]";
10+
11+
test.before(`${namespace} - initialize dataSource`, async () => {
12+
await dataSource.initialize();
13+
});
14+
15+
test.after(`${namespace} - destroy dataSource`, async () => {
16+
await dataSource.destroy();
17+
});
18+
19+
test(`${namespace} - join after user cancel`, async ava => {
20+
const [roomUUID] = [v4()];
21+
const [ownerUUID, anotherUserUUID] = await createRoomUser(roomUUID, 2);
22+
await createRoom(ownerUUID, roomUUID, RoomStatus.Started);
23+
24+
const joinRoom = createJoinRoom(roomUUID, anotherUserUUID);
25+
const result = await joinRoom.execute();
26+
const f: number = (result as any).data.rtcUID;
27+
28+
await createCancel(roomUUID, anotherUserUUID).execute();
29+
30+
const joinRoom1 = createJoinRoom(roomUUID, anotherUserUUID);
31+
const join1Result = await joinRoom1.execute();
32+
const f1: number = (join1Result as any).data.rtcUID;
33+
34+
ava.is(f > 0 && f1 > 0, true);
35+
ava.is(f == f1, true);
36+
});

0 commit comments

Comments
 (0)