Skip to content

Commit adc452f

Browse files
authored
Fix connection between FE and Yjs (#133)
* Install ESLint for Github Action * Fix issue connecting to yjs from fe
1 parent e7b0fdc commit adc452f

File tree

5 files changed

+26
-15
lines changed

5 files changed

+26
-15
lines changed

.github/workflows/docker-build-push-gcloud.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,5 @@ jobs:
4141
4242
# Build and push the Docker image
4343
echo "Building and pushing image for $service..."
44-
docker buildx build --platform linux/amd64 -t $IMAGE_NAME -f ./backend/$service/Dockerfile ./backend/$service --push
44+
docker build --platform linux/amd64 -t $IMAGE_NAME -f ./backend/$service/Dockerfile ./backend/$service --push
4545
done

backend/y-websocket-service/src/yjs.gateway.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,18 @@ export class YjsGateway implements OnGatewayConnection, OnGatewayDisconnect {
2929

3030
async handleConnection(client: WebSocket, request: Request) {
3131
try {
32+
console.log('New connection:', request.url);
3233
const url = new URL(request.url, 'http://${request.headers.host}');
3334
const sessionId = url.searchParams.get('sessionId');
34-
// roomId is appended to the end of the URL like so /yjs?sessionId=123&userId=456/roomId789
35-
// Thus the reason to split the userIdParam by '/' to get the userId and roomId
36-
// Very hacky. App might break if param order changes
3735
const userIdParam = url.searchParams.get('userId');
38-
const userId = userIdParam.split('/')[0];
39-
const roomId = userIdParam.split('/')[1];
4036

41-
setupWSConnection(client, request, { docName: roomId, gc: true });
37+
if (!userIdParam || !userIdParam.includes('/')) {
38+
console.error('Invalid user ID parameter');
39+
client.close(1008, 'Invalid user ID parameter');
40+
return;
41+
}
42+
43+
const [userId, roomId] = userIdParam.split('/');
4244

4345
if (!sessionId) {
4446
console.error('No session ID provided');
@@ -52,7 +54,16 @@ export class YjsGateway implements OnGatewayConnection, OnGatewayDisconnect {
5254
return;
5355
}
5456

55-
console.log('Session ID:', sessionId, 'User ID:', userId);
57+
console.log(
58+
'Session ID:',
59+
sessionId,
60+
'User ID:',
61+
userId,
62+
'Room ID:',
63+
roomId,
64+
);
65+
66+
setupWSConnection(client, request, { docName: roomId, gc: true });
5667

5768
const sessionDetails = await this.validateSessionDetails(
5869
sessionId,

frontend/src/app/collaboration/_components/Editor/CollaborativeEditor/CollaborativeEditor.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,10 @@ export default function CollaborativeEditor({
163163
minimap: { enabled: false },
164164
}}
165165
defaultValue={defaultEditorValues[language]}
166-
// value={code[language]}
167-
// onChange={(value) => {
168-
// setCode((prevCode) => ({ ...prevCode, [language]: value || "" }));
169-
// }}
166+
// value={code[language]}
167+
// onChange={(value) => {
168+
// setCode((prevCode) => ({ ...prevCode, [language]: value || "" }));
169+
// }}
170170
/>
171171
</div>
172172
);

frontend/src/app/collaboration/_components/Editor/CollaborativeEditor/CollaborativeEditorTab.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { useSessionContext } from "@/contexts/SessionContext";
55
export default function CollaborativeEditorTab() {
66
const {sessionId, userProfile} = useSessionContext();
77

8-
const socketUrl = process.env.PUBLIC_Y_WEBSOCKET_URL || "ws://localhost:4001";
8+
const socketUrl = process.env.NEXT_PUBLIC_Y_WEBSOCKET_URL || "ws://localhost:4001";
99

1010
if (!userProfile) {
1111
return <div>Loading user profile...</div>;

frontend/src/app/collaboration/_components/Editor/CollaborativeWhiteboard/CollaborativeWhiteboardTab.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import CollaborativeWhiteboard from "./CollaborativeWhiteboard";
22
import { useSessionContext } from "@/contexts/SessionContext";
33

44
export default function CollaborativeEditorTab() {
5-
const {userProfile, sessionId} = useSessionContext()
5+
const { userProfile, sessionId } = useSessionContext()
66

7-
const socketUrl = process.env.PUBLIC_Y_WEBSOCKET_URL || "ws://localhost:4001";
7+
const socketUrl = process.env.NEXT_PUBLIC_Y_WEBSOCKET_URL || "ws://localhost:4001";
88

99
if (!userProfile) {
1010
return <div>Loading user profile...</div>;

0 commit comments

Comments
 (0)