Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Strophe receive only one message

    • 1
    • 0
    • 0
    • 1
    • 0
    • 0
    • 0
    • 1.43k
    Answer it

    Hi..I want to create a chat app.I'm using Strophe js with and xmpp server.I send a message to another client(Spark) and after that i can send one message from Spark to strophe client.Here is my code.I wil appreciate any help :)

    var connection = new Strophe.Connection('http://localhost:5280/http-bind/');
    
                    connection.connect('marian112@localhost', 'secret', function (status)
                        {
                            if (status == Strophe.Status.CONNECTED)
                            {   
                                console.log('Connected to server')
                                //connection.jid='marian12@localhost'
                                connection.addHandler(on_chat_message, null, 'message', 'chat',null,null);
                                connection.send($pres().c("priority").t("10"));
                                connection.addHandler(on_presence, null, 'presence');
                                connection.addHandler(on_error_iq, null, 'iq', 'error');
                                connection.send($pres().tree());
                                console.log(connection.jid);
                                var sendMessageQuery = $msg({to: 'marian@localhost/BBXFRONT', type: 'chat'}).c('body').t('AAAAAA');
                                connection.send(sendMessageQuery);
                            }
                        });
                    var on_chat_message=function(msg) {
                        var sendMessageQuery = $msg({to: 'marian@localhost/BBXFRONT', type: 'chat'}).c('body').t('bbbb');
                        connection.send(sendMessageQuery);
                    console.log(msg);
                    console.log('You have received a message!');
                    var to = msg.getAttribute('to');
                    var from = msg.getAttribute('from');
                    var type = msg.getAttribute('type');
                    console.log(to+'  '+from+'   '+type);
                    var elems = msg.getElementsByTagName('body');
                    var message=Strophe.getText(body);
                    console.log(message);
                    return true;
                }
    
                var on_presence=function(stanza) {
                    console.log(stanza);
                    return true;
                }
    
                var on_error_iq=function(stanza) {
                    console.log(stanza);
                    return true;
                }
    

 1 Answer(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: