예제 #1
0
 private void updateUserList() {
   List<String> usernames = new ArrayList<>();
   for (Session s : session.getOpenSessions()) {
     String uname = (String) s.getUserProperties().get(USERNAME_KEY);
     usernames.add(uname);
   }
   this.endpointConfig.getUserProperties().put(USERNAMES_KEY, usernames);
 }
예제 #2
0
  private void broadcastTranscriptUpdate() {
    String v = this.transcript.getRec();
    String g;
    if (c.equals(v)) {
      for (Session nextSession : session.getOpenSessions()) {

        ChatUpdateMessage cdm =
            new ChatUpdateMessage(
                this.transcript.getLastUsername(),
                this.transcript.getLastMessage(),
                this.transcript.getRec());

        try {
          nextSession.getBasicRemote().sendObject(cdm);
        } catch (IOException | EncodeException ex) {
          System.out.println("Error updating a client : " + ex.getMessage());
        }
      }
    } else {
      for (Session nextSession : session.getOpenSessions()) {
        String check = this.transcript.getRec();
        ChatUpdateMessage cdm =
            new ChatUpdateMessage(
                this.transcript.getLastUsername(),
                this.transcript.getLastMessage(),
                this.transcript.getRec());
        g = (String) nextSession.getUserProperties().get(USERNAME_KEY);
        if (v.equals(g)) {
          try {
            nextSession.getBasicRemote().sendObject(cdm);
          } catch (IOException | EncodeException ex) {
            System.out.println("Error updating a client : " + ex.getMessage());
          }
        }
      }
    }
  }
예제 #3
0
 private void registerUser(String username) {
   System.out.println("Inside registration");
   session.getUserProperties().put(USERNAME_KEY, username);
   this.updateUserList();
 }
예제 #4
0
 private String getCurrentUsername() {
   return (String) session.getUserProperties().get(USERNAME_KEY);
 }