Connection lost azure webpubsub socketio / nodejs

Koen Bonenkamp 5 Reputation points
2024-05-02T10:29:53.2366667+00:00

After some inactivity (e.g. computer goes into sleep modus) the connection to azure socket io hub gets lost. My express server functions normally so http requests are served but clients can't connect to the hub anymore as they get the message there is no backend service connected to the hub.
How can I prevent this loss of connection or at least automatically reconnect when it happens? I tried to listen to disconnect events but they are not triggered when the connection gets lost.

const httpServer = createServer(app)
export let io
async function main() {
  const socketIOAzure = require('socket.io')
  io = await socketIOAzure(httpServer).useAzureSocketIO({ hub, connectionString })
  io.httpServer.listen(port, () => log({ level: 'info', message: `Server is running on port ${port}` }))
}
main()
Azure Web PubSub
Azure Web PubSub
An Azure service that provides real-time messaging for web applications using WebSockets and the publish-subscribe pattern.
79 questions
Azure Startups
Azure Startups
Azure: A cloud computing platform and infrastructure for building, deploying and managing applications and services through a worldwide network of Microsoft-managed datacenters.Startups: Companies that are in their initial stages of business and typically developing a business model and seeking financing.
484 questions
{count} vote

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.