You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
74 lines
2.8 KiB
74 lines
2.8 KiB
<!DOCTYPE html>
|
|
|
|
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
|
|
<head>
|
|
<meta charset="utf-8" />
|
|
<title></title>
|
|
|
|
</head>
|
|
<body>
|
|
<script type="text/javascript" src="https://cdn.goeasy.io/goeasy-2.11.1.min.js"></script>
|
|
<script type="text/javascript" async>
|
|
var user;
|
|
var goeasy;
|
|
async function init() {
|
|
var hostOjbect = await window?.chrome?.webview?.hostObjects?.sync?.qymsgcenter;
|
|
var userString = hostOjbect.GetUserString();
|
|
user = JSON.parse(userString);
|
|
//alert(user.Name);
|
|
|
|
goeasy = GoEasy.getInstance({
|
|
host: "hangzhou.goeasy.io", //若是新加坡区域:singapore.goeasy.io
|
|
appkey: "BC-652c4236c6ba4083b026e8cfa2e199b1",
|
|
modules: ['pubsub']//根据需要,传入‘pubsub’或'im’,或数组方式同时传入
|
|
});
|
|
|
|
//建立连接
|
|
goeasy.connect({
|
|
onSuccess: function () { //连接成功
|
|
//hostOjbect.OnError("GoEasy connect successfully");
|
|
console.log("GoEasy connect successfully.") //连接成功
|
|
subscribe();
|
|
},
|
|
onFailed: function (error) { //连接失败
|
|
var msg = "Failed to connect GoEasy, code:" + error.code + ",error:" + error.content;
|
|
hostOjbect.OnError(msg);
|
|
console.log(msg);
|
|
},
|
|
onProgress: function (attempts) { //连接或自动重连中
|
|
console.log("GoEasy is connecting", attempts);
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
function subscribe() {
|
|
var pubsub = goeasy.pubsub;
|
|
|
|
for (var i = 0; i < user.DepartmentList.length; i++) {
|
|
var channel = user.DepartmentList[i].Id;
|
|
pubsub.subscribe({
|
|
channel: channel,//替换为您自己的channel
|
|
onMessage: function (message) {
|
|
//收到消息
|
|
console.log("Channel:" + message.channel + " content:" + message.content);
|
|
hostOjbect.OnReceiveMessage(message.channel, message.content);
|
|
},
|
|
onSuccess: function () {
|
|
//hostOjbect.OnError("Channel订阅成功。");
|
|
var msg = `channel ${channel} 订阅成功`;
|
|
console.log(msg);
|
|
},
|
|
onFailed: function (error) {
|
|
var msg = "Channel订阅失败, 错误编码:" + error.code + " 错误信息:" + error.content;
|
|
hostOjbect.OnError(msg);
|
|
console.log(msg)
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
init();
|
|
</script>
|
|
</body>
|
|
</html>
|