I have a problem where my rails server cannot detect when the client device is turned off. I have my software designed as below:
- Server: Using Rails ActionCable for websocket connection. Using redis as an adapter..
- Client: NodeJS server running on facial recognition device. I'm using
ws
npm package for web socket connection. It acts as a client and subscribe to Rails ActionCable.
The ActionCable subscription and unsubscription is working well and data can also be sent between client and server. Inside my device_channel.rb,
# below method is called when my client wants to subscribe
def subscribed
# do necessary updates based on successful subscription
...
end
# below method is called when I purposely close websocket connection or stop NodeJS server
def unsubscribed
# do necessary updates based on successful unsubscription
...
end
Right now the problem comes when I power off the device. In this scenario, websocket connection is not closed from client or NodeJS is not stopped before the device's power is cut off. So, unsubscribed
method in my rails server is not triggered and I cannot do necessary updates.
So, is there any way that I can check active ActionCables in rails? If there is, I can do this checking and do updates accordingly when user tries to access the device status page. Right now, the device is still shown as online on the page even though it's already powered off.