peerjs icon indicating copy to clipboard operation
peerjs copied to clipboard

on("error") callback function is never executed.

Open allanbbs opened this issue 3 years ago • 4 comments

I'm currently using npm peerjs with webpack. When testing error handling , I found out that error (fatal and non-fatal) error would not execute the defined callback function. The console would log something like : "ERROR PeerJS : ...." and the callback code would not have been executed. I tested this both on Chrome and IE. Can anyone give me some directions?

allanbbs avatar Aug 23 '22 14:08 allanbbs

Hey @allanbbs,

Thank you for the report. How do you provoke the error? Can you post some logs (with {debug: 3}) and/or something to reproduce this?

jonasgloning avatar Sep 06 '22 09:09 jonasgloning

Hi @jonasgloning, It seems like I have the same problem. It seems that an 'error' event handler attached to a PeerConnection object is not triggered in case that the connection between two peers gets suddenly lost. Sample code:

let conn = peer.connect(senderId, { reliable: true });
conn.on('open', () => {
    // ...
    conn.on('data', (data) => {
        // ...
    });
});
// ...
conn.on('close', () => {
    // ...
});
conn.on('error', (err) => {
    // This apparently is not executed!
});

I provoked a connection error by closing the browser window while data was being transferred between two peers. The receiver stopped receiving the data but the error event handler was not invoked.

Has this problem been fixed in the meantime or is this still an open issue?

Would be grateful for any support on this!

nikur avatar May 29 '24 11:05 nikur

I found the following comment in the CHANGELOG.md file: Connections no longer emit errors from PeerConnection; PeerConnection errors are now forwarded to the Peer object.

This dates back to version 0.2.0 which was released on 2013-03-24. It sounds like the 'error' event is not triggered by PeerConnection objects anymore but instead the 'error' handler of the corresponding Peer object is invoked instead. However, the 'error' event is still listed in the official API documentation for PeerConnections and I didn't observe the Peer's error handler being called when the connection got lost.

nikur avatar May 29 '24 12:05 nikur

Problem persists in version 1.5.4. Neither the 'error' handler of the PeerConnection nor the one of the Peer object is called. Maybe a duplicate of #626.

nikur avatar May 29 '24 13:05 nikur