def main(self): while 1: print 'loop!' while self.dataReady("control"): mes = self.recv("control") if isinstance(mes, shutdownMicroprocess) or isinstance(mes, producerFinished): self.send(producerFinished(), "signal") break while self.dataReady("subscribe"): p = self.recv("subscribe") p.swap_jids() # Automatically accept any subscription requests p = Presence(from_jid=p.from_jid, to_jid=unicode(p.to_jid), type=u'subscribed') self.send(p, "outbox") # Automatically subscribe in return as well p = Presence(from_jid=p.from_jid, to_jid=unicode(p.to_jid), type=u'subscribe') self.send(p, "outbox") while self.dataReady("unsubscribe"): p = self.recv("unsubscribe") p.swap_jids() # We stop our subscription to the other user p = Presence(from_jid=p.from_jid, to_jid=unicode(p.to_jid), type=u'unsubscribed') self.send(p, "outbox") # We stop the other user's subscription p = Presence(from_jid=p.from_jid, to_jid=unicode(p.to_jid), type=u'unsubscribe') self.send(p, "outbox") # We remove this user from our roster list r = Roster(from_jid=p.from_jid, type=u'set') i = Item(p.to_jid) i.subscription = u'remove' r.items[unicode(p.to_jid)] = i self.send(r, 'roster') # We tell the other user we're not available anymore p = Presence(from_jid=p.from_jid, to_jid=unicode(p.to_jid), type=u'unavailable') self.send(p, "outbox") if not self.anyReady(): self.pause() yield 1
def shutdown(self): self.send(Presence.to_element(Presence(self.jid, type=u'unavailable')), 'forward') self.send('OUTGOING : </stream:stream>', 'log') self.send('</stream:stream>', 'outbox')