Does a leave event trigger when a client disconnects from a channel?

Not necessarily, since PubNub detects a leave event when an outstanding http request is closed (i.e. not when a connection is closed). To ensure a leave event triggers, the client can issue a new subscribe request just prior to disconnecting from the channel. In general, join and leave events work as follows:

  • A join event triggers when the first subscribe http request completes (typically with timetoken 0) which returns immediately with the current timetoken.  Subscribing with timetoken > 1000 will block until the first message is received on that channel and then the join event triggers.
  • PubNub servers don't always notice a network loss or other non-graceful disconnects, hence no leave event is fired. Instead, a timeout event is fired after the 320 second period is elapsed.