Reputation: 315
I am using openfire as an XMPP server and using converse as client library. I want to send a chat message from my chat window to openfire. For this I want to send the text to a converse method which will send the message to the XMPP server. I am trying to send the message using the following:
var msg = converse.env.$msg({
from: 'a1@localhost',
to: 'a6@localhost',
type: 'chat',
body: "Hi"
});
converse.send(msg);
But this sends the following frame in network of console in websocket:
message from='a1@localhost' to='a6@localhost' type='chat' body='Hi' xmlns='jabber:client'/>
This does not transfer message to the other user neither it stores it in the table. I am pretty much sure I am calling a wrong function. Can anyone povide any help.
Upvotes: 1
Views: 1827
Reputation: 336
The syntax is wrong. conversejs uses strophe plugin to construct and send messages. It exposes the strophe $msg message builder for constructing stanzas. It has to be in the following format:
converse.env.$msg({from: 'a1@localhost', to: 'a6@localhost', type: 'chat'}).c('body').t('Hi');
You need to add a body node and within it a text node for the message.
You can also create and add your own api method and internally create a method that sends your custom stanza, and expose it using the api.
Upvotes: 1
Reputation: 2940
You are calling the right function.
What you'll probably miss:
Listener of messages in "a6@localhost" client: as I read in documentation there are few functions
Probably, the right name of server. "localhost" has problem. You can check Openfire for real service name on his own web panel
https://conversejs.org/docs/html/development.html
converse.chats.open('[email protected]');
converse.chats.get('[email protected]');
converse.listen.on('message', function (event, messageXML) { ... });
Upvotes: 2