Commit cc008975 by 周志凯

nature socket

1 parent 5cbfc59c
Showing 1 changed file with 57 additions and 22 deletions
......@@ -1498,7 +1498,7 @@
stepList: []
};
obj.stepType = wsUrl;
obj.mark = params.mark || params.featureType;
obj.mark = params.mark;
if (!webSockUrl) {
webSock = window.location.host;
}
......@@ -1857,7 +1857,10 @@
// 参数 mallIds,startDate,endDate,scheduleType
// 店员重新比对 /mall/staff
// 参数 mallIds,startDate,endDate,scheduleType
this.socket && this.socket.close()
if (this.socket) {
this.socket.close()
this.socket = null
}
this.results = []
this.startTiming = 0
this.endTiming = 0
......@@ -1904,29 +1907,61 @@
wsUrl = webSockUrl || window.location.host,
socketUrl = "ws://" + wsUrl + "/recal/schedule/" + scheduleType
console.log('[socketUrl]:', socketUrl)
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!!')
if ("WebSocket" in window) {
self.socket = new WebSocket(socketUrl);
} else if ("MozWebSocket" in window) {
self.socket = new MozWebSocket(socketUrl);
} else {
self.socket = new SockJS(socketUrl);
}
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()
try {
self.socket.onopen = function(ev) {
self.startTiming = +new Date()
self.fetchApi(callbackUrlPath, callbackParam)
};
self.socket.onclosed = function() {
console.log('socket:onclose')
};
self.socket.onmessage = function(evt) {
var msg = JSON.parse(ev.data)
console.log('[onmessage]:', msg)
self.dealMessage(msg)
if (msg.stepCount === 1) {
self.endTiming = +new Date()
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) {
const {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!