Skip to content

Commit be2ab21

Browse files
author
Alexander Maxakov
committed
socket io transport stores session id
1 parent 5530bb8 commit be2ab21

File tree

4 files changed

+25
-9
lines changed

4 files changed

+25
-9
lines changed

AndroidAsync/src/com/koushikdutta/async/http/socketio/SocketIOConnection.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ void reconnect(final DependentCancellable child) {
109109
@Override
110110
protected void transform(String result) throws Exception {
111111
String[] parts = result.split(":");
112-
String session = parts[0];
112+
final String sessionId = parts[0];
113113
if (!"".equals(parts[1]))
114114
heartbeat = Integer.parseInt(parts[1]) / 2 * 1000;
115115
else
@@ -122,7 +122,7 @@ protected void transform(String result) throws Exception {
122122

123123
if (set.contains("websocket")) {
124124
final String sessionUrl = Uri.parse(request.getUri().toString()).buildUpon()
125-
.appendPath("websocket").appendPath(session)
125+
.appendPath("websocket").appendPath(sessionId)
126126
.build().toString();
127127

128128
httpClient.websocket(sessionUrl, null, null)
@@ -133,14 +133,14 @@ public void onCompleted(Exception e, WebSocket result) {
133133
transport.setComplete(e);
134134
return;
135135
}
136-
transport.setComplete(new WebSocketTransport(result));
136+
transport.setComplete(new WebSocketTransport(result, sessionId));
137137
}
138138
});
139139
} else if (set.contains("xhr-polling")) {
140140
final String sessionUrl = Uri.parse(request.getUri().toString()).buildUpon()
141-
.appendPath("xhr-polling").appendPath(session)
141+
.appendPath("xhr-polling").appendPath(sessionId)
142142
.build().toString();
143-
XHRPollingTransport xhrPolling = new XHRPollingTransport(httpClient, sessionUrl);
143+
XHRPollingTransport xhrPolling = new XHRPollingTransport(httpClient, sessionUrl, sessionId);
144144
transport.setComplete(xhrPolling);
145145
} else {
146146
throw new SocketIOException("transport not supported");

AndroidAsync/src/com/koushikdutta/async/http/socketio/transport/SocketIOTransport.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,6 @@ static public interface StringCallback {
3535
* @return
3636
*/
3737
public boolean heartbeats();
38+
39+
public String getSessionId();
3840
}

AndroidAsync/src/com/koushikdutta/async/http/socketio/transport/WebSocketTransport.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88
public class WebSocketTransport implements SocketIOTransport {
99
private WebSocket webSocket;
1010
private StringCallback stringCallback;
11+
private String sessionId;
1112

12-
public WebSocketTransport(WebSocket webSocket) {
13+
public WebSocketTransport(WebSocket webSocket, String sessionId) {
1314
this.webSocket = webSocket;
14-
15+
this.sessionId = sessionId;
1516
this.webSocket.setDataCallback(new NullDataCallback());
1617
}
1718

@@ -63,4 +64,10 @@ public void onStringAvailable(String s) {
6364
public boolean heartbeats() {
6465
return true;
6566
}
67+
68+
@Override
69+
public String getSessionId() {
70+
return this.sessionId;
71+
}
6672
}
73+

AndroidAsync/src/com/koushikdutta/async/http/socketio/transport/XHRPollingTransport.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@ public class XHRPollingTransport implements SocketIOTransport {
1818
private StringCallback stringCallback;
1919
private CompletedCallback closedCallback;
2020
private boolean connected;
21+
private String sessionId;
2122

2223
private static final String SEPARATOR = "\ufffd";
2324

24-
public XHRPollingTransport(AsyncHttpClient client, String sessionUrl) {
25+
public XHRPollingTransport(AsyncHttpClient client, String sessionUrl, String sessionId) {
2526
this.client = client;
2627
this.sessionUrl = Uri.parse(sessionUrl);
27-
28+
this.sessionId = sessionId;
29+
2830
doLongPolling();
2931
connected = true;
3032
}
@@ -135,4 +137,9 @@ public void setStringCallback(StringCallback callback) {
135137
public boolean heartbeats() {
136138
return false;
137139
}
140+
141+
@Override
142+
public String getSessionId() {
143+
return this.sessionId;
144+
}
138145
}

0 commit comments

Comments
 (0)