Skip to content

Commit

Permalink
wip testing voice and video chat
Browse files Browse the repository at this point in the history
  • Loading branch information
pb-coding committed Oct 13, 2023
1 parent c9d8959 commit 61f2a2c
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/config/allowedOrigins.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
const allowedOrigins = ["http://localhost:3000", "https://localhost:3001"];
const allowedOrigins = [
"http://localhost:3000",
"http://localhost:5173",
"http://localhost:3001",
];

export default allowedOrigins;
46 changes: 43 additions & 3 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,49 @@ io.on("connection", (socket: Socket) => {
handleLeaveSession(socket, sessionId);
});

socket.on("signal", (data: any) => {
const { to, signalData } = data;
io.to(to).emit("signal", { from: socket.id, signalData });
socket.on("create-offer", (offerData) => {
const { offerDescription, sessionName } = offerData;

if (!sessionName || sessionName == "")
return console.log("No session name provided");

const clientsInRoom =
io.sockets.adapter.rooms.get(sessionName) || new Set();
clientsInRoom.forEach((clientId) => {
if (clientId !== socket.id) {
io.to(clientId).emit("offer-made", offerDescription);
}
});
});

socket.on("answer-call", (answerData) => {
const { answerDescription, sessionName } = answerData;

if (!sessionName || sessionName == "")
return console.log("No session name provided");

const clientsInRoom =
io.sockets.adapter.rooms.get(sessionName) || new Set();
clientsInRoom.forEach((clientId) => {
if (clientId !== socket.id) {
io.to(clientId).emit("answer-made", answerDescription);
}
});
});

socket.on("ice-candidate", (candidateData) => {
const { candidate, sessionName } = candidateData;

if (!sessionName || sessionName == "")
return console.log("No session name provided");

const clientsInRoom =
io.sockets.adapter.rooms.get(sessionName) || new Set();
clientsInRoom.forEach((clientId) => {
if (clientId !== socket.id) {
io.to(clientId).emit("add-ice-candidate", candidate);
}
});
});

socket.on("new-game", (gameDetails: { sessionId: string }) =>
Expand Down

0 comments on commit 61f2a2c

Please sign in to comment.