Commit c79c5e7a authored by martin hou's avatar martin hou

Merge branch 'v20250816' into device-mgr

parents 253e0ea4 f18d4cee
...@@ -142,6 +142,7 @@ declare class Jensen { ...@@ -142,6 +142,7 @@ declare class Jensen {
onconnect: () => void; onconnect: () => void;
// 事件:当连接异常时触发 // 事件:当连接异常时触发
onerror: (e: Error) => void; onerror: (e: Error) => void;
onwakeup: () => void;
// 主动断开连接(单连接时适用) // 主动断开连接(单连接时适用)
disconnect: () => void; disconnect: () => void;
// 事件:当连接断开时触发 // 事件:当连接断开时触发
......
...@@ -14,6 +14,9 @@ export function Home() { ...@@ -14,6 +14,9 @@ export function Home() {
jensen.connect(); jensen.connect();
jensen.onconnect = () => { jensen.onconnect = () => {
console.log('connect successfully'); console.log('connect successfully');
jensen.onwakeup = function() {
console.log('从休眠中恢复过来了?');
}
jensen.getDeviceInfo().then((info) => { jensen.getDeviceInfo().then((info) => {
console.log('getDeviceInfo', info); console.log('getDeviceInfo', info);
alert(info.sn + ' connected'); alert(info.sn + ' connected');
...@@ -25,6 +28,10 @@ export function Home() { ...@@ -25,6 +28,10 @@ export function Home() {
// console.log('onerror', e); // console.log('onerror', e);
// alert('此设备已经在其它已打开的HiNotes网页上建立连接'); // alert('此设备已经在其它已打开的HiNotes网页上建立连接');
// }; // };
setInterval(function()
{
Logger.info('hearbeat', 'tick', 'xxxx');
}, 5000);
}, []); }, []);
const getFilePart = () => { const getFilePart = () => {
......
...@@ -102,6 +102,10 @@ function Jensen(log, conn) { ...@@ -102,6 +102,10 @@ function Jensen(log, conn) {
this.onconnect = null; this.onconnect = null;
this.onreceive = null; this.onreceive = null;
this.onerror = null; this.onerror = null;
this.onwakeup = null;
this.sleepChecker = null;
this.lastTimerInvoked = new Date().getTime();
const RECV_BUFF_SIZE = 512000; const RECV_BUFF_SIZE = 512000;
...@@ -154,7 +158,9 @@ function Jensen(log, conn) { ...@@ -154,7 +158,9 @@ function Jensen(log, conn) {
self.model = determineModel(device.productId); self.model = determineModel(device.productId);
Logger.info('jensen', 'connect', 'device pid: ' + device.productId); Logger.info('jensen', 'connect', 'device pid: ' + device.productId);
} catch (e) { } catch (e) {
Logger.error('jensen', 'setup', String(e)); let err = String(e);
Logger.error('jensen', 'setup', err);
if (err.indexOf('Unable to claim interface.') > -1 && typeof(self?.onerror) == 'function') self?.onerror(e);
} }
if (!disableOnConnect) _check_conn_status(); if (!disableOnConnect) _check_conn_status();
current = null; current = null;
...@@ -166,6 +172,16 @@ function Jensen(log, conn) { ...@@ -166,6 +172,16 @@ function Jensen(log, conn) {
} catch (err) { } catch (err) {
Logger.error('jensen', 'setup', err); Logger.error('jensen', 'setup', err);
} }
if (self.sleepChecker) window.clearInterval(self.sleepChecker);
self.sleepChecker = setInterval(function() {
let now = new Date().getTime();
if (now - self.lastTimerInvoked > 6000)
{
if (typeof(self.onwakeup) == 'function') self.onwakeup();
}
self.lastTimerInvoked = now;
}, 5000);
console.log('休眠检测准备完毕');
}; };
this.initialize = async function() { this.initialize = async function() {
...@@ -408,7 +424,7 @@ function Jensen(log, conn) { ...@@ -408,7 +424,7 @@ function Jensen(log, conn) {
receive(r); receive(r);
}).catch((e) => { }).catch((e) => {
console.log('tryReceive error', e) console.log('tryReceive error', e)
if (!channelHealthy) self.onerror?.(e); // if (!channelHealthy) self.onerror?.(e);
}); });
}; };
...@@ -1041,14 +1057,14 @@ Jensen.prototype.getFile = async function (filename, length, ondata, onprogress) ...@@ -1041,14 +1057,14 @@ Jensen.prototype.getFile = async function (filename, length, ondata, onprogress)
this.onprogress = onprogress; this.onprogress = onprogress;
this.onreceive = function(recvBytes) this.onreceive = function(recvBytes)
{ {
let percent = Math.floor(recvBytes / length * 100); let percent = Math.floor(recvBytes / length * 1000);
let k = 't' + percent; let k = 't' + percent;
if (percent > 0 && percent < 100) if (percent > 0 && percent < 1000)
{ {
if (!(k in self._progress_report)) onprogress?.(recvBytes); if (!(k in self._progress_report)) onprogress?.(recvBytes);
self._progress_report[k] = true; self._progress_report[k] = true;
} }
if (percent >= 100 && !(k in self._progress_report)) if (percent >= 1000 && !(k in self._progress_report))
{ {
onprogress?.(length); onprogress?.(length);
self._progress_report[k] = true; self._progress_report[k] = true;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment