Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wx-school-app
Project
Overview
Details
Activity
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
姜雷
wx-school-app
Commits
7ab5a9f5
Commit
7ab5a9f5
authored
Jun 18, 2019
by
姜雷
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'develop' into test
parents
d741ffe2
6698c484
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
26 deletions
+18
-26
Shower.tsx
src/pages/Shower/Shower.tsx
+18
-26
No files found.
src/pages/Shower/Shower.tsx
View file @
7ab5a9f5
...
...
@@ -45,8 +45,6 @@ type IProps = PageStateProps & PageDispatchProps;
type
PageState
=
{
bluetoothState
:
boolean
;
task
:
Taro
.
SocketTask
|
null
;
timer
:
number
|
undefined
;
reConnectting
:
boolean
;
deviceInfo
:
DeviceInfo
;
sockedDone
:
boolean
;
deviceDone
:
boolean
;
...
...
@@ -59,6 +57,9 @@ interface Shower {
state
:
PageState
;
}
let
timer
:
number
|
null
=
null
;
let
reConnectting
:
boolean
=
false
;
@
connect
(
({
userinfo
,
Shower
})
=>
({
userinfo
,
...
...
@@ -80,8 +81,6 @@ class Shower extends Component {
this
.
state
=
{
bluetoothState
:
false
,
task
:
null
,
timer
:
undefined
,
reConnectting
:
false
,
sockedDone
:
false
,
deviceDone
:
false
,
showerState
:
false
,
...
...
@@ -114,7 +113,6 @@ class Shower extends Component {
connectSocket
(
SOCKET_URL
).
then
(
task
=>
{
task
.
onOpen
(()
=>
{
console
.
log
(
'onOpen'
);
const
{
reConnectting
}
=
this
.
state
;
if
(
reConnectting
)
{
this
.
reConnectDeviceSocket
(
true
);
}
...
...
@@ -149,28 +147,28 @@ class Shower extends Component {
}
});
task
.
onClose
(
e
=>
{
console
.
log
(
'socked关闭'
,
e
);
console
.
log
(
'socked关闭'
,
e
,
reConnectting
,
timer
);
this
.
setState
({
task
:
null
,
sockedDone
:
false
,
});
if
(
e
.
code
===
StopCode
)
{
console
.
log
(
'正确结束socket连接'
);
}
else
{
}
else
if
(
!
reConnectting
)
{
console
.
log
(
'开始重连socket'
);
this
.
reConnectDeviceSocket
(
false
);
}
else
{
console
.
log
(
'断开socket'
,
e
);
}
});
});
}
reConnectDeviceSocket
(
cancel
:
boolean
)
{
const
{
timer
,
reConnectting
}
=
this
.
state
;
if
(
cancel
)
{
clearTimeout
(
timer
);
this
.
setState
({
timer
:
null
,
reConnectting
:
false
,
});
timer
&&
clearTimeout
(
timer
);
timer
=
null
;
reConnectting
=
false
;
return
;
}
console
.
log
(
reConnectting
,
timer
);
...
...
@@ -179,10 +177,8 @@ class Shower extends Component {
this
.
connectDeviceSocket
();
}
else
if
(
timer
)
{
clearTimeout
(
timer
);
this
.
setState
({
timer
:
null
,
reConnectting
:
false
,
});
reConnectting
=
false
;
timer
=
null
;
console
.
log
(
'请保证网络正常'
);
Taro
.
showModal
({
title
:
'警告'
,
...
...
@@ -190,15 +186,11 @@ class Shower extends Component {
});
}
else
{
let
newTimer
=
setTimeout
(()
=>
{
this
.
setState
({
reConnectting
:
false
,
});
reConnectting
=
false
;
},
10000
);
reConnectting
=
true
;
timer
=
newTimer
;
console
.
log
(
reConnectting
,
timer
);
this
.
setState
({
timer
:
newTimer
,
reConnectting
:
true
,
});
this
.
connectDeviceSocket
();
}
}
...
...
@@ -224,8 +216,8 @@ class Shower extends Component {
}
closeDeviceSocket
()
{
const
{
task
,
timer
}
=
this
.
state
;
console
.
log
(
'in close'
,
task
);
const
{
task
}
=
this
.
state
;
console
.
log
(
'in close'
,
task
,
timer
);
if
(
task
)
{
task
.
close
({
code
:
StopCode
,
...
...
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