3

I am using Strophe.js to connect with XMPP server in angular6. connection.addHandler() is method to receive messages.

My component structure is

Parent Component:

which contains users list with whom I chat and latest message below user name, which is at left side of page.

e.g.

user1

Hi...

Child Component: In right side there are chat messages with particular user, like two way chat window.

Refer enclosed images for structure. enter image description here enter image description here

When I receive message from user1, it appears in left side i.e. below user1 name ('Hi' will be replaced with new latest message) This is handled with connection.addHandler() call for left side/parent component.

This code should also be automatically executed for child component. So that new latest message should appear in chat list, but that is not happening.

Here is the listener code:

 `connectionXmpp.connection.addHandler((msg) => {
    console.log(msg)
    return true;
}, null, 'message')`

I have added connection.addHandler() listener in parent as well as in child component, also tried only in parent component by using if else conditions, but in vain.

Please let me know, where I did wrong or have any solution to call listener in both parent and child component.

Community
  • 1
  • 1
Amol Chakane
  • 1,501
  • 2
  • 21
  • 43
  • You should be using the same `Strophe.Connection` instance everywhere, i.e. you shouldn't need to add more than one handler for the same thing. It might help your debugging if you set Connection.rawInput and Connection.rawOutput as per the docs to log all XMPP communication -- that way you'll know if you're at least receiving the messages. http://strophe.im/strophejs/doc/1.3.0/files/strophe-js.html#Strophe.Connection.Strophe.Connection – tao_oat Dec 21 '18 at 13:37

0 Answers0