Skip to content

Commit 1c02c06

Browse files
committed
import socket.js
1 parent 65b2f8a commit 1c02c06

File tree

4 files changed

+10
-3
lines changed

4 files changed

+10
-3
lines changed

api/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ app.get('/test', (req, res) => {
2626
res.send(JSON.stringify({ok: true}));
2727
})
2828

29-
io.on('connection', (socket)=>{
29+
io.on('connection', (socket) => {
3030
console.log('user connected socket')
3131
socket.on('draw', (data)=>{
3232
socket.broadcast.emit('draw', data);
3333
})
34-
socket.on('clear', ()=>{
34+
socket.on('clear', () => {
3535
io.emit('clear');
3636
})
3737
})

client/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@
99
<body>
1010
<div id="root"></div>
1111
<script type="module" src="/src/main.jsx"></script>
12+
<script src="./src/socket.js"></script>
1213
</body>
1314
</html>

client/src/App.jsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { useEffect, useRef, useState } from "react";
33
import "./App.css";
44
import * as Y from "yjs";
55
import { SocketIOProvider } from "y-socket.io";
6-
import socket from "./Socket";
6+
import socket from "./socket";
77

88
import Sidebar from "./components/Sidebar";
99
import Canvas from "./components/Canvas";
@@ -22,6 +22,8 @@ import {
2222
textEditorInput
2323
} from "./atoms";
2424

25+
socket.connect();
26+
2527
function App() {
2628
const [showMenu, setShowMenu] = useRecoilState(showMenuState);
2729
const eraserMode = useRecoilValue(eraserState);

client/src/Socket.js renamed to client/src/socket.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,8 @@ const PORT = "http://localhost:8000";
44

55
const socket = io(PORT);
66

7+
socket.on("connect", () => {
8+
console.log("connected");
9+
});
10+
711
export default socket;

0 commit comments

Comments
 (0)