strophe.register.js
A Strophe Plugin for In-Band Registration. ( XEP 0077 )
Usage
Just link the register plugin below the strophe library in your HTML head section:
<!-- ... --><!-- ... -->
To register a JID you need to listen for REGISTER und REGISTERED in your connection callback and use connection.register.connect() instead of connection.connect().
On REGISTER you need to inspect the connection.register.fields
object, fill in every field and call connection.register.submit().
(There may be more fields than username and password!)
On REGISTERED you can can then call connection.authenticate() if you want to login normally with the account you just created.
You should also listen for CONFLICT, REGIFAIL and NOTACCEPTABLE to catch failure-status of registrations.
Example for registering a new account and logging in with it:
var {if status === StropheStatusREGISTER// fill out the fieldsconnectionregisterfieldsusername = "juliet";connectionregisterfieldspassword = "R0m30";// calling submit will continue the registration processconnectionregister;else if status === StropheStatusREGISTEREDconsole;// calling login will authenticate the registered JID.connection;else if status === StropheStatusCONFLICTconsole;else if status === StropheStatusNOTACCEPTABLEconsoleelse if status === StropheStatusREGIFAILconsoleelse if status === StropheStatusCONNECTED// do something after successful authenticationelse// Do other stuff};connectionregister;
After that you're logged in with a fresh jid.