Spaces:
Runtime error
Runtime error
No longer can create room with custom room ID
Browse files
server/src/socket/routes/join_room.ts
CHANGED
|
@@ -23,9 +23,14 @@ export function JoinRoomHandler(ctx: Context<JoinRoomPayload>) {
|
|
| 23 |
|
| 24 |
if (ctx.payload.roomId && !ctx.server.rooms[ctx.payload.roomId]) {
|
| 25 |
// User sent roomId, but room doesn't exist
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
} else if (!ctx.payload.roomId) {
|
| 31 |
// Didn't include RoomID, creating new one
|
|
|
|
| 23 |
|
| 24 |
if (ctx.payload.roomId && !ctx.server.rooms[ctx.payload.roomId]) {
|
| 25 |
// User sent roomId, but room doesn't exist
|
| 26 |
+
return ctx.ws.send(JSON.stringify({
|
| 27 |
+
"message": "join_room_response",
|
| 28 |
+
"status": "room doesn't exist",
|
| 29 |
+
}))
|
| 30 |
+
// Custom ID Code:
|
| 31 |
+
// room = new Room(ctx.payload.roomId);
|
| 32 |
+
// room.id = room.id.toUpperCase();
|
| 33 |
+
// ctx.server.rooms[room.id] = room;
|
| 34 |
|
| 35 |
} else if (!ctx.payload.roomId) {
|
| 36 |
// Didn't include RoomID, creating new one
|
server/test/socket/routes/join_room.spec.ts
CHANGED
|
@@ -43,6 +43,16 @@ describe("Join Room", () => {
|
|
| 43 |
expect(ctx.payload.roomId!).to.satisfy((id: string) => id.length > 3, "room id not generated");
|
| 44 |
expect(user.username).to.equal("test", "didn't set username");
|
| 45 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
it("should join existing room", () => {
|
| 48 |
testJoinRoom(1); // Initial user joins and creates room
|
|
|
|
| 43 |
expect(ctx.payload.roomId!).to.satisfy((id: string) => id.length > 3, "room id not generated");
|
| 44 |
expect(user.username).to.equal("test", "didn't set username");
|
| 45 |
});
|
| 46 |
+
|
| 47 |
+
it("should fail to join not existant room", () => {
|
| 48 |
+
ctx.payload.roomId = "testid"
|
| 49 |
+
JoinRoomHandler(ctx);
|
| 50 |
+
const resData = (ws.sendData as string);
|
| 51 |
+
const res = JSON.parse(resData);
|
| 52 |
+
expect(res.message).to.eq("join_room_response", "didn't get server response");
|
| 53 |
+
const roomNowExists = server.rooms["testid"]
|
| 54 |
+
expect(roomNowExists).to.equal(undefined, "server allowed to join non-existant room");
|
| 55 |
+
});
|
| 56 |
|
| 57 |
it("should join existing room", () => {
|
| 58 |
testJoinRoom(1); // Initial user joins and creates room
|
server/test/socket/routes/send_touch.spec.ts
CHANGED
|
@@ -24,13 +24,13 @@ describe("Send Vibration", () => {
|
|
| 24 |
ctx = {
|
| 25 |
ws: ws,
|
| 26 |
user: user,
|
| 27 |
-
payload: { username: "test"
|
| 28 |
server: server,
|
| 29 |
};
|
| 30 |
ctx2 = {
|
| 31 |
ws: ws2,
|
| 32 |
user: user2,
|
| 33 |
-
payload: { username: "test2"
|
| 34 |
server: server,
|
| 35 |
};
|
| 36 |
|
|
@@ -54,6 +54,8 @@ describe("Send Vibration", () => {
|
|
| 54 |
|
| 55 |
it("should broadcast vibration", () => {
|
| 56 |
JoinRoomHandler(ctx)
|
|
|
|
|
|
|
| 57 |
JoinRoomHandler(ctx2)
|
| 58 |
ws.sendData = "";
|
| 59 |
ws2.sendData = "";
|
|
|
|
| 24 |
ctx = {
|
| 25 |
ws: ws,
|
| 26 |
user: user,
|
| 27 |
+
payload: { username: "test" },
|
| 28 |
server: server,
|
| 29 |
};
|
| 30 |
ctx2 = {
|
| 31 |
ws: ws2,
|
| 32 |
user: user2,
|
| 33 |
+
payload: { username: "test2" },
|
| 34 |
server: server,
|
| 35 |
};
|
| 36 |
|
|
|
|
| 54 |
|
| 55 |
it("should broadcast vibration", () => {
|
| 56 |
JoinRoomHandler(ctx)
|
| 57 |
+
const resData = JSON.parse(ws.sendData as string)
|
| 58 |
+
ctx2.payload.roomId = resData.roomId
|
| 59 |
JoinRoomHandler(ctx2)
|
| 60 |
ws.sendData = "";
|
| 61 |
ws2.sendData = "";
|