vervallsweg / cast-web-api

Quick and dirty web API for Google Cast enabled devices.
GNU General Public License v3.0
141 stars 74 forks source link

Devices disconnect when my phone goes to sleep #155

Open joymyr opened 2 years ago

joymyr commented 2 years ago

Every time my phone goes to sleep I see messages like this:

1|cast-web-api  | 2022-02-16T11:03:36.594Z 4647135ec8e8308b2a3eef50598bbdf0 CastMedia.disconnect(): host: 192.168.1.186, port: 8009
1|cast-web-api  | 2022-02-16T11:03:36.648Z 4647135ec8e8308b2a3eef50598bbdf0 ReconnectionManager.stop():
1|cast-web-api  | 2022-02-16T11:03:36.671Z 4647135ec8e8308b2a3eef50598bbdf0 removeDevice(): deviceExists: false
1|cast-web-api  | deviceDown: {"id":"2111a3fe16a639b340771fb91d7d2d16","name":"Gangen","address":{"port":8009,"host":"192.168.1.114"},"groups":[]}
1|cast-web-api  | 2022-02-16T11:03:36.704Z 2111a3fe16a639b340771fb91d7d2d16 removeDevice():

And the device call returns an empty list. All devices are still working, and I can ping them.

If I wake my phone up again, I see messages like this within a few seconds:

1|cast-web-api  | 2022-02-16T11:10:50.986Z 2111a3fe16a639b340771fb91d7d2d16 CastDevice.constructor(): autoConnect
1|cast-web-api  | 2022-02-16T11:10:51.008Z 2111a3fe16a639b340771fb91d7d2d16 CastDevice.connect(): connecting
1|cast-web-api  | 2022-02-16T11:10:51.029Z 2111a3fe16a639b340771fb91d7d2d16 CastReceiver.connect(): host: 192.168.1.114, port: 8009
1|cast-web-api  | deviceUp: {"id":"2111a3fe16a639b340771fb91d7d2d16","name":"Gangen","address":{"port":8009,"host":"192.168.1.114","rejectUnauthorized":false},"groups":[]}
1|cast-web-api  | 2022-02-16T11:10:51.145Z 2111a3fe16a639b340771fb91d7d2d16 addDevice():

And the api starts working again.

I guess my phone sends a request that makes the devices broadcast their status which is also picked up by the cast-web-api. Why does the cast-web-api think my devices is disconnected? Is there some way I can make it reconnect automatically or just never disconnect my devices?

BTW the assistant functionality is fully reliable for me, but I prefer the device APIs if only I can make it reliable.