react-native-xmpp icon indicating copy to clipboard operation
react-native-xmpp copied to clipboard

How to join a room?

Open jzhw0130 opened this issue 7 years ago • 9 comments

Now I can connect the server, send message fro another account. If I want to join a chat room, chat with multi-users, how to implement?
Does the library support? If yes, which API should use?

Thanks

jzhw0130 avatar Dec 12 '17 14:12 jzhw0130

The library does not support the feature. Need to do by yourself. Code as follows:

Join a room:

        var builder = require('xmlbuilder');
        var xml = builder.begin()
                        .ele('presence',{'to':`${roomJID}/${nickName}`})
                        .ele('x', {'xmlns':'http://jabber.org/protocol/muc'})
                        .end({ pretty: true});
        XMPP.sendStanza(xml.toString());

Send group message:

        var builder = require('xmlbuilder');
        var xml = builder.begin()
                        .ele('message',{'to':`${roomJID}`, type:'groupchat'})
                        .ele('body', {}, message)
                        .end({ pretty: true});
        XMPP.sendStanza(xml.toString());

jzhw0130 avatar Dec 17 '17 13:12 jzhw0130

By the way, for the custom IQ message, Android needs to add custom Provider to support. Otherwise, parse will fail, you will get a UnParsed IQ.

jzhw0130 avatar Dec 17 '17 13:12 jzhw0130

Hello, I also met the same problem, through the way you mentioned that the group chat messages have been solved, but can not monitor the group chat messages, do you have a similar problem?

CocktailZY avatar May 17 '18 10:05 CocktailZY

Sorry, I have stopped using the library. Just use the service from PubNub.

jzhw0130 avatar May 18 '18 01:05 jzhw0130

@CocktailZY hello, how to monitor the group chat messages? Have you solved the problem?

heachou avatar Jun 14 '18 08:06 heachou

@heachou see my pull-request "multi-chat rooms"

andrzejbe avatar Jul 01 '18 17:07 andrzejbe

@andrzejbe How can I use your pull request into my project? is there any npm install available? or do I need to download all project?

vinayakb-pits avatar Aug 13 '18 13:08 vinayakb-pits

@vinayakb-pits - there's no npm as I (still) hope it will be merged with master branch at some point ;) for now you can use it as follows:

  • "npm install react-native-xmpp"
  • download .zip with my pull request (https://github.com/andrzejbe/react-native-xmpp)
  • replace "react-native-xmpp" folder in node_modules
  • only then run "pods install"
  • finally replace in Xcode:

@import KissXML = replace with => #import "KissXML.h" @import CocoaAsyncSocket = replace with => #import "GCDAsyncSocket.h"

hope it helps

andrzejbe avatar Aug 14 '18 06:08 andrzejbe

@andrzejbe I added your code as a library in my project and add "react-native-xmpp": "file:./src/libs/react-native-xmpp-master", in package json . It's working perfectly. Thank you very much

vinayakb-pits avatar Aug 14 '18 07:08 vinayakb-pits