alxhotel / chromecast-api

:tv: Chromecast Node.js module
MIT License
155 stars 49 forks source link

Timeout Error for a device not on my network #74

Open macharborguy opened 3 years ago

macharborguy commented 3 years ago

I have a barebones script based off of the example code in the README, a simple listener on the client that listens for the device event, and a console.log that prints out the resulting device objects.

After a few moments, i receive an Unhandled Error event showing a timeout while waiting for a response from 192.168.1.2. After checking my NetGear Nighthawk router's connected devices screen, it shows that there is no device on that IP address. There is also no events available for me to listen for and handle this event, and the app simply crashes.

events.js:353
      throw er; // Unhandled 'error' event
      ^

Error: connect ETIMEDOUT 192.168.1.2:8060
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1146:16)
Emitted 'error' event on ClientRequest instance at:
    at Socket.socketErrorListener (_http_client.js:475:9)
    at Socket.emit (events.js:376:20)
    at emitErrorNT (internal/streams/destroy.js:106:8)
    at emitErrorCloseNT (internal/streams/destroy.js:74:3)
    at processTicksAndRejections (internal/process/task_queues.js:82:21) {
  errno: -4039,
  code: 'ETIMEDOUT',
  syscall: 'connect',
  address: '192.168.1.2',
  port: 8060
}

here is the code for my script. Like I said, super simple...

const ChromecastAPI = require('chromecast-api')
const Client = new ChromecastAPI()
Client.on('device',(device)=>{
    console.log('device ', device)
})

Before the error is emitted and the app crashes, it does fine all of the Chromecasts, Nest Hubs and Cast Groups on my network. The app just doesnt run long enough for me to really do anything

macharborguy commented 3 years ago

Just as a follow up, i ran the same code on my Raspberry Pi 4B, and i received a different error. Still a connection error to 192.168.1.2, but this time the following...

node:events:368
      throw er; // Unhandled 'error' event
      ^

Error: connect EHOSTUNREACH 192.168.1.2:8060
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1161:16)
Emitted 'error' event on ClientRequest instance at:
    at Socket.socketErrorListener (node:_http_client:447:9)
    at Socket.emit (node:events:390:28)
    at emitErrorNT (node:internal/streams/destroy:157:8)
    at emitErrorCloseNT (node:internal/streams/destroy:122:3)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  errno: -113,
  code: 'EHOSTUNREACH',
  syscall: 'connect',
  address: '192.168.1.2',
  port: 8060
}
VuHoangNgo commented 3 years ago

Having the same issue, when a chromecast disconnects for any reason and I try to send a play command, I get this error after a while. Is there any way to catch this error? try/catch around play is not working in my that case.

Cheers

travisghansen commented 3 weeks ago

Anyone ever find a solution to this issue to prevent the app from blowing up?