Skip to content

Commit 382c3d0

Browse files
committed
Disable socket disconnection on component unmount
- Send PNotify notification on socket alert responses - Fix missing userType in register
1 parent 04b00ec commit 382c3d0

2 files changed

Lines changed: 26 additions & 16 deletions

File tree

src/app/components/Leaderboard/LeaderboardElement.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -296,10 +296,10 @@ export class LeaderboardElement extends React.Component<
296296
{!(isPlayAgainstDisabled || currentUsername === player.username) ? (
297297
<div
298298
style={{ fontSize: '0.55em', cursor: 'pointer' }}
299-
onClick={(e) => {
299+
onClick={async (e) => {
300300
// hello
301-
updatePlayerId2(player.userId);
302-
updateRequest(Request.MANUAL);
301+
await updatePlayerId2(player.userId);
302+
await updateRequest(Request.MANUAL);
303303
e.stopPropagation();
304304
}}
305305
title={`Start match`}

src/app/components/SocketHandler.tsx

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@ export class SocketHandler extends React.Component<SocketHandlerInterfaces.Props
1414
{},
1515
// @ts-ignore
1616
(frame) => {
17-
// tslint:disable-next-line:no-console
18-
console.log('Success call back console log', frame);
19-
const { userId } = this.props;
17+
const { userId, success } = this.props;
18+
success('Connected to Server.');
2019
// @ts-ignore
2120
this.stompClient.subscribe(
2221
`/socket/response/alert/${userId}`,
@@ -29,9 +28,13 @@ export class SocketHandler extends React.Component<SocketHandlerInterfaces.Props
2928
this.stompClient.subscribe(
3029
`/socket/response/match/${userId}`,
3130
(message: { body: string }) => {
32-
// @ts-ignore
33-
// tslint:disable-next-line: no-console
34-
console.log('Received match object', message.body);
31+
if (message.body[0] === 'E') {
32+
this.props.error('Match not executed successfully');
33+
this.props.updateGameLog(message.body, message.body, '');
34+
return;
35+
}
36+
37+
this.props.success('Match executed successfully');
3538

3639
const matchDetails = {
3740
matchPlayerId: '',
@@ -103,9 +106,15 @@ export class SocketHandler extends React.Component<SocketHandlerInterfaces.Props
103106
}
104107

105108
public componentDidUpdate() {
106-
// tslint:disable-next-line: no-console
107-
const { request, mapId, playerId1, playerId2, commitHash, updateRequest, userId } = this.props;
108-
// tslint:disable-next-line: no-console
109+
const {
110+
request,
111+
mapId,
112+
playerId2,
113+
commitHash,
114+
currentAiId,
115+
updateRequest,
116+
userId,
117+
} = this.props;
109118
switch (request) {
110119
case SubmissionInterfaces.Request.PREVIOUS_COMMIT_MATCH: {
111120
// tslint:disable-next-line: no-console
@@ -137,9 +146,9 @@ export class SocketHandler extends React.Component<SocketHandlerInterfaces.Props
137146
// tslint:disable-next-line: no-console
138147
console.log('INITIATING MATCH:SELF_MATCH');
139148
this.initiateMatch(
140-
playerId1,
149+
userId,
141150
playerId2,
142-
SubmissionInterfaces.Request.SELF_MATCH,
151+
SubmissionInterfaces.Request.MANUAL,
143152
mapId,
144153
commitHash,
145154
);
@@ -159,8 +168,9 @@ export class SocketHandler extends React.Component<SocketHandlerInterfaces.Props
159168
}
160169
}
161170

162-
public componentWillUnmount() {
163-
this.socket.disconnect();
171+
public componentWillUnmount(): void {
172+
// @ts-ignore
173+
// this.stompClient.disconnect();
164174
}
165175

166176
public render() {

0 commit comments

Comments
 (0)