-1

Is it possible to execute functions when server is connected/disconnected? Principally to give user information about connection status.

Ivan Kalashnik
  • 411
  • 7
  • 12

1 Answers1

0
gun.on('hi', peer => console.log(peer));

and

gun.on('bye', peer => console.log(peer));

You can create a presence system with gun, by having users ping their account with a heartbeat of when they were last online. You can then have other peers subscribe to these heartbeats to see if they are online.

If you are okay with building centralized server logic (I encourage people to build P2P/decentralized apps, instead, though), you could do something similar to what is suggested on the Firebase shim page:

https://gun.eco/docs/shim.js

Ivan Kalashnik
  • 411
  • 7
  • 12