Changeset 162:8bffd58d7b6d
- Timestamp:
- Jan 8, 2012, 9:26:06 AM (9 years ago)
- Branch:
- default
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/examples/muc_client.tac
r156 r162 16 16 17 17 from twisted.application import service 18 from twisted.python import log 18 19 from twisted.words.protocols.jabber.jid import JID 19 20 from wokkel.client import XMPPClient … … 42 43 """ 43 44 Once authorized, join the room. 45 46 If the join action causes a new room to be created, the room will be 47 locked until configured. Here we will just accept the default 48 configuration by submitting an empty form using L{configure}, which 49 usually results in a public non-persistent room. 50 51 Alternatively, you would use L{getConfiguration} to retrieve the 52 configuration form, and then submit the filled in form with the 53 required settings using L{configure}, possibly after presenting it to 54 an end-user. 44 55 """ 56 def joinedRoom(room): 57 if room.locked: 58 # Just accept the default configuration. 59 return self.configure(room.roomJID, {}) 60 45 61 MUCClient.connectionInitialized(self) 46 self.join(self.roomJID, self.nick) 62 63 d = self.join(self.roomJID, self.nick) 64 d.addCallback(joinedRoom) 65 d.addCallback(lambda _: log.msg("Joined room")) 66 d.addErrback(log.err, "Join failed") 67 47 68 48 69 def receivedGroupChat(self, room, user, message): -
wokkel/muc.py
r161 r162 1134 1134 @type nick: C{unicode} 1135 1135 1136 @ivar state: The status code of the room.1137 @type state: L{int}1138 1139 1136 @ivar occupantJID: The JID of the occupant in the room. Generated from 1140 1137 roomJID and nick. 1141 1138 @type occupantJID: L{jid.JID} 1142 """ 1143 1144 1145 def __init__(self, roomJID, nick, state=None): 1139 1140 @ivar locked: Flag signalling a locked room. A locked room first needs 1141 to be configured before it can be used. See 1142 L{MUCClientProtocol.getConfiguration} and 1143 L{MUCClientProtocol.configure}. 1144 @type locked: C{bool} 1145 """ 1146 1147 locked = False 1148 1149 def __init__(self, roomJID, nick): 1146 1150 """ 1147 1151 Initialize the room. … … 1149 1153 self.roomJID = roomJID 1150 1154 self.setNick(nick) 1151 self.state = state1152 1153 self.status = 01154 1155 1155 self.roster = {} 1156 1156 … … 1456 1456 We have presence that says we joined a room. 1457 1457 """ 1458 room.state = 'joined' 1458 if STATUS_CODE.ROOM_CREATED in presence.mucStatuses: 1459 room.locked = True 1460 1459 1461 return room 1460 1462 … … 1463 1465 return failure 1464 1466 1465 room = Room(roomJID, nick , state='joining')1467 room = Room(roomJID, nick) 1466 1468 self._addRoom(room) 1467 1469 -
wokkel/test/test_muc.py
r161 r162 1664 1664 def cb(room): 1665 1665 self.assertEqual(self.roomJID, room.roomJID) 1666 self.assert True('joined', room.state)1666 self.assertFalse(room.locked) 1667 1667 1668 1668 d = self.protocol.join(self.roomJID, self.nick) … … 1681 1681 1682 1682 1683 def test_joinLocked(self): 1684 """ 1685 A new room is locked by default. 1686 """ 1687 1688 def cb(room): 1689 self.assertTrue(room.locked, "Room is not marked as locked") 1690 1691 d = self.protocol.join(self.roomJID, self.nick) 1692 d.addCallback(cb) 1693 1694 # send back user presence, they joined 1695 xml = """ 1696 <presence from='%s@%s/%s'> 1697 <x xmlns='http://jabber.org/protocol/muc#user'> 1698 <item affiliation='owner' role='moderator'/> 1699 <status code="110"/> 1700 <status code="201"/> 1701 </x> 1702 </presence> 1703 """ % (self.roomIdentifier, self.service, self.nick) 1704 self.stub.send(parseXml(xml)) 1705 return d 1706 1707 1683 1708 def test_joinForbidden(self): 1684 1709 """
Note: See TracChangeset
for help on using the changeset viewer.