Question

I am building a web-application chat. I want to know how to send the connection status once the authentication is successful to the next page. The gateway would be the login page.

login.html

<html>
<script src="scripts/login.js"></script>
<script src="scripts/strophe.js"></script>
<form>
JID: <input type="text" name="username" id="username"><br/>
Password: <input type="password" name="password" id="password">
<input type="button" value="Connect" id="connect"/>
</form>
</html>

login.js

var BOSH_SERVICE = "http://127.0.0.1:7070/http-bind/";
$(function{
var connection = new Strophe.Connection(BOSH_SERVICE);
var jid = $('#username').val();
var password = $('#password').val();

//connection
connection.connect(jid, password, callback());

});

function callback(status){
//authentication code here

else if(status==Strophe.Status.CONNECTED){
 log(connected);
 windows.location = "chat.html";
}

}

How do I keep the session alive so that when the page redirects to chat.html it will still be connected. Thanks. Need help really soon.

Était-ce utile?

La solution

You can store the BOSH 'sid' and 'rid' values, either locally or on the server, and re-attach to the connection from the new page.

An overview of doing with Strophe.js is described in this article: Getting attached to Strophe. Other libraries will likely have similar mechanisms, as this is a common BOSH technique.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top