|
@@ -1,13 +1,14 @@
|
|
|
let DebugMode = false, Wines = [], ParamMap = {
|
|
|
- ListTimeOut: 60,
|
|
|
- DetailTimeOut: 120,
|
|
|
- PayTimeOut: 180,
|
|
|
- WaitCountDown: 5,
|
|
|
- WarnLine: 3000,
|
|
|
- DangerLine: 500,
|
|
|
- VolumeAdv: 5,
|
|
|
- VolumeNormal: 15
|
|
|
-}, EventBus = {}, socket = null, socketUrl, SockEventMap = {"pon": undefined};
|
|
|
+ ListTimeOut: 60,
|
|
|
+ DetailTimeOut: 120,
|
|
|
+ PayTimeOut: 180,
|
|
|
+ WaitCountDown: 5,
|
|
|
+ WarnLine: 3000,
|
|
|
+ DangerLine: 500,
|
|
|
+ VolumeAdv: 5,
|
|
|
+ VolumeNormal: 15
|
|
|
+ }, EventBus = {}, SockEventMap = {"pon": c => EventBus["debug"](`time: ${new Date().toLocaleString()}, pin/pon: ${c}`)},
|
|
|
+ socket = null, socketTimer = null, socketUrl = "";
|
|
|
|
|
|
// wss://wine.ifarmcloud.com/api/seller/socket, ws://192.168.1.6:3080/seller/socket
|
|
|
const ServerPrefix = "wss://wine.ifarmcloud.com/api/seller/socket";
|
|
@@ -22,15 +23,19 @@ const Android = (func, ...args) => {
|
|
|
window._weight = 0;
|
|
|
window._timer = null;
|
|
|
window.android = {
|
|
|
+ pin: window.pon,
|
|
|
onWebMounted: () => window.startApp("EMULATOR32X1X14X0", "v2023.11.01"),
|
|
|
openFrontGate: () => window.frontGateResult(true),
|
|
|
openBackGate: () => window.backGateResult(true),
|
|
|
lightOn: index => console.log(`light on: ${index}`),
|
|
|
lightOff: index => console.log(`light off: ${index}`),
|
|
|
- isCupProperlyPlaced: () => {
|
|
|
- window._weight = 2; // 0.2g
|
|
|
+ isCupProperlyPlaced: index => {
|
|
|
+ console.log(`is cup properly placed at ${index}`)
|
|
|
+ window._weight = 34; // 0.2g
|
|
|
setTimeout(() => window.cupProperlyPlaced(window._weight), 1500);
|
|
|
},
|
|
|
+ openGas: () => console.log("open gas"),
|
|
|
+ closeGas: () => console.log("close gas"),
|
|
|
openValve: (index, pulse) => {
|
|
|
console.log(`valve[${index}] opened for: ${pulse}`);
|
|
|
let outed = 0;
|
|
@@ -49,25 +54,35 @@ const Android = (func, ...args) => {
|
|
|
if (window._timer !== null) clearInterval(window._timer);
|
|
|
window._timer = null;
|
|
|
},
|
|
|
- readSteadyWeight: () => window.steadyWeight(window._weight),
|
|
|
+ readSteadyWeight: index => {
|
|
|
+ console.log(`steady weight of ${index}`);
|
|
|
+ window.steadyWeight(window._weight);
|
|
|
+ },
|
|
|
setVolume: volume => console.log(`volume will be set to: ${volume}`),
|
|
|
hide: () => console.log("gesture will be hide"),
|
|
|
show: () => console.log("gesture will be show")
|
|
|
};
|
|
|
},
|
|
|
- SendWss = data => socket.send(JSON.stringify(data)),
|
|
|
+ SendWss = (data, ttl) => {
|
|
|
+ if (socket !== null) return socket.send(JSON.stringify(data));
|
|
|
+ if (ttl === undefined) ttl = 3;
|
|
|
+ if (ttl > 0) setTimeout(() => SendWss(data, ttl - 1), 1000);
|
|
|
+ EventBus["debug"](`event: ${data.event}, ttl: ${ttl}`);
|
|
|
+ },
|
|
|
ConnectSocket = device => {
|
|
|
if (device !== undefined) socketUrl = `${ServerPrefix}/${device}`;
|
|
|
socket = new WebSocket(socketUrl);
|
|
|
- socket.onclose = e => {
|
|
|
- EventBus["debug"](`websocket断开:code[${e.code}], reason[${e.reason}], clean[${e.wasClean}]`);
|
|
|
+ socket.onclose = () => {
|
|
|
+ socket = null;
|
|
|
+ ConnectSocket();
|
|
|
}
|
|
|
socket.onopen = () => {
|
|
|
- setInterval(() => SendWss({event: "pin", data: null}), 50 * 1000);
|
|
|
+ let count = 0;
|
|
|
+ clearInterval(socketTimer);
|
|
|
+ socketTimer = setInterval(() => SendWss({event: "pin", data: count++}), 50 * 1000);
|
|
|
}
|
|
|
socket.onmessage = event => {
|
|
|
let body = JSON.parse(event.data);
|
|
|
- EventBus["debug"](`event: ${body.event}`);
|
|
|
SockEventMap[body.event] && SockEventMap[body.event](body.data);
|
|
|
}
|
|
|
},
|