Dual-Login
You should use this method if you have already a login in your website.
<form id="form"> <input type="text" id="username" /> <input type="password" id="password" /> <input type="submit" value="Submit" /> </form> <button id="logout">Logout</button>
let jsxc = new JSXC();
let formElement = $('#form');
let usernameElement = $('#username');
let passwordElement = $('#password');
let logoutElement = $('#logout');
function getSettings(username, password) {
return Promise.resolve({
xmpp: {
url: '/http-bind/',
domain: 'localhost',
}
});
}
jsxc.watchForm(formElement, usernameElement, passwordElement, getSettings);
jsxc.watchLogoutClick(logoutElement);
Instant Login
Do you want to login directly within your script? Choose this type.
<input type="text" id="username" /> <input type="password" id="password" /> <button id="submit">Log in</button>
let jsxc = new JSXC();
$('#submit').click(function(){
let username = $('#username').val();
let password = $('#password').val();
let url = '/http-bind/';
let jid = username + '@localhost';
jsxc.start(url, jid , password);
});
Prelogin
Attach to existing BOSH connection after JSXC was initialized.
let jsxc = new JSXC(); let url = '/http-bind/'; let jid = 'username@localhost'; let sid = 'YOUR_SID'; let rid = 'YOUR_RID'; jsxc.start(url, jid, sid, rid);