コード例 #1
0
  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;
  }
コード例 #2
0
  public void dispatch(String room, Packet packet) {
    Iterable<SocketIOClient> clients = getRoomClients(room);

    for (SocketIOClient socketIOClient : clients) {
      socketIOClient.send(packet);
    }
  }
コード例 #3
0
  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);
    }
  }
コード例 #4
0
 public Set<String> getRooms(SocketIOClient client) {
   Set<String> res = clientRooms.get(client.getSessionId());
   if (res == null) {
     return Collections.emptySet();
   }
   return Collections.unmodifiableSet(res);
 }
コード例 #5
0
  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);
    }
  }
コード例 #6
0
 @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);
 }
コード例 #7
0
 /* 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()));
 }
コード例 #8
0
 public void endSession(SocketIOClient client) {
   assert client != null;
   Session session = sessions.remove(client.getSessionId());
   Preconditions.checkNotNull(session);
   session.end();
 }
コード例 #9
0
 public void addClient(SocketIOClient client) {
   allClients.put(client.getSessionId(), client);
 }
コード例 #10
0
 @OnConnect
 public void welcome(SocketIOClient client) {
   client.sendEvent("login", "");
 }