Skip to content

Commit 4d15ec9

Browse files
committed
Merge pull request koush#258 from surfstudio/session_id
Expose socket io session id to SocketIOTransport
2 parents 1987519 + be2ab21 commit 4d15ec9

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
@@ -111,7 +111,7 @@ void reconnect(final DependentCancellable child) {
111111
@Override
112112
protected void transform(String result) throws Exception {
113113
String[] parts = result.split(":");
114-
String session = parts[0];
114+
final String sessionId = parts[0];
115115
if (!"".equals(parts[1]))
116116
heartbeat = Integer.parseInt(parts[1]) / 2 * 1000;
117117
else
@@ -124,7 +124,7 @@ protected void transform(String result) throws Exception {
124124

125125
if (set.contains("websocket")) {
126126
final String sessionUrl = Uri.parse(request.getUri().toString()).buildUpon()
127-
.appendPath("websocket").appendPath(session)
127+
.appendPath("websocket").appendPath(sessionId)
128128
.build().toString();
129129

130130
httpClient.websocket(sessionUrl, null, null)
@@ -135,14 +135,14 @@ public void onCompleted(Exception e, WebSocket result) {
135135
transport.setComplete(e);
136136
return;
137137
}
138-
transport.setComplete(new WebSocketTransport(result));
138+
transport.setComplete(new WebSocketTransport(result, sessionId));
139139
}
140140
});
141141
} else if (set.contains("xhr-polling")) {
142142
final String sessionUrl = Uri.parse(request.getUri().toString()).buildUpon()
143-
.appendPath("xhr-polling").appendPath(session)
143+
.appendPath("xhr-polling").appendPath(sessionId)
144144
.build().toString();
145-
XHRPollingTransport xhrPolling = new XHRPollingTransport(httpClient, sessionUrl);
145+
XHRPollingTransport xhrPolling = new XHRPollingTransport(httpClient, sessionUrl, sessionId);
146146
transport.setComplete(xhrPolling);
147147
} else {
148148
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)