12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- // 站点工况(websocket实时推送)
- (function() {
- var flag = false;
- var aa = false;
- var arrData = [];
- var wsUri = "wss://iot.usky.cn:55120";
- var websocket;
- function initWebSocket() {
- try {
- if (typeof MozWebSocket == 'function')
- WebSocket = MozWebSocket;
- websocket = new WebSocket(wsUri);
- websocket.onopen = function(evt) {
- var json = {};
- json.agentid = 'admin';
- console.log("Connected.");
- (function() {})()
- websocket.send(JSON.stringify(json));
- };
- websocket.onclose = function(evt) {
- console.log("DisConnected.");
- (function() {})()
- initWebSocket();
- };
- websocket.onmessage = function(evt) {
- var siteData = eval('(' + evt.data + ')');
- console.log('siteData')
- console.log(siteData)
- // console.log('arrData')
- // console.log(arrData)
- //返回值渲染
- if (siteData.time && aa) {
- $('.receive-time').text('[' + siteData.time + ' 收到]')
- $(".receive-request").text(JSON.stringify(siteData, null, 2));
- }
- };
- websocket.onerror = function(evt) {
- console.log("Error:", evt.data);
- (function() {})()
- };
- } catch (exception) {
- console.log("Exception:", exception);
- (function() {})()
- }
- }
- //打开websocket
- $('.openWebsocket').on('click', function() {
- initWebSocket();
- flag = true;
- })
- //站点工况点击
- $('.siteCondition').on('click', function() {
- aa = true;
- if (!flag) {
- alert('请先打开连接')
- return
- }
- var stationId = $('#stationId').val()
- var stationName = $('#stationName').val()
- var json = {};
- json.CMD = 'getStationInfo';
- json.StationID = stationId;
- json.StationName = stationName;
- //发送时间和请求参数页面渲染
- time('.send-time');
- $(".send-request").text(JSON.stringify(json, null, 2));
- websocket.send(JSON.stringify(json));
- })
- })()
|