I used the example here example with strophe JS and it worked correctly, but when I tried to do the same with stroph Dart, it does not work and I can not receive messages.
eliminating connection.send($pres().tree());
of the code in JS I do not receive messages either, the problem is that I do not know how to transform that to Strophe Dart.
String mi_jid;
var _domain = "localhost";
String host = 'my_server_ip';
StropheConnection _connection;
log(msg)
{
print(msg);
}
onMessage(msg) {
print("mensaje recibido");
var to = msg.getAttribute('to');
var from = msg.getAttribute('from');
var type = msg.getAttribute('type');
var elems = msg.getElementsByTagName('body');
if (type == "chat" && elems.length > 0) {
var body = elems[0];
print('ECHOBOT: I got a message from ' + from + ': ' +
Strophe.getText(body));
}
// we must return true to keep the handler alive.
// returning false would remove it after it finishes.
return true;
}
onConnect(status)
{
if (status == Strophe.Status['CONNECTING']) {
log('Strophe is connecting.');
}
else if (status == Strophe.Status['CONNFAIL']) {
log('Strophe failed to connect.');
} else if (status == Strophe.Status['DISCONNECTING']) {
log('Strophe is disconnecting.');
} else if (status == Strophe.Status['DISCONNECTED']) {
log('Strophe is disconnected.');
}
else if (status == Strophe.Status['CONNECTED']) {
log('Strophe is connected.');
log('ECHOBOT: Send a message to ' + _connection.jid +
' to talk to me.');
_connection.addHandler(onMessage, null, 'message', null, null, null);
}
}
void _inicia_sesion() async {
_connection = Strophe.Connection("ws://"+ host +":7070/ws/");
print("iniciando conexion....");
/*
_connection.xmlInput = (elem) {
print('input $elem');
};
_connection.xmlOutput = (elem) {
print('output $elem');
};
*/
_connection.connect('user1@localhost', 'password',
(int status, condition, ele){
onConnect(status);
});
}
Please help me