Wednesday, October 25, 2006

Keeping xAP Jabber connected

One thing I've noticed is that xAP Jabber seems to get disconnected from the Y! network after not sending a message for a period of time. I fired up the xAP message viewer to see if there were any messages being sent when Jabber disconnected. I found that Jabber would send a User.Status message with the field xstatus set to nothing (as opposed to "Online" or "Logged off").

I wrote a small raw script for xAP Floorplan to send a message whenever it detects that status message:
Sub Main()
status=xap.getfromraw(rawmessage, "User.Status,xstatus")
user=xap.getfromraw(rawmessage, "User.Status,username")
' replace w/ your user name
if user= "yahoo_house_xyz@yahoo.localhost" then
' save status in global in case you want to use it somewhere else
SetGlobal "IMHouse", status
if Len(status) < 2 then
xAPBody="line1=wake myself up ping"
' replace w/ your user name
xAPTarget="mi4.jabber.jabber:yahoo_house_xyz.yahoo.localhost"
' the following 3 lines need to be all 1 line
x=xap.SendxAP("display.text" & chr(10) & "{" & chr(10) &
xAPBody & chr(10) & "priority=1" & chr(10) & "}" &
chr(10),"message.display",xAPTarget)
end if
end if
end sub

I saved it as jabberstatus.txt. The next step was to trigger this every time xstatus changed. Following this Floorplan example, I created a raw device for Jabber in floorplan. I filled in the fields as follows:
  • Alias = jabber status
  • Source = mi4.jabber.jabber
  • Class = Messenger.Event
  • Section = User.Status
  • Item = xstatus
  • Script to run on update = jabberstatus
That's it. Now, whenever Floorplan detects Jabber being disconnected, it sends a message that causes Jabber to reconnect. So far, it seems to work. Jabber has stayed connected overnight for the first time since I installed it. Use the xAP Message Viewer to resend the User.Status messages to test out the script. Make sure you check the Script Debug tab in Floorplan to make sure you didn't make any typos (or copy any of mine!)

No comments:

Post a Comment