Skip to content

Commit ab77ba5

Browse files
authored
Merge pull request #134 from Lemoncode/bug/fix-duplicated-room
refactor get initial content when establish connection
2 parents e0ead48 + e22a062 commit ab77ba5

8 files changed

Lines changed: 8 additions & 70 deletions

File tree

‎back/src/pods/messages/messages.consts.ts‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,13 @@ export const InputMessageTypes = {
44
TRAINER_APPEND_TEXT: 'TRAINER_APPEND_TEXT',
55
TRAINER_SET_FULL_TEXT: 'TRAINER_SET_FULL_TEXT',
66
TRAINER_SAVE_CONTENT: 'TRAINER_SAVE_CONTENT',
7-
TRAINER_REQUEST_FULL_CONTENT: 'TRAINER_REQUEST_FULL_CONTENT',
8-
STUDENT_REQUEST_FULL_CONTENT: 'STUDENT_REQUEST_FULL_CONTENT',
97
};
108

119
export const OutputMessageTypes = {
1210
CONNECTION_ESTABLISHED_TRAINER: 'CONNECTION_ESTABLISHED_TRAINER',
1311
CONNECTION_ESTABLISHED_STUDENT: 'CONNECTION_ESTABLISHED_STUDENT',
1412
ERROR_MULTI_TRAINER_NOT_IMPLEMENTED_YET: 'ERROR_MULTI_TRAINER_NOT_IMPLEMENTED_YET',
1513
APPEND_TEXT: 'APPEND_TEXT',
16-
TRAINER_SEND_FULL_CONTENT: 'TRAINER_SEND_FULL_CONTENT',
17-
STUDENT_SEND_FULL_CONTENT: 'STUDENT_SEND_FULL_CONTENT',
1814
UPDATE_FULL_CONTENT: 'UPDATE_FULL_CONTENT',
1915
};
2016

‎back/src/pods/messages/processors/input-processor.ts‎

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,6 @@ export const processInputMessage = async (
4141
InputMessageTypes.TRAINER_SET_FULL_TEXT
4242
);
4343
break;
44-
case InputMessageTypes.STUDENT_REQUEST_FULL_CONTENT:
45-
outputActionCollection = await handleRequestGetStudentContent();
46-
break;
47-
case InputMessageTypes.TRAINER_REQUEST_FULL_CONTENT:
48-
outputActionCollection = await handleRequestGetTrainerContent();
49-
break;
5044
default:
5145
break;
5246
}
@@ -135,11 +129,3 @@ const handleTrainerSendText = async (
135129
return [];
136130
}
137131
};
138-
139-
const handleRequestGetStudentContent = async (): Promise<Action[]> => {
140-
return [{ type: OutputMessageTypes.STUDENT_SEND_FULL_CONTENT }];
141-
};
142-
143-
const handleRequestGetTrainerContent = async (): Promise<Action[]> => {
144-
return [{ type: OutputMessageTypes.TRAINER_SEND_FULL_CONTENT }];
145-
};

‎back/src/pods/messages/processors/output-processor.ts‎

Lines changed: 8 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,6 @@ export const processOuputMessage = async (
3535
case OutputMessageTypes.UPDATE_FULL_CONTENT:
3636
await handleUpdateFullContent(socketInfo);
3737
break;
38-
case OutputMessageTypes.STUDENT_SEND_FULL_CONTENT:
39-
await handleSingleStudentSendFullContent(socketInfo);
40-
break;
41-
case OutputMessageTypes.TRAINER_SEND_FULL_CONTENT:
42-
await handleTrainerSendFullContent(socketInfo);
43-
break;
4438
default:
4539
break;
4640
}
@@ -49,23 +43,21 @@ export const processOuputMessage = async (
4943
const handleNotifyConnectionEstablishedTrainer = async (
5044
socketInfo: SocketInfo
5145
) => {
52-
const room = await sessionRepository.getRoomFromConnectionId(
53-
socketInfo.connectionId
46+
await handleSendFullContent(
47+
socketInfo,
48+
responseType.TRAINER_GET_FULL_CONTENT,
49+
false
5450
);
55-
const response: ResponseBase = { type: responseType.CONNECTION_ACK };
56-
socketInfo.socket.in(room).emit(SocketOuputMessageLiteral.MESSAGE, response);
5751
};
5852

5953
const handleNotifyConnectionEstablishedStudent = async (
6054
socketInfo: SocketInfo
6155
) => {
62-
const room = await sessionRepository.getRoomFromConnectionId(
63-
socketInfo.connectionId
56+
await handleSendFullContent(
57+
socketInfo,
58+
responseType.STUDENT_GET_FULL_CONTENT,
59+
false
6460
);
65-
const response: ResponseBase = {
66-
type: responseType.CONNECTION_ACK,
67-
};
68-
socketInfo.socket.in(room).emit(SocketOuputMessageLiteral.MESSAGE, response);
6961
};
7062

7163
const handleAppendText = async (socketInfo: SocketInfo, text: string) => {
@@ -86,22 +78,6 @@ const handleUpdateFullContent = async (socketInfo: SocketInfo) => {
8678
);
8779
};
8880

89-
const handleSingleStudentSendFullContent = async (socketInfo: SocketInfo) => {
90-
await handleSendFullContent(
91-
socketInfo,
92-
responseType.STUDENT_GET_FULL_CONTENT,
93-
false
94-
);
95-
};
96-
97-
const handleTrainerSendFullContent = async (socketInfo: SocketInfo) => {
98-
await handleSendFullContent(
99-
socketInfo,
100-
responseType.TRAINER_GET_FULL_CONTENT,
101-
false
102-
);
103-
};
104-
10581
const handleSendFullContent = async (
10682
socketInfo: SocketInfo,
10783
responseType: string,

‎front/src/common-app/index.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
export * from './session-content';
21
export * from './components/appbar';
32
export * from './components/footer';

‎front/src/common-app/session-content.ts‎

Lines changed: 0 additions & 7 deletions
This file was deleted.

‎front/src/core/const.ts‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ export const SocketOuputMessageLiteral = {
88
export const SocketEmitMessageTypes = {
99
TRAINER_APPEND_TEXT: 'TRAINER_APPEND_TEXT', // Trainer add new text
1010
TRAINER_SET_FULL_TEXT: 'TRAINER_SET_FULL_TEXT', // Trainer send full session text
11-
TRAINER_REQUEST_FULL_CONTENT: 'TRAINER_REQUEST_FULL_CONTENT', // Trainer checks if there's previous session content when connecting
12-
STUDENT_REQUEST_FULL_CONTENT: 'STUDENT_REQUEST_FULL_CONTENT', // Student checks if there's previous session content when connecting
1311
};
1412

1513
export const SocketReceiveMessageTypes = {

‎front/src/pods/student/student.container.tsx‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
} from 'core';
88
import { useLog } from 'core';
99
import { StudentComponent } from './student.component';
10-
import { getPreviousSessionContent } from 'common-app';
1110
import { useParams } from 'react-router-dom';
1211

1312
interface Params {
@@ -42,10 +41,6 @@ export const StudentContainer = () => {
4241
}
4342
}
4443
});
45-
getPreviousSessionContent(
46-
socket,
47-
SocketEmitMessageTypes.STUDENT_REQUEST_FULL_CONTENT
48-
);
4944
};
5045

5146
React.useEffect(() => {

‎front/src/pods/trainer/trainer.container.tsx‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {
1111
import { useLog } from 'core';
1212
import { TrainerComponent } from './trainer.component';
1313
import { useWithRef, getHostBaseUrl } from 'common';
14-
import { getPreviousSessionContent } from 'common-app';
1514

1615
interface Params {
1716
token: string;
@@ -46,10 +45,6 @@ export const TrainerContainer = () => {
4645
}
4746
}
4847
});
49-
getPreviousSessionContent(
50-
socket,
51-
SocketEmitMessageTypes.TRAINER_REQUEST_FULL_CONTENT
52-
);
5348
};
5449

5550
React.useEffect(() => {

0 commit comments

Comments
 (0)