Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
bh_face_counter
Overview
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
黄天晨
bh_face_counter
Commits
8063656c
Commit
8063656c
authored
Jun 27, 2020
by
zeven
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修复微信刷脸支付导致socket掉线问题
parent
9d676d50
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
132 additions
and
9 deletions
+132
-9
android
android
+1
-1
App.js
src/App.js
+1
-0
admin.js
src/models/admin.js
+14
-4
CounterMixins.js
src/pages/CounterMixins.js
+1
-1
authInterval.js
src/utils/authInterval.js
+9
-3
socketio.js
src/utils/socketio.js
+106
-0
No files found.
android
@
ea22824f
Subproject commit
a68acacc0bd5b01ab34362b4ef09bbab72ded3d5
Subproject commit
ea22824f4000883940b000f1e1854893e7463f1e
src/App.js
View file @
8063656c
...
...
@@ -54,6 +54,7 @@ class App extends React.Component {
};
async
componentWillMount
()
{
// await AsyncStorage.clear(); // 清除数据
window
.
dispatch
=
this
.
props
.
dispatch
;
const
HOST
=
await
AsyncStorage
.
getItem
(
'HOST'
);
axios
.
defaults
.
baseURL
=
HOST
||
host
;
// 配置接口地址
...
...
src/models/admin.js
View file @
8063656c
import
AsyncStorage
from
'@react-native-community/async-storage'
;
import
*
as
api
from
'../services/admin'
;
import
axios
from
'axios'
;
import
*
as
api
from
'../services/admin'
;
import
SocketIO
from
'../utils/socketio'
;
export
default
{
namespace
:
'admin'
,
...
...
@@ -14,9 +15,18 @@ export default {
state
.
auth
=
auth
;
window
.
auth
=
auth
;
if
(
window
.
socket
)
{
window
.
socket
.
io
.
opts
.
query
=
{
token
:
auth
.
token
,
};
if
(
window
.
socket
.
io
)
{
window
.
socket
.
io
.
opts
.
query
=
{
token
:
auth
.
token
,
};
}
else
{
// 使用原生SocketIO
window
.
socket
.
disconnect
();
window
.
socket
=
new
SocketIO
(
`
${
axios
.
defaults
.
baseURL
}
/socket.io/?token=
${
window
.
auth
.
token
}
`
,
);
window
.
socket
.
connect
();
}
}
AsyncStorage
.
setItem
(
'auth'
,
JSON
.
stringify
(
auth
));
if
(
login
)
{
...
...
src/pages/CounterMixins.js
View file @
8063656c
...
...
@@ -138,7 +138,7 @@ const CounterMixins = ComposeComponent => {
window
.
socket
.
emit
(
'counterGoods'
,
sid
,
goods
,
JSON
.
stringify
(
goods
)
,
totalPrice
,
totalCount
,
payType
,
...
...
src/utils/authInterval.js
View file @
8063656c
import
io
from
'socket.io-client'
;
import
axios
from
'axios'
;
import
SocketIO
from
'../utils/socketio'
;
import
Restart
from
'./Restart'
;
window
.
restart
=
Restart
.
restartApp
;
...
...
@@ -7,9 +7,15 @@ window.restart = Restart.restartApp;
export
async
function
counterInterval
(
dispatch
,
expiresIn
,
reload
)
{
window
.
socket
=
window
.
socket
||
io
(
axios
.
defaults
.
baseURL
,
{
query
:
{
token
:
window
.
auth
.
token
}
,
new
SocketIO
(
axios
.
defaults
.
baseURL
,
{
query
:
`token=
${
window
.
auth
.
token
}
`
,
});
window
.
socket
.
connect
();
// window.socket =
// window.socket ||
// io(axios.defaults.baseURL, {
// query: {token: window.auth.token},
// });
window
.
authInterval
=
window
.
setInterval
(()
=>
{
dispatch
({
type
:
'admin/auth'
});
},
8
*
60
*
60
*
1000
);
// 每8小时更新一次
...
...
src/utils/socketio.js
0 → 100644
View file @
8063656c
import
{
DeviceEventEmitter
,
NativeModules
,
Platform
}
from
'react-native'
;
import
{
debounce
}
from
'throttle-debounce'
;
let
SocketIO
=
NativeModules
.
SocketIO
;
class
Socket
{
constructor
(
host
,
config
)
{
if
(
typeof
host
===
'undefined'
)
{
throw
'Hello there! Could you please give socket a host, please.'
;
}
if
(
typeof
config
===
'undefined'
)
{
config
=
{};
}
this
.
sockets
=
SocketIO
;
this
.
isConnected
=
false
;
this
.
handlers
=
{};
this
.
onAnyHandler
=
null
;
this
.
deviceEventSubscription
=
DeviceEventEmitter
.
addListener
(
'socketEvent'
,
this
.
_handleEvent
.
bind
(
this
),
);
// Set default handlers
this
.
defaultHandlers
=
{
connect
:
e
=>
{
if
(
e
&&
e
.
sid
)
{
this
.
id
=
e
.
sid
;
}
this
.
isConnected
=
true
;
},
disconnect
:
()
=>
{
this
.
isConnected
=
false
;
},
};
// Set initial configuration
this
.
sockets
.
initialize
(
host
,
config
);
}
debounceHandler
=
debounce
(
1000
,
true
,
event
=>
{
console
.
warn
(
event
.
name
);
const
res
=
event
.
hasOwnProperty
(
'items'
)
?
event
.
items
[
0
]
:
{};
this
.
handlers
[
event
.
name
](
res
);
});
_handleEvent
(
event
)
{
if
(
this
.
defaultHandlers
.
hasOwnProperty
(
event
.
name
))
{
this
.
defaultHandlers
[
event
.
name
](
event
);
}
if
(
this
.
handlers
.
hasOwnProperty
(
event
.
name
))
{
const
res
=
event
.
hasOwnProperty
(
'items'
)
?
event
.
items
[
0
]
:
{};
this
.
handlers
[
event
.
name
](
res
);
}
if
(
this
.
onAnyHandler
)
{
this
.
onAnyHandler
(
event
);
}
}
hasListeners
(
eventName
)
{
return
this
.
handlers
.
hasOwnProperty
(
eventName
);
}
getId
()
{
return
this
.
sockets
.
getId
();
}
connect
()
{
this
.
sockets
.
connect
();
}
on
(
event
,
handler
)
{
this
.
handlers
[
event
]
=
handler
;
if
(
Platform
.
OS
===
'android'
)
{
this
.
sockets
.
on
(
event
);
}
}
onAny
(
handler
)
{
this
.
onAnyHandler
=
handler
;
}
emit
(
event
,
...
data
)
{
this
.
sockets
.
emit
(
event
,
data
);
}
joinNamespace
(
namespace
)
{
this
.
sockets
.
joinNamespace
(
namespace
);
}
leaveNamespace
()
{
this
.
sockets
.
leaveNamespace
();
}
disconnect
()
{
this
.
sockets
.
disconnect
();
}
reconnect
()
{
this
.
sockets
.
reconnect
();
}
}
export
default
Socket
;
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