Search code examples
javascriptxmppregistrationstrophe

Strophe.js in-band Registration


I know that there are many other questions related to strophe in-band registration and XEP 0077 but my question is the following:

I'm trying to write in the correct form the following stanza:

<iq to='marlowe.shakespeare.lit' type='set'>
  <query xmlns='jabber:iq:register'>
    <username>juliet</username>
    <password>R0m30</password>
    <name>JJ</name>
  </query>
</iq>

But I'm unable to write it correctly. I'm stuck on how to write the username, password, and name fields in javascript.

This is what I wrote so far:

connection.sendIQ($iq({to: "server", type: "set"}).c('query', {xmlns: "jabber:iq:register"}).c)

Any help is greatly appreciated!


Solution

  • I know this is an old post, but I think the Strophe Plugin for In-Band Registration is exactly what you were looking for!

    <head>
    <!-- ... -->
    <script type="text/javascript" src="strophe.min.js"></script>
    <script type="text/javascript" src="strophe.register.js"></script>
    <!-- ... -->
    </head>
    

    Javascript:

    var callback = function (status) {
        if (status === Strophe.Status.REGISTER) {
            connection.register.fields.username = "juliet";
            connection.register.fields.password = "R0m30";
            connection.register.submit();
        } else if (status === Strophe.Status.REGISTERED) {
            console.log("registered!");
            connection.authenticate();
        } else if (status === Strophe.Status.CONNECTED) {
            console.log("logged in!");
        } else {
            // every other status a connection.connect would receive
        }
    };
    connection.register.connect("example.com", callback, wait, hold);