0

I am using openfire for chat application in iOs and php website. and everything is working fine.

I have also implemented push notifications when opponent user is offline and you are sending a message to that user (in short push notification for offline message). I have implemented above stuff which is available here : Openfire offline notification through PHP

Now, client asks me to implement one more feature which includes :

  • Send mail to admin when any user goes offline.

But now there is no any hook available to track user status. So how to implement the same ?

What I tried

I also tried one trick in which I am sending broadcast message to all users and if any user is offile then my CallbackOnOffline plugin will invoke, but here its not sending broadcast message to offline users.

Community
  • 1
  • 1
Er.KT
  • 2,852
  • 1
  • 36
  • 70

1 Answers1

1

You can give a try to "intercept" Presence packet with Presence.Type.unavailable

Openfire has a ConnectionCloseListener (in SessionManager class) that fires a Presence unavailable.

If you read the class comments, it says

  // Send an unavailable presence to the user's subscribers
  // Note: This gives us a chance to send an unavailable presence to the
  // entities that the user sent directed presences

so probably it's possible to have an administrative user who can auto-subscribe to all users, recive the presence-unavailable and so you'll be able to just intercept the packet direct to this user to send your e-mail.

With opposite logic you'll be able to force a direct presence to something you control and intercept presence-unavailable to this entity

MrPk
  • 2,862
  • 2
  • 20
  • 26
  • I am 100% agree with your logic, but the problem is over here I need to keep one user logged-in all the time in the browser, where I can implement listener and can fire ajax based on that. But what if no one is logged-in to system and want to track users presence ??? is it possible to trigger any url same as CallbackOnOffline plugin ? – Er.KT Jun 08 '16 at 04:16
  • With Openfire (so I bet also with any other server), you can intercept a kind of Stanza (Presence) and if needed add a filter (example: "to=admin@adminmessages"). So, just intercept any Presence ad do your staff or add and administrative user by default (you can duplicate the Presence, or just force a subscription and so on). In theory you don't need a client always online, you'll just have to add a prerequisite to let Openfire send the Presence. You'll intercept the presence before openfire "realize" admin it's offline – MrPk Jun 08 '16 at 08:46
  • "add a prerequisite to let Openfire send the Presence" but here send to whom ? I want to call one php script on offline, is that possible ? – Er.KT Jun 08 '16 at 11:41
  • Well dude, it's all possible. You can intercept the Presence, on intercept you can do all what you want, also a call on a servlet that call a php script, call a ws that invoke a php script, an update on a database with a php job that consume this database and so on. But this is really out of the original question and you know your architecture ;) – MrPk Jun 08 '16 at 12:08
  • Is it possible for you to chat more on the same at http://chat.stackoverflow.com/rooms/114182/room-for-er-kt-and-mrpk ? – Er.KT Jun 09 '16 at 06:36