Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
AloqaIM-Android
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
Administrator
AloqaIM-Android
Commits
1994e656
Commit
1994e656
authored
Jan 23, 2017
by
Yusuke Iwaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
omit ping request for multiple request in 20 seconds
parent
cc94abe8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
0 deletions
+27
-0
RocketChatWebSocketThread.java
...hat/rocket/android/service/RocketChatWebSocketThread.java
+27
-0
No files found.
app/src/main/java/chat/rocket/android/service/RocketChatWebSocketThread.java
View file @
1994e656
...
@@ -64,6 +64,27 @@ public class RocketChatWebSocketThread extends HandlerThread {
...
@@ -64,6 +64,27 @@ public class RocketChatWebSocketThread extends HandlerThread {
private
DDPClientWrapper
ddpClient
;
private
DDPClientWrapper
ddpClient
;
private
boolean
listenersRegistered
;
private
boolean
listenersRegistered
;
private
static
class
KeepAliveTimer
{
private
long
lastTime
;
private
final
long
thresholdMs
;
public
KeepAliveTimer
(
long
thresholdMs
)
{
this
.
thresholdMs
=
thresholdMs
;
lastTime
=
System
.
currentTimeMillis
();
}
public
boolean
shouldCheckPrecisely
()
{
return
lastTime
+
thresholdMs
<
System
.
currentTimeMillis
();
}
public
void
update
()
{
lastTime
=
System
.
currentTimeMillis
();
}
}
private
final
KeepAliveTimer
keepAliveTimer
=
new
KeepAliveTimer
(
20000
);
private
RocketChatWebSocketThread
(
Context
appContext
,
String
hostname
)
{
private
RocketChatWebSocketThread
(
Context
appContext
,
String
hostname
)
{
super
(
"RC_thread_"
+
hostname
);
super
(
"RC_thread_"
+
hostname
);
this
.
appContext
=
appContext
;
this
.
appContext
=
appContext
;
...
@@ -158,6 +179,11 @@ public class RocketChatWebSocketThread extends HandlerThread {
...
@@ -158,6 +179,11 @@ public class RocketChatWebSocketThread extends HandlerThread {
return
Single
.
just
(
false
);
return
Single
.
just
(
false
);
}
}
if
(!
keepAliveTimer
.
shouldCheckPrecisely
())
{
return
Single
.
just
(
true
);
}
keepAliveTimer
.
update
();
return
Single
.
fromEmitter
(
emitter
->
{
return
Single
.
fromEmitter
(
emitter
->
{
new
Thread
()
{
new
Thread
()
{
@Override
@Override
...
@@ -168,6 +194,7 @@ public class RocketChatWebSocketThread extends HandlerThread {
...
@@ -168,6 +194,7 @@ public class RocketChatWebSocketThread extends HandlerThread {
emitter
.
onSuccess
(
false
);
emitter
.
onSuccess
(
false
);
ddpClient
.
close
();
ddpClient
.
close
();
}
else
{
}
else
{
keepAliveTimer
.
update
();
emitter
.
onSuccess
(
true
);
emitter
.
onSuccess
(
true
);
}
}
return
null
;
return
null
;
...
...
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