Skip to content

Commit c31003c

Browse files
authored
Merge pull request #25 from oslabs-beta/Lauren
rejoining bug fix
2 parents 20ec777 + 1a324a2 commit c31003c

File tree

4 files changed

+14
-9
lines changed

4 files changed

+14
-9
lines changed

app/src/components/left/RoomsContainer.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ import {
5656
DeleteContextPayload,
5757
addComponentToContext
5858
} from '../../../src/redux/reducers/slice/contextReducer';
59-
import Canvas from '../components/main/Canvas';
6059

6160
// // for websockets
6261
// // Part - join room and room code functionality
@@ -126,7 +125,8 @@ const RoomsContainer = () => {
126125
});
127126

128127
socket.on('child data from server', (childData: object) => {
129-
console.log('child data received by users', childData);
128+
console.log(`child data received by socket ${socket.id}`, childData);
129+
console.log(socket);
130130
store.dispatch(addChild(childData));
131131
});
132132

app/src/components/main/Canvas.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,9 @@ function Canvas(props: {}): JSX.Element {
231231
contextParam: contextParam
232232
});
233233

234-
console.log('emit addChildAction event is triggered in canvas');
234+
console.log(
235+
`emit addChildAction event is triggered in canvas from ${socket.id}`
236+
);
235237
}
236238
} else if (item.newInstance && item.instanceType === 'Component') {
237239
let hasDiffParent = false;

app/src/helperFunctions/socket.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ import config from '../../../config';
44
let socket = null;
55

66
export const initializeSocket = () => {
7-
if (socket) socket.connect();
8-
if (!socket) {
9-
socket = io(config.API_BASE_URL, { transports: ['websocket'] });
10-
console.log('A user connected');
11-
console.log('socket:', socket);
12-
}
7+
socket = io(config.API_BASE_URL, {
8+
transports: ['websocket'],
9+
// will force new socket connection if re-joining to prevent double emits
10+
forceNew: true
11+
});
12+
console.log('A user connected');
13+
console.log('socket:', socket);
14+
// }
1315
};
1416

1517
// export socket to ensure a single socket instance across the entire app

server/server.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ io.on('connection', (client) => {
182182
if (roomCode) {
183183
//server send the data to everyone in the room
184184
client.to(roomCode).emit('child data from server', childData);
185+
console.log(`client id: ${client.id} sending from server ${childData}`);
185186
}
186187
});
187188

0 commit comments

Comments
 (0)