From 0c08e93ba1fc8cf675b24ad9aaa59a2857e9f662 Mon Sep 17 00:00:00 2001 From: fan <18706759286@163.com> Date: Tue, 21 Jul 2020 10:01:19 +0800 Subject: [PATCH] =?UTF-8?q?websocket=E8=B0=83=E6=95=B4&ibp=E8=AE=BE?= =?UTF-8?q?=E5=A4=87=E9=85=8D=E7=BD=AE=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 1 - .../jl3ddevicetrain/component/StompClient.js | 56 +++++++++---------- src/utils/baseUrl.js | 4 +- src/utils/sock.js | 29 ++-------- .../system/deviceManage/editConfigIbp.vue | 9 ++- 5 files changed, 38 insertions(+), 61 deletions(-) diff --git a/package.json b/package.json index b7dc55048..b8f859114 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,6 @@ "recordrtc": "^5.5.9", "script-loader": "^0.7.2", "sessionstorage": "^0.1.0", - "sockjs-client": "^1.4.0", "stompjs": "^2.3.3", "storejs": "^1.0.25", "three": "^0.107.0", diff --git a/src/jlmap3d/jl3ddevicetrain/component/StompClient.js b/src/jlmap3d/jl3ddevicetrain/component/StompClient.js index eed528e23..d8d0b3cdc 100644 --- a/src/jlmap3d/jl3ddevicetrain/component/StompClient.js +++ b/src/jlmap3d/jl3ddevicetrain/component/StompClient.js @@ -1,19 +1,17 @@ -import SockJS from 'sockjs-client'; import Stomp from 'stompjs'; import { getBaseUrl } from '@/utils/baseUrl'; const BASE_API = getBaseUrl(); -let baseUrl = "http://192.168.3.6:9600";//本地旭强 -if(BASE_API == 'https://joylink.club/jlcloud'){ - baseUrl = "https://joylink.club/relay"; -}else if(BASE_API == 'https://test.joylink.club/jlcloud'){ - baseUrl = "https://test.joylink.club/relay"; +let baseUrl = 'http://192.168.3.6:9600';// 本地旭强 +if (BASE_API == 'https://joylink.club/jlcloud') { + baseUrl = 'https://joylink.club/relay'; +} else if (BASE_API == 'https://test.joylink.club/jlcloud') { + baseUrl = 'https://test.joylink.club/relay'; } class StompClient { - constructor() { - const ws = new SockJS(`${baseUrl}/ws-relay`); + const ws = new WebSocket(`${baseUrl}/ws-relay`.replace(/https/, 'wss').replace(/http/, 'ws')); this.client = Stomp.over(ws); this.client.debug = function (message) { console.debug(message); @@ -24,27 +22,27 @@ class StompClient { } connect() { - return new Promise((resolve, reject) => { - this.onUsed = true; - const that = this; - const header = { - login: 'relay', - passcode: 'relay' - }; - this.client.connect(header, - ()=>{ - that.connected = true; - // 重连时需要重新订阅 - that.subscribeMap.forEach((subscribe, dest) => { - that.subscribe(subscribe.dest, subscribe.handler); - }); - resolve(); - }, - (error)=>{ - console.error(error); - this.connected = false; - reject(error); - }); + return new Promise((resolve, reject) => { + this.onUsed = true; + const that = this; + const header = { + login: 'relay', + passcode: 'relay' + }; + this.client.connect(header, + ()=>{ + that.connected = true; + // 重连时需要重新订阅 + that.subscribeMap.forEach((subscribe, dest) => { + that.subscribe(subscribe.dest, subscribe.handler); + }); + resolve(); + }, + (error)=>{ + console.error(error); + this.connected = false; + reject(error); + }); }); } diff --git a/src/utils/baseUrl.js b/src/utils/baseUrl.js index 778caeb7b..c59924e25 100644 --- a/src/utils/baseUrl.js +++ b/src/utils/baseUrl.js @@ -2,9 +2,9 @@ export function getBaseUrl() { let BASE_API; if (process.env.NODE_ENV === 'development') { // BASE_API = 'https://joylink.club/jlcloud'; - BASE_API = 'https://test.joylink.club/jlcloud'; + // BASE_API = 'https://test.joylink.club/jlcloud'; // BASE_API = 'http://192.168.3.5:9000'; // 袁琪 - // BASE_API = 'http://192.168.3.6:9000'; // 旭强 + BASE_API = 'http://192.168.3.6:9000'; // 旭强 // BASE_API = 'http://192.168.3.41:9000'; // 张赛 // BASE_API = 'http://192.168.3.82:9000'; // 杜康 // BASE_API = 'http://b29z135112.zicp.vip'; diff --git a/src/utils/sock.js b/src/utils/sock.js index 5af53a1d8..80517e316 100644 --- a/src/utils/sock.js +++ b/src/utils/sock.js @@ -3,7 +3,6 @@ import { checkLoginLine } from '@/api/login'; import { getBaseUrl } from '@/utils/baseUrl'; import { MessageBox } from 'element-ui'; import store from '@/store/index_APP_TARGET'; -import SockJS from 'sockjs-client'; import Stomp from 'stompjs'; const isDev = process.env.NODE_ENV === 'development'; @@ -19,7 +18,7 @@ var StompClient = function (headers) { }; StompClient.prototype = { - socket: null, + websocket: null, clientIns: null, url: '', status: false, @@ -34,27 +33,10 @@ StompClient.prototype = { // 连接服务端 connect() { - // 建立连接对象(还未发起连接) - // (null, {transports:['websocket']})虽可以解决连接关闭后xhr_streaming无限循环 - // 但是该参数只会允许websockets,若不支持,直接报错 - // 注意sockjs会做降级处理,优先处理websockets,若浏览器不支持websockets - // 则会降级为xhr_streaming(轮询),继续不支持的时候会降级为xhr-polling - - // const oldtransportClose = SockJS.prototype._transportClose; - // SockJS.prototype._transportClose = function(code, reason) { - // // To do - // // ... - // console.log(reason + '-----------------', this._transport); - // if (this._transport && this._transport.close) { - // this._transport.close(); - // } - // return oldtransportClose.call(this, code, reason); - // }; - // 向服务器发起websocket连接并发送CONNECT帧 - this.socket = new SockJS(websocketUrl + getToken()); + this.websocket = new WebSocket(this.url.replace(/https/, 'wss').replace(/http/, 'ws')); // 获取 STOMP 子协议的客户端对象 - this.clientIns = Stomp.over(this.socket); + this.clientIns = Stomp.over(this.websocket); this.closeStompDebug(); const that = this; this.clientIns.connect({ 'X-Token': getToken() }, () => { @@ -70,7 +52,6 @@ StompClient.prototype = { }); // sock断开回调 that.clientIns.ws.onclose = () => { - // Message.error(`通信连接已断开!`); console.info(`通信连接已断开!`); checkLoginLine().then(() => { that.count++; @@ -161,8 +142,8 @@ StompClient.prototype = { this.clientIns.disconnect(); } this.isPassived = false; - this.socket.close(); - this.socket = null; + this.websocket.close(); + this.websocket = null; this.clientIns = null; } this.status = false; diff --git a/src/views/system/deviceManage/editConfigIbp.vue b/src/views/system/deviceManage/editConfigIbp.vue index 090249ee0..020a8fb65 100644 --- a/src/views/system/deviceManage/editConfigIbp.vue +++ b/src/views/system/deviceManage/editConfigIbp.vue @@ -279,7 +279,6 @@ import { getDeviceDetail, setIbpConfig} from '@/api/project'; import { deepAssign } from '@/utils/index'; import { getAllMapOnline, getStationListNeedAttendant } from '@/api/jmap/map'; const propMap = { - addr: '网关位地址', ribpsd: 'IBP盘试灯按钮', wibpsdand: 'IBP盘试灯指示灯', afczjConfig: { @@ -446,7 +445,7 @@ const propMap = { rxxsd: '下行试灯按钮[信号配置]', wfmq: '蜂鸣器[信号配置]', wsxjjtccand: '上行紧急停车按钮灯[信号配置]', - wsxjjtczsd: '上行取消紧急停车指示灯[信号配置]', + wsxjjtczsd: '上行紧急停车指示灯[信号配置]', wsxjljcand: '上行警铃解除按钮灯[信号配置]', wsxkcand: '上行扣车按钮灯[信号配置]', wsxkczsd: '上行扣车指示灯[信号配置]', @@ -455,7 +454,7 @@ const propMap = { wsxqxkczsd: '上行取消扣车指示灯[信号配置]', wsxsdand: '上行试灯按钮灯[信号配置]', wxxjjtccand: '下行紧急停车按钮灯[信号配置]', - wxxjjtczsd: '下行取消紧急停车按钮灯[信号配置]', + wxxjjtczsd: '下行紧急停车指示灯[信号配置]', wxxjljcand: '下行警铃解除按钮灯[信号配置]', wxxkcand: '下行扣车按钮灯[信号配置]', wxxkczsd: '下行扣车指示灯[信号配置]', @@ -711,7 +710,7 @@ export default { items:[ { prop:'wfmq', label: '蜂鸣器:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0, size: 'small', noControls: true}, { prop:'wsxjjtccand', label: '上行紧急停车按钮灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0, size: 'small', noControls: true}, - { prop:'wsxjjtczsd', label: '上行取消紧急停车指示灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0, size: 'small', noControls: true}, + { prop:'wsxjjtczsd', label: '上行紧急停车指示灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0, size: 'small', noControls: true}, { prop:'wsxjljcand', label: '上行警铃解除按钮灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0, size: 'small', noControls: true}, { prop:'wsxkcand', label: '上行扣车按钮灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0, size: 'small', noControls: true}, { prop:'wsxkczsd', label: '上行扣车指示灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0, size: 'small', noControls: true}, @@ -720,7 +719,7 @@ export default { { prop:'wsxqxkczsd', label: '上行取消扣车指示灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0, size: 'small', noControls: true}, { prop:'wsxsdand', label: '上行试灯按钮灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0, size: 'small', noControls: true}, { prop:'wxxjjtccand', label: '下行紧急停车按钮灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0, size: 'small', noControls: true}, - { prop:'wxxjjtczsd', label: '下行取消紧急停车按钮灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0, size: 'small', noControls: true}, + { prop:'wxxjjtczsd', label: '下行紧急停车指示灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0, size: 'small', noControls: true}, { prop:'wxxjljcand', label: '下行警铃解除按钮灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0, size: 'small', noControls: true}, { prop:'wxxkcand', label: '下行扣车按钮灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0, size: 'small', noControls: true}, { prop:'wxxkczsd', label: '下行扣车指示灯:', type: 'number', min: 0, max: 20000, step: 1, precisionFlag: true, precision: 0, size: 'small', noControls: true},