source: ralphm-patches/client_service_example.patch @ 36:f2953cadca90

Last change on this file since 36:f2953cadca90 was 36:f2953cadca90, checked in by Ralph Meijer <ralphm@…>, 11 years ago

Work on roster item representation.

File size: 2.1 KB
  • new file doc/examples/client_service.tac

    diff -r 22c292560ce9 doc/examples/client_service.tac
    - +  
     1from twisted.application import service
     2from twisted.internet import defer
     3
     4from wokkel.client import ClientService
     5from wokkel.generic import FallbackHandler
     6from wokkel.subprotocols import XMPPHandler
     7from wokkel.xmppim import RosterItem, RosterServerProtocol
     8
     9from twisted.words.protocols.jabber.jid import internJID as JID
     10
     11import socket
     12domain = socket.gethostname()
     13
     14class StaticRoster(RosterServerProtocol):
     15
     16    def __init__(self):
     17        RosterServerProtocol.__init__(self)
     18        self.roster = {'ralphm': [
     19                           RosterItem(JID('intosi@'+domain),
     20                                      subscriptionTo=True,
     21                                      subscriptionFrom=True,
     22                                      name='Intosi',
     23                                      groups=set(['Friends'])),
     24                           RosterItem(JID('termie@'+domain),
     25                                      subscriptionTo=True,
     26                                      subscriptionFrom=True,
     27                                      name='termie'),
     28                           ],
     29                       'test': [],
     30                       }
     31
     32    def getRoster(self, entity):
     33        return defer.succeed(self.roster[entity.user])
     34
     35
     36class Hello(XMPPHandler):
     37
     38    def q(self):
     39        from wokkel.xmppim import AvailabilityPresence
     40        p = AvailabilityPresence(JID('ralphm@'+domain+'/default'), JID('termie@'+domain+'/Home'), show='chat')
     41        self.parent.send(p.toElement())
     42
     43
     44    def connectionInitialized(self):
     45        from twisted.internet import reactor
     46        reactor.callLater(5, self.q)
     47
     48
     49
     50application = service.Application("Jabber server")
     51clientService = ClientService(domain, 5224)
     52clientService.logTraffic = True
     53FallbackHandler().setHandlerParent(clientService)
     54StaticRoster().setHandlerParent(clientService)
     55Hello().setHandlerParent(clientService)
     56clientService.setServiceParent(application)
Note: See TracBrowser for help on using the repository browser.