Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could not connect to the local peerjs server #27

Open
nikita-zot-1408 opened this issue Jun 8, 2021 · 2 comments
Open

Could not connect to the local peerjs server #27

nikita-zot-1408 opened this issue Jun 8, 2021 · 2 comments

Comments

@nikita-zot-1408
Copy link

This is what I am trying to do:

 const callUser = id => {
    const peer = new Peer({initiator: true, trickle: false, stream});

    console.log(stream);

    peer.on('error', console.log);
    peer.on('connect', console.log);

    peer.on('signal', data => {
      console.log('data', data);
      socket.emit('callUser', {
        userToCall: id,
        signalData: data,
        from: me,
        name,
      });
    });

This function does not show nor error message,nor success message.

But on top of the component I have tried to call peerServer like this:

const peerServer = new Peer({
  host: 'https://0.0.0.0',
  secure: false,
  port: 8080,
  path: '/mypeer',
});

peerServer.on('error', console.log);

And it constantly returned: Could not get User Id error.

This is my code for server:

const app = require("express")();
const server = require("http").createServer(app);
const cors = require("cors");

const { ExpressPeerServer } = require("peer");

const io = require("socket.io")(server, {
  cors: {
    origin: "*",
    methods: ["GET", "POST"],
  },
});

const env = require("dotenv").config();

const customGenerationFunction = () =>
  (Math.random().toString(36) + "0000000000000000000").substr(2, 16);

app.use(cors());

app.get("/hello", (req, res) => {
  res.send("hello from the other siiiiiiide");
});

const peerServer = ExpressPeerServer(server, {
  debug: true,
  path: "/",
  generateClientId: customGenerationFunction,
});

app.use("/mypeer", peerServer);

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

  console.log("connected", socket.id);

  socket.on("disconnect", () => {
    socket.broadcast.emit("callEnded");
  });

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

  socket.on("answerCall", (data) => {
    io.to(data.to).emit("callAccepted", data.signal);
  });
});

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

Any suggestions please? Following code of server works perfectly on web.

I am using Linux Mint latest version.

Android emulator latest version Emulator: Pixel 4

@evgromov
Copy link

evgromov commented Jun 9, 2021

same problem.. did you found how resolve this?

@marcjulianfleck
Copy link

marcjulianfleck commented Sep 9, 2021

Facing the same issue! Any news on that?

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

No branches or pull requests

3 participants