]> git.babelmonkeys.de Git - jubjub.git/commitdiff
Add basic Service Discovery support
authorFlorian Zeitz <florob@babelmonkeys.de>
Wed, 3 Apr 2013 21:37:48 +0000 (23:37 +0200)
committerFlorian Zeitz <florob@babelmonkeys.de>
Wed, 3 Apr 2013 21:37:48 +0000 (23:37 +0200)
src/core/JubChatClient.h
src/core/JubChatClient.m

index cacb72dcf2aae0721340362168e60a2e1046d1c4..57cfd0b5782f29732863e3631aac10ed3fcfa9c1 100644 (file)
        XMPPRoster *_roster;
        XMPPStreamManagement *_streamManagement;
        XMPPContactManager *_contactManager;
+       XMPPDiscoEntity *_discoEntity;
        XMPPPresence *_presence;
        id<JubUI> _ui;
 }
 @property (readonly) XMPPConnection *connection;
 @property (readonly) XMPPRoster *roster;
 @property (readonly) XMPPContactManager *contactManager;
+@property (readonly) XMPPDiscoEntity *discoEntity;
 @property (readonly) XMPPPresence *presence;
 @property (assign) id<JubUI> ui;
 
index eea1b8a98fd0af6df0e898a3e951c850cd102d8a..1d7874ad563d26c044f5b9d100651c0505deb94f 100644 (file)
@@ -1,9 +1,13 @@
 #import "JubChatClient.h"
+#import "ObjXMPP/namespaces.h"
+
+#define JUB_CLIENT_URI @"http://babelmonkeys.de/jubjub"
 
 @implementation JubChatClient
 @synthesize connection = _connection;
 @synthesize roster = _roster;
 @synthesize contactManager = _contactManager;
+@synthesize discoEntity = _discoEntity;
 @synthesize presence = _presence;
 @synthesize ui = _ui;
 
@@ -47,6 +51,7 @@
 
        [_roster release];
        [_contactManager release];
+       [_discoEntity release];
        [_streamManagement release];
        [_connection release];
        [_presence release];
        if (text != nil)
                presence.status = text;
 
+       OFXMLElement *caps = [OFXMLElement elementWithName: @"c"
+                                                namespace: XMPP_NS_CAPS];
+       [caps addAttributeWithName: @"hash"
+                      stringValue: @"sha-1"];
+       [caps addAttributeWithName: @"ver"
+                      stringValue: [_discoEntity capsHash]];
+       [caps addAttributeWithName: @"node"
+                      stringValue: JUB_CLIENT_URI];
+
+       [presence addChild: caps];
+
        [_connection sendStanza: presence];
 }
 
 {
        of_log(@"Bound to JID: %@", [jid fullJID]);
 
+       _discoEntity =
+           [[XMPPDiscoEntity alloc] initWithConnection: connection
+                                              capsNode: JUB_CLIENT_URI];
+
+       XMPPDiscoIdentity *identity =
+           [XMPPDiscoIdentity identityWithCategory: @"client"
+                                              type: @"pc"
+                                              name: @"JubJub"];
+       [_discoEntity addIdentity: identity];
+       [_discoEntity addFeature: XMPP_NS_CAPS];
+
        [_roster requestRoster];
 }
 
 
 - (void)rosterWasReceived: (XMPPRoster*)roster
 {
-       XMPPPresence *pres = [XMPPPresence presence];
-       [pres setStatus: @"Hello from JubJub"];
-       [_connection sendStanza: pres];
+       [self sendPresenceWithStatus: @"available"
+                               text: @"Hello from JubJub"];
 }
 @end