Browse Source

Added a simple method to get all the rooms for a single namespace.

Added the ability to use the "io" cookie for the sessionId if it is present.
master
Ryan Dietrich 10 years ago
parent
commit
5067894bab
  1. 21
      src/main/java/com/corundumstudio/socketio/handler/AuthorizeHandler.java
  2. 4
      src/main/java/com/corundumstudio/socketio/namespace/Namespace.java

21
src/main/java/com/corundumstudio/socketio/handler/AuthorizeHandler.java

@ -98,7 +98,7 @@ public class AuthorizeHandler extends ChannelInboundHandlerAdapter implements Di
}, configuration.getFirstDataTimeout(), TimeUnit.MILLISECONDS); }, configuration.getFirstDataTimeout(), TimeUnit.MILLISECONDS);
super.channelActive(ctx); super.channelActive(ctx);
} }
@Override @Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
SchedulerKey key = new SchedulerKey(Type.PING_TIMEOUT, ctx.channel()); SchedulerKey key = new SchedulerKey(Type.PING_TIMEOUT, ctx.channel());
@ -159,8 +159,7 @@ public class AuthorizeHandler extends ChannelInboundHandlerAdapter implements Di
return false; return false;
} }
// TODO try to get sessionId from cookie
UUID sessionId = UUID.randomUUID();
UUID sessionId = this.generateOrGetSessionIdFromRequest(headers);
List<String> transportValue = params.get("transport"); List<String> transportValue = params.get("transport");
if (transportValue == null) { if (transportValue == null) {
@ -193,6 +192,22 @@ public class AuthorizeHandler extends ChannelInboundHandlerAdapter implements Di
return true; return true;
} }
/**
This method will either generate a new random sessionId or will retrieve the value stored
in the "io" cookie. Failures to parse will cause a logging warning to be generated and a
random uuid to be generated instead (same as not passing a cookie in the first place).
*/
private UUID generateOrGetSessionIdFromRequest(Map<String, List<String>> headers) {
if ( headers.containsKey("io") && headers.get("io").size() == 1 ) {
try {
return UUID.fromString(headers.get("io").get(0));
} catch ( IllegalArgumentException iaex ) {
log.warn("Malformed UUID received for session! io=" + headers.get("io"));
}
}
return UUID.randomUUID();
}
public void connect(UUID sessionId) { public void connect(UUID sessionId) {
SchedulerKey key = new SchedulerKey(Type.PING_TIMEOUT, sessionId); SchedulerKey key = new SchedulerKey(Type.PING_TIMEOUT, sessionId);
disconnectScheduler.cancel(key); disconnectScheduler.cancel(key);

4
src/main/java/com/corundumstudio/socketio/namespace/Namespace.java

@ -310,6 +310,10 @@ public class Namespace implements SocketIONamespace {
return Collections.unmodifiableSet(res); return Collections.unmodifiableSet(res);
} }
public Set<String> getRooms() {
return roomClients.keySet();
}
public Iterable<SocketIOClient> getRoomClients(String room) { public Iterable<SocketIOClient> getRoomClients(String room) {
Set<UUID> sessionIds = roomClients.get(room); Set<UUID> sessionIds = roomClients.get(room);

Loading…
Cancel
Save