Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
J
jensen
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Skye Yu
jensen
Commits
00e8a809
Commit
00e8a809
authored
Jun 09, 2025
by
martin hou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 增加实例内handler注册机制
parent
68b04970
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
6 deletions
+12
-6
jensen.js
src/utils/jensen.js
+12
-6
No files found.
src/utils/jensen.js
View file @
00e8a809
...
@@ -80,11 +80,11 @@ function Jensen(log, conn) {
...
@@ -80,11 +80,11 @@ function Jensen(log, conn) {
let
sequence
=
0
;
let
sequence
=
0
;
let
current
=
null
;
let
current
=
null
;
let
commands
=
[];
let
commands
=
[];
let
handlers
=
[];
let
statusTimeout
=
null
;
let
statusTimeout
=
null
;
let
recv
=
false
;
let
recv
=
false
;
let
ready
=
false
;
let
ready
=
false
;
let
totalBytes
=
0
;
let
totalBytes
=
0
;
let
handlers
=
{};
let
self
=
this
;
let
self
=
this
;
this
.
data
=
{};
this
.
data
=
{};
...
@@ -419,7 +419,8 @@ function Jensen(log, conn) {
...
@@ -419,7 +419,8 @@ function Jensen(log, conn) {
'recv: '
+
cname
+
', seq: '
+
msg
.
sequence
+
', data bytes: '
+
msg
.
body
?.
byteLength
+
', data: '
+
heading
.
join
(
' '
)
'recv: '
+
cname
+
', seq: '
+
msg
.
sequence
+
', data bytes: '
+
msg
.
body
?.
byteLength
+
', data: '
+
heading
.
join
(
' '
)
);
);
try
{
try
{
let
handler
=
Jensen
.
handlers
[
msg
.
id
];
let
handler
=
handlers
[
msg
.
id
];
if
(
!
handler
)
handler
=
Jensen
.
handlers
[
msg
.
id
];
let
r
=
handler
(
msg
,
self
);
let
r
=
handler
(
msg
,
self
);
if
(
r
)
trigger
(
r
,
msg
.
id
);
if
(
r
)
trigger
(
r
,
msg
.
id
);
}
catch
(
e
)
{
}
catch
(
e
)
{
...
@@ -434,7 +435,8 @@ function Jensen(log, conn) {
...
@@ -434,7 +435,8 @@ function Jensen(log, conn) {
// 5是msgid
// 5是msgid
let
msgid
=
parseInt
(
current
.
replace
(
/^cmd-
(\d
+
)
-
(\d
+
)
$/gi
,
'$1'
));
let
msgid
=
parseInt
(
current
.
replace
(
/^cmd-
(\d
+
)
-
(\d
+
)
$/gi
,
'$1'
));
try
{
try
{
let
handler
=
Jensen
.
handlers
[
msgid
];
let
handler
=
handlers
[
msgid
];
if
(
!
handler
)
handler
=
Jensen
.
handlers
[
msgid
];
handler
(
null
,
self
);
handler
(
null
,
self
);
}
catch
(
e
)
{
}
catch
(
e
)
{
trigger
(
e
);
trigger
(
e
);
...
@@ -523,6 +525,10 @@ function Jensen(log, conn) {
...
@@ -523,6 +525,10 @@ function Jensen(log, conn) {
}
}
return
str
;
return
str
;
};
};
this
.
registerHandler
=
function
(
cmdid
,
handler
)
{
handlers
[
cmdid
]
=
handler
;
};
}
}
function
Command
(
id
)
{
function
Command
(
id
)
{
...
@@ -631,7 +637,7 @@ Jensen.prototype.getBluetoothStatus = async function (seconds) {
...
@@ -631,7 +637,7 @@ Jensen.prototype.getBluetoothStatus = async function (seconds) {
};
};
Jensen
.
prototype
.
listFiles
=
async
function
()
{
Jensen
.
prototype
.
listFiles
=
async
function
()
{
let
tag
=
'filelist
'
;
let
tag
=
'filelist
-'
+
this
.
serialNumber
;
if
(
this
[
tag
]
!=
null
)
return
null
;
if
(
this
[
tag
]
!=
null
)
return
null
;
let
fc
=
null
;
let
fc
=
null
;
...
@@ -645,7 +651,7 @@ Jensen.prototype.listFiles = async function () {
...
@@ -645,7 +651,7 @@ Jensen.prototype.listFiles = async function () {
let
self
=
this
;
let
self
=
this
;
// let tag = 'data_' + new Date().getTime();
// let tag = 'data_' + new Date().getTime();
this
[
tag
]
=
[];
this
[
tag
]
=
[];
Jensen
.
registerHandler
(
QUERY_FILE_LIST
,
(
msg
,
jensen
)
=>
{
this
.
registerHandler
(
QUERY_FILE_LIST
,
(
msg
,
jensen
)
=>
{
if
(
msg
.
body
.
length
==
0
)
{
if
(
msg
.
body
.
length
==
0
)
{
jensen
[
tag
]
=
null
;
jensen
[
tag
]
=
null
;
return
[];
return
[];
...
@@ -944,7 +950,7 @@ Jensen.prototype.getFile = async function (filename, length, ondata, onprogress)
...
@@ -944,7 +950,7 @@ Jensen.prototype.getFile = async function (filename, length, ondata, onprogress)
onprogress
?.(
recvBytes
);
onprogress
?.(
recvBytes
);
}
}
}
}
Jensen
.
registerHandler
(
TRANSFER_FILE
,
handler
);
this
.
registerHandler
(
TRANSFER_FILE
,
handler
);
this
.
send
(
new
Command
(
TRANSFER_FILE
).
body
(
fname
));
this
.
send
(
new
Command
(
TRANSFER_FILE
).
body
(
fname
));
};
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment