Question

i am using xmpp framework to develop an chat application using openfire server. The users are registered on the server using In Band account registration. But i am not able to understand how a user will be added into the roaster list of another user . Does the app have to fetch all the users that are registered on the server , so that user using the app can send buddy requests Or when any user comes online the server must broadcast it to other users.

I am having difficulties in the flow . Please help me out.

Was it helpful?

Solution

There are two ways to do that.

  1. Having database of users on server where you can fetch all users on server.
  2. Using Search api of openfire. If you are not using any webservice, you can implement xep-0055

As a response of search you can get a list of jids, from where you have to select one. Now again there are two options to add that jid in your roster list

  1. Install User service plugin and use add roster api provided by openfire.

  2. From app as below

XMPPJID *newBuddy = [XMPPJID jidWithString:@"jid"];
[xmppRoster addUser:newBuddy withNickname:nil];

Other user will get it via presence

if([presenceType isEqualToString:@"subscribe"])
{
    NSXMLElement *presenceToRequest = [NSXMLElement elementWithName:@"presence"];
    [presenceToRequest addAttributeWithName:@"type" stringValue:@"subscribed"];
    [presenceToRequest addAttributeWithName:@"to" stringValue:[NSString stringWithFormat:@"%@", [presence fromStr]]];
    [presenceToRequest addAttributeWithName:@"from" stringValue:[NSString stringWithFormat:@"%@", [presence toStr]]];
    [[self xmppStream] sendElement:presenceToRequest];
}

Refer this link for more info

This list out iq used for various purpose.

PS: Links with openfire will work after modifying openfire ip and port

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top