peerjs
peerjs copied to clipboard
peer.connect not open on some users
I am using peerjs custom server on nodejs and the client is Electron app
const handelPeer = async (peerId: string) => {
const id = `${Math.random().toString(16).slice(2)}_${user?.username
?.replaceAll(' ', '_')
.toString()!}`;
const peer = new Peer(id, {
host: 'xxx.xxxx.xxx',
path: '/peerjs',
secure: true,
});
peer.on('open', () => {
const connection = peer.connect(peerId); // Never called on some users
connection.on('open', async () => {
dataSream.current = await createStream();
callRef.current = peer.call(peerId, dataSream.current);
callRef.current?.on('error', (e) => {
console.log('error', e);
});
callRef.current?.on('close', () => {
cleanUp(connection);
});
});
connection.on('close', () => {
cleanUp(connection);
});
connection.on('error', (e: any) => {
console.log('got connection error', e);
});
});
peer.on('disconnected', () => {
console.log('disconnect');
cleanUp();
});
peer.on('error', (error) => {
cleanUp();
});
};
everything working great but it's not working on some users' devices without errors after debugging I have figured that peer.connect never open even on setTimeOut console.log(connection)