Skip to content

Commit

Permalink
Added a simple method to get all the rooms for a single namespace.
Browse files Browse the repository at this point in the history
Added the ability to use the "io" cookie for the sessionId if it is present.
  • Loading branch information
ryandietrich committed Jun 10, 2015
1 parent c1d134a commit 5067894
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public void run() {
}, configuration.getFirstDataTimeout(), TimeUnit.MILLISECONDS);
super.channelActive(ctx);
}

@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
SchedulerKey key = new SchedulerKey(Type.PING_TIMEOUT, ctx.channel());
Expand Down Expand Up @@ -159,8 +159,7 @@ private boolean authorize(ChannelHandlerContext ctx, Channel channel, String ori
return false;
}

// TODO try to get sessionId from cookie
UUID sessionId = UUID.randomUUID();
UUID sessionId = this.generateOrGetSessionIdFromRequest(headers);

List<String> transportValue = params.get("transport");
if (transportValue == null) {
Expand Down Expand Up @@ -193,6 +192,22 @@ private boolean authorize(ChannelHandlerContext ctx, Channel channel, String ori
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) {
SchedulerKey key = new SchedulerKey(Type.PING_TIMEOUT, sessionId);
disconnectScheduler.cancel(key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,10 @@ public Set<String> getRooms(SocketIOClient client) {
return Collections.unmodifiableSet(res);
}

public Set<String> getRooms() {
return roomClients.keySet();
}

public Iterable<SocketIOClient> getRoomClients(String room) {
Set<UUID> sessionIds = roomClients.get(room);

Expand Down

0 comments on commit 5067894

Please sign in to comment.