-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Server receives CANDIDATE message from client, but never responds to it #864
Comments
I also face this problem. But
But that is maybe the same for you. |
I just debugged the working app, and what I found that it's (peer-client) loggs appears in a different order then mine.
In my project the first two rows appear last, the same as @karmeleon.
Could that be the problem? That socket is not opened in time? |
I think that's it. I have added a few // This does not work.
let peer = new Peer();
peer.connect(id); // This works.
let peer = new Peer();
setTimeout(()=>peer.connect(id), 1000); I have currently a few more |
I think I have solved it now. Wait until function createPeer(id, callback=()=>{}){
let peer = new Peer(id.toLocaleLowerCase());
peer.on('open', (ID:string)=>{
console.log('My peer ID is: ' + ID);
callback();
});
return peer;
}
function host(id) {
let peer = this.createPeer(id, ()=>{
peer.on('connection', (connection)=>{
connection.on('data', (data)=>{
console.log(data);
connection.send('good day?');
});
});
});
}
function client(id) {
let peer = this.createPeer('', ()=>{
const connection = peer.connect(id);
connection.on('open', ()=>{
connection.send('hi!');
connection.on('data', (data)=>{
console.log(data);
connection.send('good day!');
});
});
});
} |
Great find, this fixes the issue for me too! Maybe the docs should be updated to point this out? |
It's probably a bug, because it should works without waiting for the open event(the outgoing messages should be queued). I'll check it and write a test. |
Fixed in the latest beta.
|
I'm closely following the example project by initializing a peer on both the client and the server in my app, then using
peer.on('connection', () => console.log('connection received'))
on the server to listen for connections andpeer.connect(serverId)
on the client to attempt a connection. The client appears to be working correctly, since it sends an offer to the server and outputs a lot of data to the console:Looking in the Network tab of the server's window, I can see that it receives the
CANDIDATE
message and it even logs it to the console, but it doesn't send any response or have any other indication that it cares about the message it received. The server never fires thepeer.on('connection')
event, and the client never fires theconnection.on('open')
event. Both windows are on the same computer, and I've tried Edge, Firefox, and Safari across a Mac and Windows machine and gotten the same results. I'm using a local PeerJS server instance, since when I try to use the public instance the server never receives theCANDIDATE
message.The code for the server starts here, the client's code is here, and you can play with the result live here. I've been at this for hours and have gotten nowhere, so I'd really appreciate any help I can get. Thanks!
EDIT: I should add that years ago this exact same code worked (with the public server, too, and version 1.0.0 of the library), but cloning the old repo again and running it gave the same broken result. I'm fairly confident my own code is working correctly here, so the issue likely lies in either the server, or changes in browsers or the OS that subtly broke something important.
The text was updated successfully, but these errors were encountered: