public Session startSession(SocketIOClient client) { Preconditions.checkNotNull(client); Session session = new Session(client.getRemoteAddress(), cateScraper, timetableScraper); sessions.put(client.getSessionId(), session); session.addSessionEventListener( new SessionEventListener() { @Override public void authSuccess(UserInfo userInfo) { if (motd != null) { session.motd(motd); } } @Override public void authLoginFailed() {} @Override public void authKick() {} @Override public void updateWork(WorkInfo work) {} @Override public void updateTimetable(Timetable timetable) {} @Override public void motd(String motd) {} }); return session; }
public void dispatch(String room, Packet packet) { Iterable<SocketIOClient> clients = getRoomClients(room); for (SocketIOClient socketIOClient : clients) { socketIOClient.send(packet); } }
public void onConnect(SocketIOClient client) { join(getName(), client.getSessionId()); storeFactory .pubSubStore() .publish( PubSubStore.JOIN, new JoinLeaveMessage(client.getSessionId(), getName(), getName())); try { for (ConnectListener listener : connectListeners) { listener.onConnect(client); } } catch (Exception e) { exceptionListener.onConnectException(e, client); } }
public Set<String> getRooms(SocketIOClient client) { Set<String> res = clientRooms.get(client.getSessionId()); if (res == null) { return Collections.emptySet(); } return Collections.unmodifiableSet(res); }
public void onDisconnect(SocketIOClient client) { allClients.remove(client.getSessionId()); leave(getName(), client.getSessionId()); storeFactory .pubSubStore() .publish( PubSubStore.LEAVE, new JoinLeaveMessage(client.getSessionId(), getName(), getName())); try { for (DisconnectListener listener : disconnectListeners) { listener.onDisconnect(client); } } catch (Exception e) { exceptionListener.onDisconnectException(e, client); } }
@OnEvent("get_auth_qr") public void getAuthQr(SocketIOClient client, Object data, AckRequest ackRequest) { NutMap re = new NutMap(); try { // TODO 可配置 SeckenResp resp = secken .getAuth(1, "https://nutz.cn/secken/callback/" + R.UU32(client.getSessionId())) .check(); String url = resp.qrcode_url(); re.put("ok", true); re.put("url", url); } catch (Exception e) { log.debug("获取洋葱授权二维码识别", e); re.put("msg", "获取洋葱授权二维码识别"); } client.sendEvent("new_auth_qr", re); }
/* Can still arrive after a given session has ended. */ public Optional<Session> getSession(SocketIOClient client) { assert client != null; return Optional.ofNullable(sessions.get(client.getSessionId())); }
public void endSession(SocketIOClient client) { assert client != null; Session session = sessions.remove(client.getSessionId()); Preconditions.checkNotNull(session); session.end(); }
public void addClient(SocketIOClient client) { allClients.put(client.getSessionId(), client); }
@OnConnect public void welcome(SocketIOClient client) { client.sendEvent("login", ""); }