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
7f01c5ed
Commit
7f01c5ed
authored
Feb 07, 2017
by
Tiago Cunha
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Using a backpressure enable observable
parent
abcedb84
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
28 deletions
+32
-28
RxWebSocket.java
...src/main/java/chat/rocket/android_ddp/rx/RxWebSocket.java
+32
-28
No files found.
android-ddp/src/main/java/chat/rocket/android_ddp/rx/RxWebSocket.java
View file @
7f01c5ed
...
...
@@ -7,9 +7,10 @@ import okhttp3.Request;
import
okhttp3.Response
;
import
okhttp3.WebSocket
;
import
okhttp3.WebSocketListener
;
import
rx.Emitter
;
import
rx.Observable
;
import
rx.Subscriber
;
import
rx.exceptions.OnErrorNotImplementedException
;
import
rx.functions.Action1
;
import
rx.observables.ConnectableObservable
;
public
class
RxWebSocket
{
...
...
@@ -23,38 +24,41 @@ public class RxWebSocket {
public
ConnectableObservable
<
RxWebSocketCallback
.
Base
>
connect
(
String
url
)
{
final
Request
request
=
new
Request
.
Builder
().
url
(
url
).
build
();
return
Observable
.
create
(
new
Observable
.
OnSubscribe
<
RxWebSocketCallback
.
Base
>()
{
@Override
public
void
call
(
Subscriber
<?
super
RxWebSocketCallback
.
Base
>
subscriber
)
{
httpClient
.
newWebSocket
(
request
,
new
WebSocketListener
()
{
return
Observable
.
fromEmitter
(
new
Action1
<
Emitter
<
RxWebSocketCallback
.
Base
>>()
{
@Override
public
void
onOpen
(
WebSocket
webSocket
,
Response
response
)
{
RxWebSocket
.
this
.
webSocket
=
webSocket
;
subscriber
.
onNext
(
new
RxWebSocketCallback
.
Open
(
RxWebSocket
.
this
.
webSocket
,
response
));
}
public
void
call
(
Emitter
<
RxWebSocketCallback
.
Base
>
emitter
)
{
httpClient
.
newWebSocket
(
request
,
new
WebSocketListener
()
{
@Override
public
void
onOpen
(
WebSocket
webSocket
,
Response
response
)
{
RxWebSocket
.
this
.
webSocket
=
webSocket
;
emitter
.
onNext
(
new
RxWebSocketCallback
.
Open
(
RxWebSocket
.
this
.
webSocket
,
response
));
}
@Override
public
void
onFailure
(
WebSocket
webSocket
,
Throwable
err
,
Response
response
)
{
try
{
subscrib
er
.
onError
(
new
RxWebSocketCallback
.
Failure
(
webSocket
,
err
,
response
));
}
catch
(
OnErrorNotImplementedException
ex
)
{
RCLog
.
w
(
ex
,
"OnErrorNotImplementedException ignored"
);
}
}
@Override
public
void
onFailure
(
WebSocket
webSocket
,
Throwable
err
,
Response
response
)
{
try
{
emitt
er
.
onError
(
new
RxWebSocketCallback
.
Failure
(
webSocket
,
err
,
response
));
}
catch
(
OnErrorNotImplementedException
ex
)
{
RCLog
.
w
(
ex
,
"OnErrorNotImplementedException ignored"
);
}
}
@Override
public
void
onMessage
(
WebSocket
webSocket
,
String
text
)
{
subscrib
er
.
onNext
(
new
RxWebSocketCallback
.
Message
(
webSocket
,
text
));
}
@Override
public
void
onMessage
(
WebSocket
webSocket
,
String
text
)
{
emitt
er
.
onNext
(
new
RxWebSocketCallback
.
Message
(
webSocket
,
text
));
}
@Override
public
void
onClosed
(
WebSocket
webSocket
,
int
code
,
String
reason
)
{
subscriber
.
onNext
(
new
RxWebSocketCallback
.
Close
(
webSocket
,
code
,
reason
));
subscriber
.
onCompleted
();
@Override
public
void
onClosed
(
WebSocket
webSocket
,
int
code
,
String
reason
)
{
emitter
.
onNext
(
new
RxWebSocketCallback
.
Close
(
webSocket
,
code
,
reason
));
emitter
.
onCompleted
();
}
});
}
}
);
}
}
).
publish
();
}
,
Emitter
.
BackpressureMode
.
BUFFER
).
publish
();
}
public
boolean
sendText
(
String
message
)
throws
IOException
{
...
...
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