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
6698c484
Commit
6698c484
authored
Jun 18, 2019
by
姜雷
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改洗浴socket重连逻辑
parent
9648e5ba
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 @
6698c484
...
@@ -45,8 +45,6 @@ type IProps = PageStateProps & PageDispatchProps;
...
@@ -45,8 +45,6 @@ type IProps = PageStateProps & PageDispatchProps;
type
PageState
=
{
type
PageState
=
{
bluetoothState
:
boolean
;
bluetoothState
:
boolean
;
task
:
Taro
.
SocketTask
|
null
;
task
:
Taro
.
SocketTask
|
null
;
timer
:
number
|
undefined
;
reConnectting
:
boolean
;
deviceInfo
:
DeviceInfo
;
deviceInfo
:
DeviceInfo
;
sockedDone
:
boolean
;
sockedDone
:
boolean
;
deviceDone
:
boolean
;
deviceDone
:
boolean
;
...
@@ -59,6 +57,9 @@ interface Shower {
...
@@ -59,6 +57,9 @@ interface Shower {
state
:
PageState
;
state
:
PageState
;
}
}
let
timer
:
number
|
null
=
null
;
let
reConnectting
:
boolean
=
false
;
@
connect
(
@
connect
(
({
userinfo
,
Shower
})
=>
({
({
userinfo
,
Shower
})
=>
({
userinfo
,
userinfo
,
...
@@ -80,8 +81,6 @@ class Shower extends Component {
...
@@ -80,8 +81,6 @@ class Shower extends Component {
this
.
state
=
{
this
.
state
=
{
bluetoothState
:
false
,
bluetoothState
:
false
,
task
:
null
,
task
:
null
,
timer
:
undefined
,
reConnectting
:
false
,
sockedDone
:
false
,
sockedDone
:
false
,
deviceDone
:
false
,
deviceDone
:
false
,
showerState
:
false
,
showerState
:
false
,
...
@@ -114,7 +113,6 @@ class Shower extends Component {
...
@@ -114,7 +113,6 @@ class Shower extends Component {
connectSocket
(
SOCKET_URL
).
then
(
task
=>
{
connectSocket
(
SOCKET_URL
).
then
(
task
=>
{
task
.
onOpen
(()
=>
{
task
.
onOpen
(()
=>
{
console
.
log
(
'onOpen'
);
console
.
log
(
'onOpen'
);
const
{
reConnectting
}
=
this
.
state
;
if
(
reConnectting
)
{
if
(
reConnectting
)
{
this
.
reConnectDeviceSocket
(
true
);
this
.
reConnectDeviceSocket
(
true
);
}
}
...
@@ -149,28 +147,28 @@ class Shower extends Component {
...
@@ -149,28 +147,28 @@ class Shower extends Component {
}
}
});
});
task
.
onClose
(
e
=>
{
task
.
onClose
(
e
=>
{
console
.
log
(
'socked关闭'
,
e
);
console
.
log
(
'socked关闭'
,
e
,
reConnectting
,
timer
);
this
.
setState
({
this
.
setState
({
task
:
null
,
task
:
null
,
sockedDone
:
false
,
sockedDone
:
false
,
});
});
if
(
e
.
code
===
StopCode
)
{
if
(
e
.
code
===
StopCode
)
{
console
.
log
(
'正确结束socket连接'
);
console
.
log
(
'正确结束socket连接'
);
}
else
{
}
else
if
(
!
reConnectting
)
{
console
.
log
(
'开始重连socket'
);
this
.
reConnectDeviceSocket
(
false
);
this
.
reConnectDeviceSocket
(
false
);
}
else
{
console
.
log
(
'断开socket'
,
e
);
}
}
});
});
});
});
}
}
reConnectDeviceSocket
(
cancel
:
boolean
)
{
reConnectDeviceSocket
(
cancel
:
boolean
)
{
const
{
timer
,
reConnectting
}
=
this
.
state
;
if
(
cancel
)
{
if
(
cancel
)
{
clearTimeout
(
timer
);
timer
&&
clearTimeout
(
timer
);
this
.
setState
({
timer
=
null
;
timer
:
null
,
reConnectting
=
false
;
reConnectting
:
false
,
});
return
;
return
;
}
}
console
.
log
(
reConnectting
,
timer
);
console
.
log
(
reConnectting
,
timer
);
...
@@ -179,10 +177,8 @@ class Shower extends Component {
...
@@ -179,10 +177,8 @@ class Shower extends Component {
this
.
connectDeviceSocket
();
this
.
connectDeviceSocket
();
}
else
if
(
timer
)
{
}
else
if
(
timer
)
{
clearTimeout
(
timer
);
clearTimeout
(
timer
);
this
.
setState
({
reConnectting
=
false
;
timer
:
null
,
timer
=
null
;
reConnectting
:
false
,
});
console
.
log
(
'请保证网络正常'
);
console
.
log
(
'请保证网络正常'
);
Taro
.
showModal
({
Taro
.
showModal
({
title
:
'警告'
,
title
:
'警告'
,
...
@@ -190,15 +186,11 @@ class Shower extends Component {
...
@@ -190,15 +186,11 @@ class Shower extends Component {
});
});
}
else
{
}
else
{
let
newTimer
=
setTimeout
(()
=>
{
let
newTimer
=
setTimeout
(()
=>
{
this
.
setState
({
reConnectting
=
false
;
reConnectting
:
false
,
});
},
10000
);
},
10000
);
reConnectting
=
true
;
timer
=
newTimer
;
console
.
log
(
reConnectting
,
timer
);
console
.
log
(
reConnectting
,
timer
);
this
.
setState
({
timer
:
newTimer
,
reConnectting
:
true
,
});
this
.
connectDeviceSocket
();
this
.
connectDeviceSocket
();
}
}
}
}
...
@@ -224,8 +216,8 @@ class Shower extends Component {
...
@@ -224,8 +216,8 @@ class Shower extends Component {
}
}
closeDeviceSocket
()
{
closeDeviceSocket
()
{
const
{
task
,
timer
}
=
this
.
state
;
const
{
task
}
=
this
.
state
;
console
.
log
(
'in close'
,
task
);
console
.
log
(
'in close'
,
task
,
timer
);
if
(
task
)
{
if
(
task
)
{
task
.
close
({
task
.
close
({
code
:
StopCode
,
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