You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
948 B
JavaScript

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'); //console log if a user connceted
socket.on('picture', (line) => { //if the message "picture" comes it will do this function. the message is called line
console.log(line); //logs the incoming message called line
socket.broadcast.emit("dingdong",line); //it broadcasts it to the other connected clients https://socket.io/docs/v4/tutorial/step-5
});
socket.on('disconnect', () => {
console.log('user disconnected');
});
});
server.listen(3000, () => { //if you would like to change the port change the number
console.log('listening on *:3000');
});