Question

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!

Was it helpful?

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);

OTHER TIPS

Use Strophe and the connect function if you are going to use javascript.

connection.connect(jid, password, cb);

In-band registration is for non-javascript use. You would assemble the body and send the string to your jabber server. See http://metajack.im/2008/10/03/getting-attached-to-strophe/ for an example.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top