1

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.

4

1 に答える 1

1

BOSH の「sid」と「rid」の値をローカルまたはサーバーに保存し、新しいページから接続に再接続できます。

Strophe.jsの使用の概要については、次の記事で説明しています: Strophe への接続。これは一般的な BOSH 手法であるため、他のライブラリにも同様のメカニズムがある可能性があります。

于 2013-08-11T15:44:55.453 に答える