Skip to content
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

peer.reconnect sometimes can't reconnect to server, and won't fire any event #1289

Open
1 task done
UTing1119 opened this issue Jun 26, 2024 · 2 comments
Open
1 task done
Labels
bug unconfirmed not yet verified as an issue

Comments

@UTing1119
Copy link

UTing1119 commented Jun 26, 2024

Please, check for existing issues to avoid duplicates.

  • No similar issues found.

What happened?

hello, I'm using Vue 3 with PeerJS.

"peerjs": "^1.5.4",
"vue": "^3.4.27",
"vite": "^2.9.14",
node version: 18.3.0

I'm creating a application and using free PeerJS server to share screen or camera.
while testing, I try to cut one PC's WiFi down and reopen the WiFi after disconnect event is fired. But reconnect only works sometimes.
after I call reconnect, nothing happens. No event, no connect, no error.

the status which PeerJS offer, like opendestory will stay false. Only disconnect will change to false after I call reconnect.
If I try to recoonect it again, the result wont change.

after I open the debug of server, it shows the steps and we can see it's not get the message:

"try to reconnect..."

PeerJS: Attempting reconnection to server with ID ****
PeerJS: Socket open
// end, no next one

it should be like this

"try to reconnect..."

PeerJS: Attempting reconnection to server with ID ****
PeerJS: Socket open
PeerJS: Server message received: { type: 'OPEN' } // we're missing this one
// next: fire the open event

here is my code

let peerConnection = new Peer()
let reconnectInterval: any
peerConnection.on('open', () => {
  console.log('open')
  if (reconnectInterval) {
    window.clearInterval(reconnectInterval)
    reconnectInterval = undefined
  }
})
peerConnection.on('error', (e) => {
  console.error('peer error, error = ' + e)
})
peerConnection.on('disconnected', (e) => {
  console.error('peer disconnected, error = ' + e + ', ' + new Date())
  if (!reconnectInterval) {
    reconnectInterval = setInterval(() => {
      if (!peerConnection.destroyed && !peerConnection.open) {
        console.log('try to reconnect...')
        try {
          peerConnection.reconnect()
        } catch (e) {
          console.error('reconnect error, error = ' + e)
        }
      }
    }, 5000)
  }
})

does anyone know about this?

How can we reproduce the issue?

No response

What do you expected to happen?

if can't reconnect, it will fire event to try again, and return evey error or fire event.

Environment setup

  • OS: windows 10 / window 11
  • Platform: nodeJS, Vue3
  • Browser: Chrome 126.0.6478.116 、 Chrome 126.0.6478.63

Is this a regression?

No response

Anything else?

No response

@hissinger
Copy link

hissinger commented Oct 13, 2024

hi

I had the same issue.

When a new socket connects before the previous socket is removed during reconnect(), the OPEN message was not sent.

I submitted a PR to the PeerJS server repo. peers/peerjs-server#462

@ogchefi
Copy link

ogchefi commented Oct 21, 2024

PR fix by @hissinger appears to work for me. I was just dealing with this exact issue and wondering why nothing gets called after reconnect. I noticed this when I was switching between wifi networks and checking how my app reacts to it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug unconfirmed not yet verified as an issue
Projects
None yet
Development

No branches or pull requests

3 participants