Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
huangzhicong
/
SmartCanteen
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
88210ec0
authored
Aug 03, 2019
by
patpat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化MainWebSocket
parent
fec40197
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
36 deletions
+9
-36
app/src/main/java/com/bgycc/smartcanteen/server/websocket/MainWebSocket.java
+9
-36
No files found.
app/src/main/java/com/bgycc/smartcanteen/server/websocket/MainWebSocket.java
View file @
88210ec0
...
...
@@ -5,6 +5,7 @@ import android.util.SparseArray;
import
com.bgycc.smartcanteen.AppConfig
;
import
com.bgycc.smartcanteen.action.ActionEnum
;
import
com.bgycc.smartcanteen.action.PayOfflineAction
;
import
com.bgycc.smartcanteen.helper.TimerHelper
;
import
com.bgycc.smartcanteen.server.websocket.event.ConnectStateEvent
;
import
com.bgycc.smartcanteen.server.websocket.event.RecvMessageEvent
;
import
com.bgycc.smartcanteen.server.websocket.event.SendMessageEvent
;
...
...
@@ -22,9 +23,6 @@ import java.net.URI;
import
java.net.URISyntaxException
;
import
java.text.SimpleDateFormat
;
import
java.util.*
;
import
java.util.concurrent.Executors
;
import
java.util.concurrent.ScheduledExecutorService
;
import
java.util.concurrent.TimeUnit
;
public
class
MainWebSocket
extends
WebSocketClient
{
...
...
@@ -48,7 +46,6 @@ public class MainWebSocket extends WebSocketClient {
private
static
MainWebSocket
sInstance
;
private
static
String
sDeviceSN
;
private
static
ScheduledExecutorService
sKeepAliveExec
;
public
static
void
initialize
()
{
if
(
sInstance
==
null
)
{
...
...
@@ -59,27 +56,18 @@ public class MainWebSocket extends WebSocketClient {
EventBus
.
getDefault
().
post
(
new
ConnectStateEvent
(
ConnectStateEvent
.
CONNECTING
));
sInstance
=
new
MainWebSocket
(
new
URI
(
String
.
format
(
AppConfig
.
getMainWebSocketServerUrl
(),
sDeviceSN
)));
sInstance
.
connect
();
}
catch
(
URISyntaxException
e
)
{
e
.
printStackTrace
();
}
}
if
(
sKeepAliveExec
==
null
)
{
sKeepAliveExec
=
Executors
.
newSingleThreadScheduledExecutor
();
sKeepAliveExec
.
scheduleAtFixedRate
(
new
Runnable
()
{
@Override
public
void
run
()
{
try
{
if
(
sInstance
==
null
)
return
;
TimerHelper
.
INSTANCE
.
loop
(
new
Runnable
()
{
@Override
public
void
run
()
{
if
(
sInstance
.
isClosed
())
{
EventBus
.
getDefault
().
post
(
new
ConnectStateEvent
(
ConnectStateEvent
.
RECONNECTING
));
sInstance
.
reconnect
();
EventBus
.
getDefault
().
post
(
new
ConnectStateEvent
(
ConnectStateEvent
.
RECONNECTING
));
}
}
catch
(
Exception
e
)
{
Log
.
e
(
TAG
,
"sKeepAliveExec error"
);
e
.
printStackTrace
();
}
}
},
0
,
1000
,
TimeUnit
.
MILLISECONDS
);
},
1000
);
}
catch
(
URISyntaxException
e
)
{
e
.
printStackTrace
();
}
}
}
...
...
@@ -91,21 +79,6 @@ public class MainWebSocket extends WebSocketClient {
return
sInstance
.
isOpen
();
}
public
static
void
payOnline
(
String
payCode
,
String
payCodeType
,
Response
callback
)
{
if
(!
isInited
())
return
;
try
{
JSONObject
json
=
new
JSONObject
();
json
.
put
(
FieldEnum
.
equipmentNo
.
name
(),
sDeviceSN
);
json
.
put
(
FieldEnum
.
payCode
.
name
(),
payCode
);
json
.
put
(
FieldEnum
.
terminalType
.
name
(),
payCodeType
);
json
.
put
(
FieldEnum
.
time
.
name
(),
new
SimpleDateFormat
(
"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"
,
Locale
.
getDefault
()).
format
(
new
Date
()));
sInstance
.
send
(
ActionEnum
.
PAY_ONLINE
.
name
(),
json
,
callback
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
public
static
void
action
(
String
action
,
JSONObject
params
,
Response
callback
)
{
if
(!
isInited
())
return
;
...
...
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