From 93d03e04414881dbbcd9c296aea236827a5ae636 Mon Sep 17 00:00:00 2001 From: joak Date: Tue, 6 Feb 2024 09:37:15 +0100 Subject: [PATCH] init commit --- .gitignore | 2 ++ index.js | 25 +++++++++++++++ package.json | 9 ++++++ public/index.html | 81 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 117 insertions(+) create mode 100644 .gitignore create mode 100644 index.js create mode 100644 package.json create mode 100644 public/index.html diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6fb3f7e --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +node_modules/* +package-lock.json diff --git a/index.js b/index.js new file mode 100644 index 0000000..7547ad4 --- /dev/null +++ b/index.js @@ -0,0 +1,25 @@ +const express = require('express'); +const app = express(); +const http = require('http'); +const server = http.createServer(app); +const { Server } = require("socket.io"); +const io = new Server(server); + +app.use(express.static('public')); + +io.on('connection', (socket) => { + console.log('a user connected'); + + socket.on('draw', (line) => { + console.log(line); + socket.broadcast.emit("draw",line); + }); + + socket.on('disconnect', () => { + console.log('user disconnected'); + }); +}); + +server.listen(3000, () => { + console.log('listening on *:3000'); +}); diff --git a/package.json b/package.json new file mode 100644 index 0000000..058184c --- /dev/null +++ b/package.json @@ -0,0 +1,9 @@ +{ + "name": "collective drawing on canvas", + "version": "0.0.1", + "description": "lets draw together", + "dependencies": { + "express": "^4.18.2", + "socket.io": "^4.7.4" + } +} diff --git a/public/index.html b/public/index.html new file mode 100644 index 0000000..5c48a31 --- /dev/null +++ b/public/index.html @@ -0,0 +1,81 @@ + + + + untitled + + + + + + + Width: + Color: + + + +