物联网平台 +Web 组态
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.

88 lines
2.2 KiB

2 years ago
$(function(){
var ws = null ;
if(!judgeBrowser()){connect();}else{tooltips("您当前浏览器版本过低,部分功能将不能使用,请尽快升级浏览器版本,谢谢!",1,3000);}
/**
* 连接
*/
function connect() {
// $.notifySetup({sound: vedio_url+'/audio/notify.wav'});
//$.notifySetup({sound: vedio_url+'/audio/warning.mp3'});
if (!websocket_url) {
return;
}
ws = new WebSocket(websocket_url);
ws.onopen = function () {
echo();
console.log("连接成功!");
};
ws.onmessage = function (event) {
var data = eval('('+ event.data + ')');
if(data.sof=='1') {
self.location.href = frontpath;
}
alert('23:'+websocket_process);
if(wpmain!=null && wpmain!='undefined') {
wpmain(data);
}
};
ws.onclose = function (event) {
console.log('Info: connection closed.');
connect();
};
ws.onerror = function(event) {
disconnect();
console.log('Info: connection error.');
};
}
/**
* 关闭连接
*/
function disconnect() {
if (ws != null) {
ws.close();
ws = null;
}
}
/**
* 发送数值
*/
function echo() {
if (ws != null) {
var data = "{'ukey':'"+ ukey +"' , 'message':'CoNNEct'}";
ws.send(data);
} else {
console.log('websockket:connection not established, please connect.');
}
}
});
/**
* 判断浏览器是否是IE 6,7,8,9
*/
function judgeBrowser(){
var browser=navigator.appName
var b_version=navigator.appVersion
var version=b_version.split(";");
if(version!=null && version.length > 1){
var trim_Version=version[1].replace(/[ ]/g,"");
if(browser=="Microsoft Internet Explorer" && trim_Version=="MSIE6.0")
{
return true ;
}
else if(browser=="Microsoft Internet Explorer" && trim_Version=="MSIE7.0")
{
return true ;
}
else if(browser=="Microsoft Internet Explorer" && trim_Version=="MSIE8.0")
{
return true ;
}
else if(browser=="Microsoft Internet Explorer" && trim_Version=="MSIE9.0")
{
return true ;
}
}
return false ;
}