Commit cc008975 by 周志凯

nature socket

1 parent 5cbfc59c
Showing 1 changed file with 48 additions and 13 deletions
...@@ -1498,7 +1498,7 @@ ...@@ -1498,7 +1498,7 @@
stepList: [] stepList: []
}; };
obj.stepType = wsUrl; obj.stepType = wsUrl;
obj.mark = params.mark || params.featureType; obj.mark = params.mark;
if (!webSockUrl) { if (!webSockUrl) {
webSock = window.location.host; webSock = window.location.host;
} }
...@@ -1857,7 +1857,10 @@ ...@@ -1857,7 +1857,10 @@
// 参数 mallIds,startDate,endDate,scheduleType // 参数 mallIds,startDate,endDate,scheduleType
// 店员重新比对 /mall/staff // 店员重新比对 /mall/staff
// 参数 mallIds,startDate,endDate,scheduleType // 参数 mallIds,startDate,endDate,scheduleType
this.socket && this.socket.close() if (this.socket) {
this.socket.close()
this.socket = null
}
this.results = [] this.results = []
this.startTiming = 0 this.startTiming = 0
this.endTiming = 0 this.endTiming = 0
...@@ -1904,21 +1907,23 @@ ...@@ -1904,21 +1907,23 @@
wsUrl = webSockUrl || window.location.host, wsUrl = webSockUrl || window.location.host,
socketUrl = "ws://" + wsUrl + "/recal/schedule/" + scheduleType socketUrl = "ws://" + wsUrl + "/recal/schedule/" + scheduleType
console.log('[socketUrl]:', socketUrl) console.log('[socketUrl]:', socketUrl)
self.socket = new ws(socketUrl) if ("WebSocket" in window) {
self.socket.onconnecting = function (ev) { self.socket = new WebSocket(socketUrl);
console.log('socket:onconnecting', ev) } else if ("MozWebSocket" in window) {
self.socket = new MozWebSocket(socketUrl);
} else {
self.socket = new SockJS(socketUrl);
} }
try {
self.socket.onopen = function(ev) { self.socket.onopen = function(ev) {
console.log('socket:onopen', ev)
self.startTiming = +new Date() self.startTiming = +new Date()
self.fetchApi(callbackUrlPath, callbackParam) self.fetchApi(callbackUrlPath, callbackParam)
} };
self.socket.onclose = function(ev) { self.socket.onclosed = function() {
console.log('socket:onclose', ev) console.log('socket:onclose')
// log('WebSocket Closed!!') };
}
self.socket.onmessage = function(ev) { self.socket.onmessage = function(evt) {
console.log('socket:onmessage', ev)
var msg = JSON.parse(ev.data) var msg = JSON.parse(ev.data)
console.log('[onmessage]:', msg) console.log('[onmessage]:', msg)
self.dealMessage(msg) self.dealMessage(msg)
...@@ -1926,7 +1931,37 @@ ...@@ -1926,7 +1931,37 @@
self.endTiming = +new Date() self.endTiming = +new Date()
self.socket.close() self.socket.close()
} }
};
self.socket.onerror = function(event) {
console.log("设备WebSocket:发生错误 ");
console.log(event);
}
} catch (error) {
console.log('onSocketConnect:', error)
} }
// self.socket = new ws(socketUrl)
// self.socket.onconnecting = function (ev) {
// console.log('socket:onconnecting', ev)
// }
// self.socket.onopen = function(ev) {
// console.log('socket:onopen', ev)
// self.startTiming = +new Date()
// self.fetchApi(callbackUrlPath, callbackParam)
// }
// self.socket.onclose = function(ev) {
// console.log('socket:onclose', ev)
// // log('WebSocket Closed!!')
// }
// self.socket.onmessage = function(ev) {
// console.log('socket:onmessage', ev)
// var msg = JSON.parse(ev.data)
// console.log('[onmessage]:', msg)
// self.dealMessage(msg)
// if (msg.stepCount === 1) {
// self.endTiming = +new Date()
// self.socket.close()
// }
// }
}, },
fetchApi(urlPath, parameter) { fetchApi(urlPath, parameter) {
const { const {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!