Skip to content

Commit

Permalink
Video Chat App completed
Browse files Browse the repository at this point in the history
v1.3 All error solved related to connection
  • Loading branch information
AyushSatyam committed Jul 1, 2021
1 parent 9ace654 commit 85834a2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
5 changes: 3 additions & 2 deletions clients/src/components/Notification.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ const Notifications = () => {
const { answerCall, call, callAccepted } = useContext(SocketContext);

return (
<>
<div>
{console.log(call.isReceivingCall)}
{call.isReceivingCall && !callAccepted && (
<div style={{ display: "flex", justifyContent: "space-around" }}>
<h1>{call.name} is calling:</h1>
Expand All @@ -16,7 +17,7 @@ const Notifications = () => {
</Button>
</div>
)}
</>
</div>
);
};

Expand Down
4 changes: 1 addition & 3 deletions clients/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import App from "./App";
import { ContextProvider } from "./SocketContext";
ReactDOM.render(
<ContextProvider>
<React.Fragment>
<App />
</React.Fragment>
<App />
</ContextProvider>,
document.getElementById("root")
);
Expand Down
22 changes: 13 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const app = require("express")();
const server = require("http").createServer(app);
const cors = require("cors");

const io = require("socket.io")(server, {
cors: {
origin: "*",
Expand All @@ -9,24 +10,27 @@ const io = require("socket.io")(server, {
});

app.use(cors());

const PORT = process.env.PORT || 5000;

app.get("/", (req, res) => {
res.send("The server is running");
res.send("Running");
});

io.on("connection", (socket) => {
socket.emit("me", socket.id);

socket.on("disconnect", () => {
socket.broadcast.emit("callend");
socket.broadcast.emit("callEnded");
});
socket.on("calluser", ({ userTocall, signalData, from, name }) => {
io.to(userTocall).emit("calluser", { signal: signalData, from, name });

socket.on("callUser", ({ userToCall, signalData, from, name }) => {
io.to(userToCall).emit("callUser", { signal: signalData, from, name });
});

socket.on("answercall", (data) => {
io.to(data.io).emit("callaccepted", data.signal);
socket.on("answerCall", (data) => {
io.to(data.to).emit("callAccepted", data.signal);
});
});
server.listen(PORT, () => {
console.log(`The server listening on port ${PORT}`);
});

server.listen(PORT, () => console.log(`Server is running on port ${PORT}`));

0 comments on commit 85834a2

Please sign in to comment.