react-native-peerjs
react-native-peerjs copied to clipboard
Could not connect to the local peerjs server
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
same problem.. did you found how resolve this?
Facing the same issue! Any news on that?