xunfei-wss/app/view/index/view.html
2024-01-04 18:59:55 +08:00

38 lines
1.1 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="shortcut icon" href="/favicon.ico"/>
<title>webman</title>
<script src="/js/push.js"> </script>
</head>
<body>
hello <span id="text1">123</span>
<script>
// 建立连接
var connection = new Push({
url: 'ws://192.168.1.21:3131', // websocket地址
app_key: 'aaea61749929eb53a4bd75a1474c1d27',
});
// 假设用户uid为1
var uid = 2;
// 浏览器监听user-2频道的消息也就是用户uid为1的用户消息
var user_channel = connection.subscribe('user-' + uid);
// 当user-2频道有message事件的消息时
user_channel.on('message', function(data) {
// data里是消息内容
console.log(data.content.name);
document.getElementById('text1').innerHTML = data.content.name;
});
// 断线事件
user_channel.on('close', function() {
});
</script>
</body>
</html>