How to delete or exit from MUC in XMPP - ios

Currently i am making chat application and i required to delete Particular group chat.
For delete group i tried below solution but not working.please check this code
-(void)ExitGroup:(NSString *)Roomjdi Removeuserid:(NSString *)Userid {
{
XMPPJID *roomJID = [XMPPJID jidWithString:Roomjdi];
XMPPRoomMemoryStorage *roomMemoryStorage = [[XMPPRoomMemoryStorage alloc] init];
XMPPRoom *xmppRooms = [[XMPPRoom alloc]
initWithRoomStorage:roomMemoryStorage
jid:roomJID
dispatchQueue:dispatch_get_main_queue()];
[xmppRooms removeDelegate:self delegateQueue:dispatch_get_main_queue()];
[self deactivate:roomJID];
[self leaveRoom:roomJID];
}
- (void)leaveRoom:(XMPPJID *)myRoomJID
{
// dispatch_block_t block = ^{ #autoreleasepool {
//XMPPLogTrace();
// <presence type='unavailable' to='darkcave#chat.shakespeare.lit/thirdwitch'/>
XMPPPresence *presence = [XMPPPresence presence];
[presence addAttributeWithName:#"to" stringValue:[myRoomJID full]];
[presence addAttributeWithName:#"type" stringValue:#"unavailable"];
[xmppStream sendElement:presence];
[xmppRoom leaveRoom];
[xmppRoom deactivate];
[xmppRoom removeDelegate:self];
}
after i execute this method but in ejabbared display online user in group list.please tell me any where i am wrong.

Related

can't receive group message using xmpp

I can't receive group message on this method.
- (void)xmppStream:(XMPPStream *)sender didReceiveMessage:(XMPPMessage *)message
{
NSLog(#"Message received description === %#",[message description]);
}
-(void)sendGroupMessage:(NSString *)NameOfGroup :(NSString *)Msg
{
[xmppRoom sendMessageWithBody:Msg];
NSXMLElement *x = [NSXMLElement elementWithName:NameOfGroup xmlns:XMPPMUCNamespace];
XMPPMessage *message = [XMPPMessage message];
[message addAttributeWithName:#"to" stringValue:[NSString stringWithFormat:#"%#",NameOfGroup]];
[message addChild:x];
NSLog(#"x in Invite === %#",x);
[xmppRoom sendMessage:message];
}
-(void)setUpRoom:(NSString *)ChatRoomJID
{
NSString *Strng=[NSString stringWithFormat:#"Abc#conference.localhost"];
ChatRoomJID=Strng;
XMPPRoomMemoryStorage *roomMemoryStorage = [[XMPPRoomMemoryStorage alloc] init];
XMPPJID *roomJID = [XMPPJID jidWithString:ChatRoomJID];
xmppRoom = [[XMPPRoom alloc] initWithRoomStorage:roomMemoryStorage jid:roomJID dispatchQueue:dispatch_get_main_queue()];
[xmppRoom activate:xmppStream];
[xmppRoom addDelegate:self delegateQueue:dispatch_get_main_queue()];
[xmppRoom joinRoomUsingNickname:self.UserID
history:nil
password:nil];
[self performSelector:#selector(ConfigureNewRoom:) withObject:nil afterDelay:4];
}
First of all I create new group, send invitation and successfully accept it also for all invited users.
When I send message on that group, all person got message successfully, But if I will stop App and run again and login with xmpp and send message on group, message is not delivered to joined users.
When i have to log out and login again to xmpp server and send message on previously created group i got this error message
<message xmlns="jabber:client" from="dharmraj123#conference.localhost" to="revoz1wwbzji1e1481005747#localhost/1824017799289652742921131" type="error"><body>1 Message</body><error code="406" type="modify"><not-acceptable xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"></not-acceptable><text xmlns="urn:ietf:params:xml:ns:xmpp-stanzas">Only occupants are allowed to send messages to the conference</text></error></message>

Unable to creating room in XAMPPFramework(iOS), getting the error as remote-server-not-found with below code

XMPPJID *roomJID = [XMPPJID jidWithString:#"chat11#conference.local_IP"];
xmppRoom = [[XMPPRoom alloc] initWithRoomStorage:roomStorage jid:roomJID dispatchQueue:dispatch_get_main_queue()];
[xmppRoom activate:[self appDelegate].xmppStream];
[xmppRoom addDelegate:self delegateQueue:dispatch_get_main_queue()];
[xmppRoom joinRoomUsingNickname:#"pandian"
history:nil password:nil];
any help will be much appreciated.
Check the hostName and port number you have set for the XMPPStream object.
let stream = XMPPStream()
stream.hostName = "hostName"
stream.hostPort = PORT_NUM

Unable to send and receive message in Group Chat using Xmpp in iphone

Using xmpp I can able to create group and send invitation to friends but while I send message on group, members will never received that message.
Is member have to accept the invitation ? If yes, then let me know how?
Please refer below code and if I made any mistake or still I am missing any things then guide me for that so after I can send and receive messages in group and chat with friends.
Below I'm attaching my some code snippet for create group in xmpp and send message.
[self setUpRoom:[NSString stringWithFormat:#"%##conference.myserver",#"GroupName"]];
-(void)setUpRoom:(NSString *)ChatRoomJID {
// Configure xmppRoom
XMPPRoomMemoryStorage *roomMemoryStorage = [[XMPPRoomMemoryStorage alloc] init];
XMPPJID *roomJID = [XMPPJID jidWithString:ChatRoomJID];
xmppRoom = [[XMPPRoom alloc] initWithRoomStorage:roomMemoryStorage jid:roomJID dispatchQueue:dispatch_get_main_queue()];
[xmppRoom activate:xmppStream];
[xmppRoom addDelegate:self delegateQueue:dispatch_get_main_queue()];
[xmppRoom joinRoomUsingNickname:_ro(#"LoginNumber")
history:nil
password:nil];
[self performSelector:#selector(ConfigureNewRoom:) withObject:nil afterDelay:4];
}
Now for room confirmation i used this snippet
- (void)ConfigureNewRoom:(id)sender
{
[xmppRoom configureRoomUsingOptions:nil];
[xmppRoom fetchConfigurationForm];
[xmppRoom fetchBanList];
[xmppRoom fetchMembersList];
[xmppRoom fetchModeratorsList];
}
XMPPRoom Delegate Mothods
- (void)xmppRoomDidCreate:(XMPPRoom *)sender
{
DDLogInfo(#"%#: %#", THIS_FILE, THIS_METHOD);
// I am inviting friends after room is created
for (int i = 0; i<[self.friendListArray count]; i++)
{
NSString * tempStr=[NSString stringWithFormat:#"%##myserver",[[self.friendListArray objectAtIndex:i] valueForKey:#"UserNumber"]];
[sender inviteUser:[XMPPJID jidWithString:tempStr] withMessage:#"Greetings!"];
}
}
- (void)xmppRoomDidJoin:(XMPPRoom *)sender
{
DDLogInfo(#"%#: %#", THIS_FILE, THIS_METHOD);
NSLog(#"........Room Did join.......");
}
- (void)xmppRoom:(XMPPRoom *)sender didFetchConfigurationForm:(NSXMLElement *)configForm
{
DDLogInfo(#"%#: %#", THIS_FILE, THIS_METHOD);
NSXMLElement *newConfig = [configForm copy];
NSArray *fields = [newConfig elementsForName:#"field"];
for (NSXMLElement *field in fields)
{
NSString *var = [field attributeStringValueForName:#"var"];
// Make Room Persistent
if ([var isEqualToString:#"muc#roomconfig_persistentroom"])
{
[field removeChildAtIndex:0];
[field addChild:[NSXMLElement elementWithName:#"value" stringValue:#"1"]];
}
if ([var isEqualToString:#"roomconfig_enablelogging"])
{
[field removeChildAtIndex:0];
[field addChild:[NSXMLElement elementWithName:#"value" stringValue:#"1"]];
}
if ([var isEqualToString:#"muc#roomconfig_maxusers"])
{
[field removeChildAtIndex:0];
[field addChild:[NSXMLElement elementWithName:#"value" stringValue:#"100"]];
}
}
[sender configureRoomUsingOptions:newConfig];
}
Sending message in group on button click for testing purpose
-(void)sendGroupMessage
{
[xmppRoom sendMessageWithBody:#"Hi All"];
NSXMLElement *x = [NSXMLElement elementWithName:#"groupchat" xmlns:XMPPMUCNamespace];
XMPPMessage *message = [XMPPMessage message];
[message addAttributeWithName:#"to" stringValue:[NSString stringWithFormat:#"%#/%#",[xmppRoom.roomJID full],_ro(#"LoginNumber")]];
[message addChild:x];
NSLog(#"x in Invite === %#",x);
[xmppStream sendElement:message];
}
Instead of:
[xmppStream sendElement:message]
try:
[xmppRoom sendMessage:message]
For MUC chat the member has to accept the invitation.
You can find the answer here:
https://stackoverflow.com/a/26031897/4050160

How to Configure XMPP Facebook chat in iOS application

I am developing an iOS application which uses the Facebook chat feature.
(I am using the XMPPFramework by Robbie Hanson).
https://github.com/robbiehanson/XMPPFramework
In connect method i have given my user name and password
- (BOOL)connect
{
if (![xmppStream isDisconnected]) {
return YES;
}
NSString *myJID = [[NSUserDefaults standardUserDefaults] stringForKey:kXMPPmyJID];
NSString *myPassword = [[NSUserDefaults standardUserDefaults] stringForKey:kXMPPmyPassword];
//
// If you don't want to use the Settings view to set the JID,
// uncomment the section below to hard code a JID and password.
//
myJID = #"example#facebook.com";
myPassword = #"Mypassword";
if (myJID == nil || myPassword == nil) {
return NO;
}
[xmppStream setMyJID:[XMPPJID jidWithString:myJID]];
password = myPassword;
NSError *error = nil;
if (![xmppStream connectWithTimeout:XMPPStreamTimeoutNone error:&error])
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Error connecting"
message:#"See console for error details."
delegate:nil
cancelButtonTitle:#"Ok"
otherButtonTitles:nil];
[alertView show];
DDLogError(#"Error connecting: %#", error);
return NO;
}
in up stream method i have given my host name and port number
- (void)setupStream
{
NSAssert(xmppStream == nil, #"Method setupStream invoked multiple times");
xmppStream = [[XMPPStream alloc] init];
#if !TARGET_IPHONE_SIMULATOR
{
xmppStream.enableBackgroundingOnSocket = YES;
}
#endif
xmppReconnect = [[XMPPReconnect alloc] init];
xmppRosterStorage = [[XMPPRosterCoreDataStorage alloc] init];
xmppRoster = [[XMPPRoster alloc] initWithRosterStorage:xmppRosterStorage];
xmppRoster.autoFetchRoster = YES;
xmppRoster.autoAcceptKnownPresenceSubscriptionRequests = YES;
xmppvCardStorage = [XMPPvCardCoreDataStorage sharedInstance];
xmppvCardTempModule = [[XMPPvCardTempModule alloc] initWithvCardStorage:xmppvCardStorage];
xmppvCardAvatarModule = [[XMPPvCardAvatarModule alloc] initWithvCardTempModule:xmppvCardTempModule];
xmppCapabilitiesStorage = [XMPPCapabilitiesCoreDataStorage sharedInstance];
xmppCapabilities = [[XMPPCapabilities alloc] initWithCapabilitiesStorage:xmppCapabilitiesStorage];
xmppCapabilities.autoFetchHashedCapabilities = YES;
xmppCapabilities.autoFetchNonHashedCapabilities = NO;
// Activate xmpp modules
[xmppReconnect activate:xmppStream];
[xmppRoster activate:xmppStream];
[xmppvCardTempModule activate:xmppStream];
[xmppvCardAvatarModule activate:xmppStream];
[xmppCapabilities activate:xmppStream];
// Add ourself as a delegate to anything we may be interested in
[xmppStream addDelegate:self delegateQueue:dispatch_get_main_queue()];
[xmppRoster addDelegate:self delegateQueue:dispatch_get_main_queue()];
[xmppStream setHostName:#"chat.facebook.com"];
[xmppStream setHostPort:5222];
// You may need to alter these settings depending on the server you're connecting to
allowSelfSignedCertificates = NO;
allowSSLHostNameMismatch = NO;
}
Is there any steps that I have missed out? I have no idea how to proceed further. Help me if any one know the solution. Please help me out
Thanks in advance.
Try securing the connection using:
[xmppStream secureConnection:(NSError *)];
in the
- (void)xmppStreamDidConnect:(XMPPStream *)sender;
delegate method.
Hope it helps.

Adding user to xmpp room

Hello I know there is alot question regarding this but still i could not figure out what can be the problem. I have sucessfully created group using following code.
- (void)createGroup
{
iXmppEngine.userID = #"lahore123#hassan.local";
iXmppEngine.userPass = #"password123";
self.rosterstorage =[[XMPPRoomCoreDataStorage alloc] init];
XMPPRoom *xmppRoom = [[XMPPRoom alloc] initWithRoomStorage:self.rosterstorage jid:[XMPPJID jidWithString:#"test#conference.hassan.local"] dispatchQueue:dispatch_get_main_queue()];
[xmppRoom activate:[[self iXmppEngine]xmppStream]];
[xmppRoom joinRoomUsingNickname:#"Dev iphone" history:nil];
[[[self iXmppEngine] xmppStream] addDelegate:self delegateQueue:dispatch_get_main_queue()];
[xmppRoom addDelegate:self delegateQueue:dispatch_get_main_queue()];
[self performSelector:#selector(joinRoom) withObject:nil afterDelay:4];
}
And For adding user i used following code. I have called this function with delay of 5s so room can be created succesfully before adding users.
- (void)joinRoom
{
self.iXmppEngine.userID = #"lahore#hassan.local";
// self.rosterstorage = [[XMPPRoomCoreDataStorage alloc] init];
XMPPRoom *xmppRoom = [[XMPPRoom alloc] initWithRoomStorage:self.rosterstorage jid:[XMPPJID jidWithString:#"test#conference.hassan.local"] dispatchQueue:dispatch_get_main_queue()];
[xmppRoom activate:[[self iXmppEngine] xmppStream]];
[xmppRoom joinRoomUsingNickname:#"lahore" history:nil];
[xmppRoom fetchConfigurationForm];
[xmppRoom configureRoomUsingOptions:nil];
[xmppRoom addDelegate:[self iXmppEngine] delegateQueue:dispatch_get_main_queue()];
}
What i am doing wrong couldnt find.
Creating and Joining (Already Created Room or Accepting Invitation To Join Room) Rooms are two differnet scenarios.
// CONFERENCE_ROOM_SERVER is the domain name for MUC
For Creating Group Do This Way:
- (void)createChatRoom:(NSString *) newRoomName
{
XMPPJID *roomJID = [XMPPJID jidWithString:[NSString stringWithFormat:#"%##%#", newRoomName, CONFERENCE_ROOM_SERVER]];
XMPPRoomMemoryStorage *roomMemoryStorage = [[XMPPRoomMemoryStorage alloc] init];
xmppRoom = [[XMPPRoom alloc]
initWithRoomStorage:roomMemoryStorage
jid:roomJID
dispatchQueue:dispatch_get_main_queue()];
[xmppRoom activate:[self xmppStream]];
[xmppRoom addDelegate:self delegateQueue:dispatch_get_main_queue()];
[xmppRoom joinRoomUsingNickname:#"Your Nick Name" history:nil];
}
You will get the response after the group has been created successfully in this delegate:
- (void)xmppRoomDidCreate:(XMPPRoom *)sender
Now Invite Users Here This Way:
[sender inviteUser:[XMPPJID jidWithString:inviteUserJID] withMessage:#"Any Message"];

Resources