Created
April 11, 2019 01:27
-
-
Save wsd1/99e42c902b7e0c2bfef8717b5ebff3d6 to your computer and use it in GitHub Desktop.
Deepstream登录退出presence API测试。结论是:可以很好的检测退出,包括正常退出,页面关闭和断网
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8" /> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> | |
<title>DsTest</title> | |
<meta name="viewport" content="width=device-width, initial-scale=1" /> | |
<!--link rel="stylesheet" type="text/css" media="screen" href="main.css" /--> | |
<script src="https://cdn.bootcss.com/deepstream.io-client-js/2.2.1/deepstream.js"></script> | |
<script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script> | |
<script> | |
var ds = null; | |
//换上合适的用户名和JWT | |
$(function() { | |
$("#login").click(function() { | |
ds = deepstream("wss://ucast.cc/deepstream").login( | |
{ | |
username: "LCMvyuT6cc", | |
password: "", | |
token: | |
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJ1Y2FzdC5jYy9hcGkiLCJhdWQiOiJ1Y2FzdC5jYy9hcGkiLCJzdWIiOiJMQ012eXVUNmNjIiwibmljayI6IkRpbmd5aSIsImlhdCI6MTU1NDk0NDQ0NywiZXhwIjoxNTU3NTM2NDQ3LCJqdGkiOiIxMjM0NSIsInBlcm1pdCI6WyJidXMiXX0.yr7nUv8pcFXm9TyVB5CEICVfA-5TK9Kcbxv0picjEcc" | |
}, | |
startApp | |
); | |
}); | |
}); | |
function startApp(success, data) { | |
if (!success) { | |
alert(`登录失败!${ds.getConnectionState()}`); | |
return; | |
} | |
console.log("登录成功!"); | |
} | |
</script> | |
</head> | |
<body> | |
<button style="width: 100%;height: 60px; margin-bottom: 10px;" id="login"> | |
login | |
</button> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8" /> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> | |
<title>DsTest</title> | |
<meta name="viewport" content="width=device-width, initial-scale=1" /> | |
<!--link rel="stylesheet" type="text/css" media="screen" href="main.css" /--> | |
<script src="https://cdn.bootcss.com/deepstream.io-client-js/2.2.1/deepstream.js"></script> | |
<script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script> | |
<script> | |
var dsClient = null; | |
//换上合适的用户名和JWT | |
$(function() { | |
$("#login").click(function() { | |
dsClient = deepstream("wss://ucast.cc/deepstream").login( | |
{ | |
username: "gQAJ2Ya5et", | |
password: "", | |
token: | |
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJ1Y2FzdC5jYy9hcGkiLCJhdWQiOiJ1Y2FzdC5jYy9hcGkiLCJzdWIiOiJnUUFKMllhNWV0IiwibmljayI6IndzZDEiLCJpYXQiOjE1NTQ5NDUzMTUsImV4cCI6MTU1NzUzNzMxNSwianRpIjoiMTIzNDUiLCJwZXJtaXQiOlsiYnVzIl19.fEK14FqF7jWC2QO6O55MMOrY91ZeFVPeDpjkp0VJQrY" | |
}, | |
startApp | |
); | |
}); | |
}); | |
function startApp(success, data) { | |
if (!success) { | |
alert(`登录失败!${dsClient.getConnectionState()}`); | |
return; | |
} | |
console.log("登录成功!"); | |
dsClient.presence.subscribe((username, login) => { | |
if (login === true) { | |
console.log(`${username} Login.`); | |
} else { | |
console.log(`${username} Logout.`); | |
} | |
}) | |
} | |
</script> | |
</head> | |
<body> | |
<button style="width: 100%;height: 60px; margin-bottom: 10px;" id="login"> | |
login | |
</button> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment