Skip to content

Commit bc90b55

Browse files
authored
Merge pull request #43 from CS3219-AY2425S1/collab-space-patch
Fix cross browser code collaboration issue
2 parents 48f4977 + 75e2610 commit bc90b55

File tree

4 files changed

+20
-6
lines changed

4 files changed

+20
-6
lines changed

Backend/CollabService/Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,6 @@ RUN npm install
88
COPY . .
99

1010
EXPOSE 3004
11+
EXPOSE 1234
12+
1113
CMD ["npm", "start"]

Backend/CollabService/app.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ const { setUpYjsSocket } = require('./websocket/collabSocket');
55
const app = express();
66

77
const server = http.createServer(app);
8-
const yjsPORT = 1234
8+
9+
// Set up Yjs server
10+
setUpYjsSocket();
911

1012
// Set up WebSocket server and attach to HTTP server
1113
setupWebSocket(server);
12-
setUpYjsSocket(yjsPORT);
14+
1315

1416
// Basic route to test the server
1517
app.get('/', (req, res) => {
Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
11
const WebSocket = require('ws');
2+
const http = require('http')
3+
const { setupWSConnection } = require('y-websocket/bin/utils');
24

3-
function setUpYjsSocket(port) {
4-
const wss = new WebSocket.Server({ port: 1234 });
5+
function setUpYjsSocket() {
56

6-
wss.on('connection', (ws) => {
7+
const server = http.createServer();
8+
9+
const wss = new WebSocket.Server({ server });
10+
11+
wss.on('connection', (ws, req) => {
712
console.log('New client connected');
813

14+
setupWSConnection(ws, req);
15+
916
ws.on('close', () => {
1017
console.log('Client disconnected');
1118
});
1219
});
1320

14-
console.log('Websocket server is listening on ws://localhost:1234')
21+
server.listen(1234, () => {
22+
console.log('Websocket server is listening on ws://localhost:1234')
23+
})
1524
}
1625

1726
module.exports = { setUpYjsSocket };

docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ services:
2626
dockerfile: Dockerfile
2727
ports:
2828
- "3004:3004" # change the first port number xxxx:3004 to suit your needs
29+
- "1234:1234"
2930

3031
frontend:
3132
build:

0 commit comments

Comments
 (0)