Skip to content

Commit 907a032

Browse files
committed
add sending capabilities
1 parent 0a7a04c commit 907a032

1 file changed

Lines changed: 19 additions & 3 deletions

File tree

  • websockets/src/main/java/com/craftsman/websockets

websockets/src/main/java/com/craftsman/websockets/WsImpl.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class WsImpl implements Ws {
1818

1919
final String TAG = "Web Socket Impl";
2020

21-
final AutobahnConnection autobahnConnection = new AutobahnConnection();
21+
AutobahnConnection autobahnConnection = new AutobahnConnection();
2222
final List<Payload> subscriptions = new ArrayList<>();
2323
String serverUrl;
2424

@@ -103,13 +103,29 @@ public void onEvent(String s, Object o) {
103103
}
104104

105105
@Override
106-
public void send(String channelPath, String text) {
106+
public void send( String text) {
107+
if(autobahnConnection.isConnected())
108+
autobahnConnection.sendTextMessage(text);
109+
}
107110

111+
@Override
112+
public void send( byte[] binary) {
113+
if(autobahnConnection.isConnected())
114+
autobahnConnection.sendBinaryMessage(binary);
108115
}
109116

110117
@Override
111-
public void send(String channelPath, byte[] binary) {
118+
public void send(String channelPath, Object o) {
119+
if(autobahnConnection.isConnected())
120+
autobahnConnection.publish(channelPath,o);
121+
}
112122

123+
@Override
124+
public void end() {
125+
if(autobahnConnection != null && autobahnConnection.isConnected()) {
126+
autobahnConnection.unsubscribe();
127+
autobahnConnection = null;
128+
}
113129
}
114130

115131
final private class Payload<T>{

0 commit comments

Comments
 (0)