peerjs-server icon indicating copy to clipboard operation
peerjs-server copied to clipboard

No error when client tries to connect with a non-existing ID

Open chris0203 opened this issue 1 year ago • 2 comments

Please, check for existing issues to avoid duplicates.

  • [x] No similar issues found.

What happened?

When trying to connect a non-existing ID, on error has no fired.

The Peer A

this._peer = new Peer('test', {
    host: 'localhost',
    port: 9000,
    path: '/signaling',
});

The Peer B

this._peer = new Peer({
    host: 'localhost',
    port: 9000,
    path: '/signaling',
});
this.peerConnection = this._peer.connect('abc');
this.peerConnection.on('error', () => {
      console.log('ERROR');
  });

The Signal server return {"type":"EXPIRE","src":"abc","dst":"7ac5c04a-d47a-44f1-95e4-7800b1a72900"} The on error in Peer B should catch the error, but here is nothing catch.

The similar error #127 , but not the same

peerjs version: 1.5.4 peer signal server version: 1.0.2

How can we reproduce the issue?

No response

What do you expected to happen?

The on error in Peer B should catch the error

Environment setup

  • OS: Windows 10
  • Platform: Electron 30.0.1

Is this a regression?

No response

Anything else?

No response

chris0203 avatar Dec 10 '24 10:12 chris0203

@chris0203 Did you find a solution to this or yet?

fr13nd230 avatar Jan 21 '25 20:01 fr13nd230

Unfortunately, that's how the client library works for now. See https://github.com/peers/peerjs/issues/924

You can catch this in your example with:

this._peer.on('error', () => { /* handle expire error */ }) 

I am prototyping a lightweight peer.js client with promise handling, tinypeer. It can still interop with the Peer.js signalling servers.

The client would allow this.

import { createPeer } from 'tinypeer';

const peer = await createPeer();

const nonExistentPeerId = `nonexistent-peer-${Math.floor(
  Math.random() * 1000
)}`;

try {
  await peer.connect(nonExistentPeerId);
} catch (err) {
  console.error(err);
}

jamsinclair avatar Oct 21 '25 03:10 jamsinclair