wip testing voice and video chat
This commit is contained in:
parent
c9d8959d21
commit
61f2a2c674
2 changed files with 48 additions and 4 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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 }) =>
|
||||
|
|
|
|||
Loading…
Reference in a new issue