Mercurial > libervia-backend
comparison sat.tac @ 52:6455fb62ff83
Connection/disconnection signals
- wix, sortilege: management of this new signals
/!\ sortilege is bugged, the contact list window is not updated correctly
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 07 Jan 2010 01:55:30 +1100 |
parents | daa1f01a5332 |
children | a5b5fb5fc9fd |
comparison
equal
deleted
inserted
replaced
51:8c67ea98ab91 | 52:6455fb62ff83 |
---|---|
68 sat_id+=1 | 68 sat_id+=1 |
69 return "sat_id_"+str(sat_id) | 69 return "sat_id_"+str(sat_id) |
70 | 70 |
71 class SatXMPPClient(client.XMPPClient): | 71 class SatXMPPClient(client.XMPPClient): |
72 | 72 |
73 def __init__(self, user_jid, password, host=None, port=5222): | 73 def __init__(self, bridge, user_jid, password, host=None, port=5222): |
74 client.XMPPClient.__init__(self, user_jid, password, host, port) | 74 client.XMPPClient.__init__(self, user_jid, password, host, port) |
75 self.factory.clientConnectionLost = self.connectionLost | 75 self.factory.clientConnectionLost = self.connectionLost |
76 self.__connected=False | 76 self.__connected=False |
77 self.bridge = bridge | |
77 | 78 |
78 def _authd(self, xmlstream): | 79 def _authd(self, xmlstream): |
79 print "SatXMPPClient" | 80 print "SatXMPPClient" |
80 client.XMPPClient._authd(self, xmlstream) | 81 client.XMPPClient._authd(self, xmlstream) |
81 self.__connected=True | 82 self.__connected=True |
82 print "********** CONNECTED **********" | 83 print "********** CONNECTED **********" |
83 self.streamInitialized() | 84 self.streamInitialized() |
85 self.bridge.connected() #we send the signal to the clients | |
84 | 86 |
85 def streamInitialized(self): | 87 def streamInitialized(self): |
86 """Called after _authd""" | 88 """Called after _authd""" |
87 self.keep_alife = task.LoopingCall(self.xmlstream.send, " ") #Needed to avoid disconnection (specially with openfire) | 89 self.keep_alife = task.LoopingCall(self.xmlstream.send, " ") #Needed to avoid disconnection (specially with openfire) |
88 self.keep_alife.start(180) | 90 self.keep_alife.start(180) |
95 print "********** DISCONNECTED **********" | 97 print "********** DISCONNECTED **********" |
96 try: | 98 try: |
97 self.keep_alife.stop() | 99 self.keep_alife.stop() |
98 except AttributeError: | 100 except AttributeError: |
99 debug("No keep_alife") | 101 debug("No keep_alife") |
102 self.bridge.disconnected() #we send the signal to the clients | |
100 | 103 |
101 | 104 |
102 class SatMessageProtocol(xmppim.MessageProtocol): | 105 class SatMessageProtocol(xmppim.MessageProtocol): |
103 | 106 |
104 def __init__(self, host): | 107 def __init__(self, host): |
354 if (self.isConnected()): | 357 if (self.isConnected()): |
355 info("already connected !") | 358 info("already connected !") |
356 return | 359 return |
357 print "connecting..." | 360 print "connecting..." |
358 self.me = jid.JID(self.memory.getParamA("JabberID", "Connection")) | 361 self.me = jid.JID(self.memory.getParamA("JabberID", "Connection")) |
359 self.xmppclient = SatXMPPClient(self.me, self.memory.getParamA("Password", "Connection"), | 362 self.xmppclient = SatXMPPClient(self.bridge, self.me, self.memory.getParamA("Password", "Connection"), |
360 self.memory.getParamA("Server", "Connection"), 5222) | 363 self.memory.getParamA("Server", "Connection"), 5222) |
361 self.xmppclient.streamInitialized = self.streamInitialized | 364 self.xmppclient.streamInitialized = self.streamInitialized |
362 | 365 |
363 self.messageProt = SatMessageProtocol(self) | 366 self.messageProt = SatMessageProtocol(self) |
364 self.messageProt.setHandlerParent(self.xmppclient) | 367 self.messageProt.setHandlerParent(self.xmppclient) |