Skip to content

Conversation

@Junaid2003
Copy link

Updated the code with react router v6

Updated the code with react router v6
@Junaid2003
Copy link
Author

//updated server.js file to latest so that it can work in 2023 hope you can accept pull request. I was not able to commit server.js file so i have pasted the code below.
const express = require("express");
const http = require("http");
const app = express();
const server = http.createServer(app);
const socket = require("socket.io");
const io = socket(server);

const rooms = {};

io.on("connection", socket => {
socket.on("join room", roomID => {
if (rooms[roomID]) {
rooms[roomID].push(socket.id);
} else {
rooms[roomID] = [socket.id];
}
const otherUser = rooms[roomID].find(id => id !== socket.id);
if (otherUser) {
socket.emit("other user", otherUser);
socket.to(otherUser).emit("user joined", socket.id);
}
});

socket.on("offer", payload => {
    io.to(payload.target).emit("offer", payload);
});

socket.on("answer", payload => {
    io.to(payload.target).emit("answer", payload);
});

socket.on("ice-candidate", incoming => {
    io.to(incoming.target).emit("ice-candidate", incoming.candidate);
});

});

server.listen(8000, () => console.log('server is running on port 8000'));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant