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
9a9a22da
Commit
9a9a22da
authored
Jun 28, 2020
by
zeven
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修复刷新token创建socket实例监听事件问题
parent
2c5595bd
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
15 deletions
+22
-15
android
android
+1
-1
admin.js
src/models/admin.js
+1
-3
socketio.js
src/utils/socketio.js
+20
-11
No files found.
android
@
a3cbda86
Subproject commit
ea22824f4000883940b000f1e1854893e7463f1
e
Subproject commit
a3cbda867ae325953176a19a5ed9da46db9d686
e
src/models/admin.js
View file @
9a9a22da
...
@@ -21,11 +21,9 @@ export default {
...
@@ -21,11 +21,9 @@ export default {
};
};
}
else
{
}
else
{
// 使用原生SocketIO
// 使用原生SocketIO
window
.
socket
.
disconnect
();
window
.
socket
=
window
.
socket
.
initialize
({
window
.
socket
=
new
SocketIO
(
axios
.
defaults
.
baseURL
,
{
query
:
`token=
${
window
.
auth
.
token
}
`
,
query
:
`token=
${
window
.
auth
.
token
}
`
,
});
});
window
.
socket
.
connect
();
}
}
}
}
AsyncStorage
.
setItem
(
'auth'
,
JSON
.
stringify
(
auth
));
AsyncStorage
.
setItem
(
'auth'
,
JSON
.
stringify
(
auth
));
...
...
src/utils/socketio.js
View file @
9a9a22da
import
{
DeviceEventEmitter
,
NativeModules
,
Platform
}
from
'react-native'
;
import
{
DeviceEventEmitter
,
NativeModules
,
Platform
}
from
'react-native'
;
import
{
debounce
}
from
'throttle-debounce'
;
let
SocketIO
=
NativeModules
.
SocketIO
;
let
SocketIO
=
NativeModules
.
SocketIO
;
...
@@ -17,10 +16,7 @@ class Socket {
...
@@ -17,10 +16,7 @@ class Socket {
this
.
handlers
=
{};
this
.
handlers
=
{};
this
.
onAnyHandler
=
null
;
this
.
onAnyHandler
=
null
;
this
.
deviceEventSubscription
=
DeviceEventEmitter
.
addListener
(
DeviceEventEmitter
.
addListener
(
'socketEvent'
,
this
.
_handleEvent
.
bind
(
this
));
'socketEvent'
,
this
.
_handleEvent
.
bind
(
this
),
);
// Set default handlers
// Set default handlers
this
.
defaultHandlers
=
{
this
.
defaultHandlers
=
{
...
@@ -37,15 +33,11 @@ class Socket {
...
@@ -37,15 +33,11 @@ class Socket {
};
};
// Set initial configuration
// Set initial configuration
this
.
host
=
host
;
this
.
config
=
config
;
this
.
sockets
.
initialize
(
host
,
config
);
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
)
{
_handleEvent
(
event
)
{
if
(
this
.
defaultHandlers
.
hasOwnProperty
(
event
.
name
))
{
if
(
this
.
defaultHandlers
.
hasOwnProperty
(
event
.
name
))
{
this
.
defaultHandlers
[
event
.
name
](
event
);
this
.
defaultHandlers
[
event
.
name
](
event
);
...
@@ -63,10 +55,27 @@ class Socket {
...
@@ -63,10 +55,27 @@ class Socket {
return
this
.
handlers
.
hasOwnProperty
(
eventName
);
return
this
.
handlers
.
hasOwnProperty
(
eventName
);
}
}
initialize
(
config
)
{
config
=
{...
this
.
config
,
...
config
};
this
.
disconnect
();
DeviceEventEmitter
.
removeAllListeners
(
'socketEvent'
);
const
socket
=
new
Socket
(
this
.
host
,
config
);
Object
.
keys
(
this
.
handlers
).
map
(
event
=>
{
const
handler
=
this
.
handlers
[
event
];
socket
.
on
(
event
,
handler
);
});
socket
.
connect
();
return
socket
;
}
getId
()
{
getId
()
{
return
this
.
sockets
.
getId
();
return
this
.
sockets
.
getId
();
}
}
updateQuery
(
query
)
{
return
this
.
sockets
.
updateQuery
(
query
);
}
connect
()
{
connect
()
{
this
.
sockets
.
connect
();
this
.
sockets
.
connect
();
}
}
...
...
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