I have an application which I am using for one-to-one chat. Now I need to implement group chat. I know it is possible with XMPPFramework and there is a class called XMPPRoom which we can use to create a room or join a room. But I am unable to implement that in my project.
Can anyone please provide me some ideas, suggestions and if possible a sample application.
Thanks in advance :)
here you have a script that allows to connect to a room
[xmppRoom activate:[self xmppStream]];
[xmppRoom createOrJoinRoom];
In order to do this you should have access to the xmppStream.
- (void)createOrJoinRoomWithRoomName:(NSString *)roomName nickName:(NSString *)nickName
{
if(roomName && nickName)
{
_xmppRoomStorage = [XMPPRoomHybridStorage sharedInstance];
XMPPJID *roomJid = [XMPPJID jidWithString:[NSString stringWithFormat:#"%##%#.%#",roomName,#"conference",self.hostName]];
_xmppRoom = [[XMPPRoom alloc] initWithRoomStorage:_xmppRoomStorage jid:roomJid];
[_xmppRoom addDelegate:self delegateQueue:dispatch_get_main_queue()];
[_xmppRoom activate:_xmppStream];
NSXMLElement *history = [NSXMLElement elementWithName:#"history"];
[history addAttributeWithName:#"maxstanzas" stringValue:MAX_ROOM_HISTORY];
[_xmppRoom joinRoomUsingNickname:nickName history:history];
}
else
{
NSLog(#"room creation arguments missing");
}
}
Related
I tried to create a new group using XMPP Framework in iOS using the following code as per given here
NSString *nickName=[NSString stringWithFormat:#"%#.nickName#conference.server.hostname.in" ,newGroupName ];
XMPPRoomMemoryStorage * roomMemory = [[XMPPRoomMemoryStorage alloc]init];
NSString* roomID = [NSString stringWithFormat:#"%##conference.server.hostname.in" ,newGroupName ];
XMPPJID * roomJID = [XMPPJID jidWithString:roomID];
XMPPRoom* xmppRoom = [[XMPPRoom alloc] initWithRoomStorage:roomMemory jid:roomJID dispatchQueue:dispatch_get_main_queue()];
[xmppRoom activate:self.xmppStream];
[xmppRoom addDelegate:self delegateQueue:dispatch_get_main_queue()];
[xmppRoom joinRoomUsingNickname:nickName history:nil password:nil];
I did configure as said in the above specified thread with
[xmppRoom fetchConfigurationForm];
But there is no response coming to the method
- (void)xmppRoomDidCreate:(XMPPRoom *)sender{
DDLogVerbose(#"%#: %#", THIS_FILE, THIS_METHOD);
}
or not even call is coming to this method.
that means the group is not being created, right? No error is shown or nothing in Log.
Please tell me what is the mistake I have made or if there is something more I have to do with this.
Thanks in advance :D
Do it in this way. This is in swift
let roomStorage: XMPPRoomMemoryStorage = XMPPRoomMemoryStorage()
let roomJID: XMPPJID = XMPPJID.jidWithString("chatRoom10#conference.localhost")
let xmppRoom: XMPPRoom = XMPPRoom(roomStorage: roomStorage,
jid: roomJID,
dispatchQueue: dispatch_get_main_queue())
xmppRoom.activate(SKxmpp.manager().xmppStream)
xmppRoom.addDelegate(self, delegateQueue: dispatch_get_main_queue())
//xmppRoom.configureRoomUsingOptions(nil)
xmppRoom.joinRoomUsingNickname(SKxmpp.manager().xmppStream.myJID.user, history: nil, password: nil)
xmppRoom.fetchConfigurationForm()
I want to add 4 members (who are already users in oprefire) to a group.
I want to add them without user permission nor sending invitation
Right now i am inviting a user using this code:
[sender inviteUser:[XMPPJID jidWithString:#"keithoys"] withMessage:#"Greetings!"];
Is there some another way to achieve this?
When user send request to other user, the following delegate method is called:
-(void)xmppMUC:(XMPPMUC *)sender roomJID:(XMPPJID *)roomJID didReceiveInvitation:(XMPPMessage *)message{
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()];
//Now add user to the group directly without prompting them
[xmppRoom joinRoomUsingNickname:[xmppStream myJID].user history:nil];
}
I've only written the code, if you need explanation, i'll.
Hi I'm developing a chat application in IOS and completed one to one chat, after searching a lot about groupChat, unable to got how to create a normal group in xmppframework.
What I already tried here is a link
iOS XMPP group chat implementation
Accepting chatroom invitation
How to create MultiUserChatRoom using XMPPFramework in iPhone
XMPPFramework - How to Create a MultiUserChat Rooms?
But didnt get any positive response from these above links,
In coding I tried
XMPPRoomCoreDataStorage *rosterstorage = [[XMPPRoomCoreDataStorage alloc] init];
XMPPRoom *xmppRoom = [[XMPPRoom alloc] initWithRoomStorage:rosterstorage jid:[XMPPJID jidWithString:#"test#conference.domainName.com/rohit"] dispatchQueue:dispatch_get_main_queue()];
[xmppRoom configureRoomUsingOptions:nil];
[xmppRoom activate:[self xmppStream]];
[xmppRoom addDelegate:self
delegateQueue:dispatch_get_main_queue()];
[xmppRoom inviteUser:[XMPPJID jidWithString:#"abc#domainName.com"] withMessage:#"Hi join room"];
Also this
- (void)createOrEnterRoom:(NSString *)roomName
{
//here we enter a room, or if the room does not yet exist, this method creates it
//per XMPP documentation: "If the room does not yet exist, the service SHOULD create the room"
//this method accepts an argument which is what you would baptize the room you wish created
XMPPPresence *presence = [XMPPPresence presence];
NSString *room = [roomName stringByAppendingString:#"#conference.domain.com"];
[presence addAttributeWithName:#"to" stringValue:room];
NSXMLElement *x = [NSXMLElement elementWithName:#"x" xmlns:#"http://jabber.org/protocol/muc"];
NSXMLElement *history = [NSXMLElement elementWithName:#"history"];
[history addAttributeWithName:#"maxstanzas" stringValue:#"50"];
[x addChild:history];
[presence addChild:x];
[[self xmppStream] sendElement:presence];
}
Last one is
-(void)createGroup
{
#try {
NSString *username=#"user_3";//[self.userDefault valueForKey:#"userid"];
NSXMLElement *presenceElement=[NSXMLElement elementWithName:#"presence"];
[presenceElement addAttributeWithName:#"type" stringValue:#"groupchat"];
[presenceElement addAttributeWithName:#"from" stringValue:[NSString stringWithFormat:#"%#%#",username,HostName]];
[presenceElement addAttributeWithName:#"to" stringValue:[NSString stringWithFormat:#"testGroup#conference.%#/%#",HostName,username]];
NSXMLElement *xElement=[NSXMLElement elementWithName:#"x" xmlns:#"http://jabber.org/protocol/muc"];
NSXMLElement *historyElement=[NSXMLElement elementWithName:#"history"];
[xElement addChild:historyElement];
[presenceElement addChild:xElement];
[self.xmppStream sendElement:presenceElement];
}
#catch (NSException *exception) {
}
}
Anyone please show me a way to solve out this. Please also let me know if we need to configure something extra in ejjabered configuration.
Please find go through this i found best and detailed answer here .
Trouble creating xmpp muc room: Code 503 (service unavailable)
Infact group chat is not provided by XMPP, its a chat room that you have created with XMPPRoom,
or you can say conversation.
You cant send offline group messages with this.
I have implement Group chat in my http://www.catchbuddies.com/ project with the help of other custom server.
You can make and configue group chat with the help of some webservces for Groups.
You should check your muc settings of ejabberd server configuration.
make sure muc host is set correctly.
in my case, I changed host to {host, "pub.#HOST#"}, then I tried to join room "test#conference.#HOST#" always got service unavailable error, it took me a whole night to fix.
also, you can use imessage login to your jabber server with admin user, and create chat room before you run ios client.
Change ejabberd log level to debug may help a lot.
For group creation change setting for muc_room. Also prefer this url will suggest the way for setting https://serverfault.com/questions/185770/configuring-ejabberd-for-multi-user-chat
In my application my User to User single chat is working perfectly.
but if I send the invitation of Room to any User then single chat is not working.
and I didn't attach group chat code in app yet. just send invitation of Room to other user and then creating single chat.
is there anything logically I missed ?
My code for creating and inviting
XMPPRoomMemoryStorage * _roomMemory = [[XMPPRoomMemoryStorage alloc]init];
NSString* roomID = [NSString stringWithFormat:#"%##conference.room",strGlobalRoomNameForLogin];
XMPPJID * roomJID = [XMPPJID jidWithString:roomID];
xmppRoom = [[XMPPRoom alloc] initWithRoomStorage:_roomMemory jid:roomJID dispatchQueue:dispatch_get_main_queue()];
[xmppRoom activate:xmppStream];
[xmppRoom joinRoomUsingNickname:[NSString stringWithFormat:#"%#",strCureentUserName] history:nil];
//NSLog(#"strCureentUserName %#",strCureentUserName);
//.........inviting the Friend.......
for (int i=0; i<[arrUserName count];i++) {
NSString *strInviteUserEmalid = [[arrUserName objectAtIndex:i] stringByReplacingOccurrencesOfString:#"#" withString:#"$"];
// NSLog(#"strInviteUserEmalid %#",strInviteUserEmalid);
[xmppRoom inviteUser:[XMPPJID jidWithString:[NSString stringWithFormat:#"%##user",strInviteUserEmalid]] withMessage:#"Come Join me in this room"];
}
[xmppRoom fetchConfigurationForm];
[xmppRoom configureRoomUsingOptions:nil];
[xmppRoom addDelegate:_roomMemory delegateQueue:dispatch_get_main_queue()];
For large numbers of invitees, you may be running into "karma" limits on your server. Try sending the invites slower by adding a timeout.
I am using Robbiehanson's iOS XMPPFramework. I am trying to create a MUC room and invite a user to the group chat room but it is not working.
I am using the following code:
XMPPRoom *room = [[XMPPRoom alloc] initWithRoomName:#"user101#conference.jabber.org/room" nickName:#"room"];
[room createOrJoinRoom];
[room sendInstantRoomConfig];
[room setInvitedUser:#"ABC#jabber.org"];
[room activate:[self xmppStream]];
[room inviteUser:jid1 withMessage:#"hello please join."];
[room sendMessage:#"HELLO"];
The user ABC#jabber.org should receive the invite message but nothing is happening.
Any help will be appreciated. :)
After exploring various solutions, I've decided to compile and share my implementation here:
Create an XMPP Room:
XMPPRoomMemoryStorage *roomStorage = [[XMPPRoomMemoryStorage alloc] init];
/**
* Remember to add 'conference' in your JID like this:
* e.g. uniqueRoomJID#conference.yourserverdomain
*/
XMPPJID *roomJID = [XMPPJID jidWithString:#"chat#conference.shakespeare"];
XMPPRoom *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:[self appDelegate].xmppStream.myJID.user
history:nil
password:nil];
Check if room is successfully created in this delegate:
- (void)xmppRoomDidCreate:(XMPPRoom *)sender
Check if you've joined the room in this delegate:
- (void)xmppRoomDidJoin:(XMPPRoom *)sender
After room is created, fetch room configuration form:
- (void)xmppRoomDidJoin:(XMPPRoom *)sender {
[sender fetchConfigurationForm];
}
Configure your room
/**
* Necessary to prevent this message:
* "This room is locked from entry until configuration is confirmed."
*/
- (void)xmppRoom:(XMPPRoom *)sender didFetchConfigurationForm:(NSXMLElement *)configForm
{
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"]];
}
}
[sender configureRoomUsingOptions:newConfig];
}
References: XEP-0045: Multi-User Chat, Implement Group Chat
Invite users
- (void)xmppRoomDidJoin:(XMPPRoom *)sender
{
/**
* You can read from an array containing participants in a for-loop
* and send multiple invites in the same way here
*/
[sender inviteUser:[XMPPJID jidWithString:#"keithoys"] withMessage:#"Greetings!"];
}
There, you've created a XMPP multi-user/group chat room, and invited a user. :)
I have the feeling that the first thing to do after alloc-init is to attach it to your xmppStream, so it can use xmppStream to send/receive messages.
More exactly:
XMPPRoom *room = [[XMPPRoom alloc] initWithRoomName:#"user101#conference.jabber.org/room" nickName:#"room"];
[room activate:[self xmppStream]];
//other things (create/config/...)
Check the latest XMPPMUCLight & XMPPRoomLight its similar to Whatsapp and other today's trends social app rooms that don't get destroyed or members kicked when offline or no one in room.
Refer this documentation & mod from MongooseIM