public void validateToken(Map<String, String> msg) {
    String token = (String) msg.get("authToken");

    BigBlueButtonSession bbbSession =
        (BigBlueButtonSession) Red5.getConnectionLocal().getAttribute(Constants.SESSION);
    assert bbbSession != null;
    String userId = bbbSession.getInternalUserID();
    String meetingId = Red5.getConnectionLocal().getScope().getName();
    String connId = Red5.getConnectionLocal().getSessionId();
    String sessionId = CONN + connId + "-" + userId;

    Map<String, Object> logData = new HashMap<String, Object>();
    logData.put("meetingId", meetingId);
    logData.put("connId", connId);
    logData.put("sessionId", sessionId);
    logData.put("userId", userId);
    logData.put("token", token);
    logData.put("event", "user_validate_token_bbb_apps");
    logData.put("description", "User validate token BBB Apps.");

    Gson gson = new Gson();
    String logStr = gson.toJson(logData);

    log.info("User validate token bbb-apps: data={}", logStr);
    red5InGW.validateAuthToken(meetingId, userId, token, meetingId + "/" + userId, sessionId);
  }
  @Override
  public void roomStop(IScope room) {
    log.debug("Stopping room [" + room.getName() + "].");
    super.roomStop(room);
    assert participantsApplication != null;
    participantsApplication.destroyRoom(room.getName());
    BigBlueButtonSession bbbSession = getBbbSession();
    assert bbbSession != null;

    /** Need to figure out if the next 2 lines should be removed. (ralam nov 25, 2010). */
    assert recorderApplication != null;
    recorderApplication.destroyRecordSession(bbbSession.getSessionName());

    log.debug("Stopped room [" + room.getName() + "].");
  }
  @Override
  public void roomDisconnect(IConnection conn) {
    String remoteHost = Red5.getConnectionLocal().getRemoteAddress();
    int remotePort = Red5.getConnectionLocal().getRemotePort();
    String clientId = Red5.getConnectionLocal().getClient().getId();
    log.info(
        "[clientid=" + clientId + "] disconnnected from " + remoteHost + ":" + remotePort + ".");

    BigBlueButtonSession bbbSession =
        (BigBlueButtonSession) Red5.getConnectionLocal().getAttribute(Constants.SESSION);
    log.info(
        "User ["
            + bbbSession.getUsername()
            + "] disconnected from room ["
            + bbbSession.getRoom()
            + "]");
    super.roomDisconnect(conn);
  }
  @Override
  public void roomDisconnect(IConnection conn) {

    String remoteHost = Red5.getConnectionLocal().getRemoteAddress();
    int remotePort = Red5.getConnectionLocal().getRemotePort();
    String clientId = Red5.getConnectionLocal().getClient().getId();

    BigBlueButtonSession bbbSession =
        (BigBlueButtonSession) Red5.getConnectionLocal().getAttribute(Constants.SESSION);

    String meetingId = bbbSession.getRoom();
    String userId = bbbSession.getInternalUserID();
    String connType = getConnectionType(Red5.getConnectionLocal().getType());
    String userFullname = bbbSession.getUsername();
    String connId = Red5.getConnectionLocal().getSessionId();

    String sessionId = CONN + userId;

    Map<String, Object> logData = new HashMap<String, Object>();
    logData.put("meetingId", meetingId);
    logData.put("connType", connType);
    logData.put("connId", connId);
    logData.put("conn", remoteHost + ":" + remotePort);
    logData.put("sessionId", sessionId);
    logData.put("userId", userId);
    logData.put("username", userFullname);
    logData.put("event", "user_leaving_bbb_apps");
    logData.put("description", "User leaving BBB Apps.");

    Gson gson = new Gson();
    String logStr = gson.toJson(logData);

    boolean removeUser = userConnections.userDisconnected(userId, connId);

    if (removeUser) {
      log.info("User leaving bbb-apps: data={}", logStr);
      red5InGW.userLeft(bbbSession.getRoom(), getBbbSession().getInternalUserID(), sessionId);
    } else {
      log.info("User not leaving bbb-apps but just disconnected: data={}", logStr);
    }

    super.roomDisconnect(conn);
  }
  @Override
  public boolean roomConnect(IConnection connection, Object[] params) {
    String username = ((String) params[0]).toString();
    String role = ((String) params[1]).toString();
    String room = ((String) params[2]).toString();

    String voiceBridge = ((String) params[3]).toString();

    boolean record = (Boolean) params[4];

    String externalUserID = ((String) params[5]).toString();
    String internalUserID = ((String) params[6]).toString();

    Boolean muted = false;
    if (params.length >= 7 && ((Boolean) params[7])) {
      muted = true;
    }

    Map<String, Boolean> lsMap = null;
    if (params.length >= 8) {
      try {
        lsMap = (Map<String, Boolean>) params[8];
      } catch (Exception e) {
        lsMap = new HashMap<String, Boolean>();
      }
    }

    String userId = internalUserID;
    String sessionId = CONN + userId;
    BigBlueButtonSession bbbSession =
        new BigBlueButtonSession(
            room,
            internalUserID,
            username,
            role,
            voiceBridge,
            record,
            externalUserID,
            muted,
            sessionId);
    connection.setAttribute(Constants.SESSION, bbbSession);
    connection.setAttribute("INTERNAL_USER_ID", internalUserID);
    connection.setAttribute("USER_SESSION_ID", sessionId);
    connection.setAttribute("TIMESTAMP", System.currentTimeMillis());

    red5InGW.initLockSettings(room, lsMap);

    red5InGW.initAudioSettings(room, internalUserID, muted);

    String meetingId = bbbSession.getRoom();

    String connType = getConnectionType(Red5.getConnectionLocal().getType());
    String userFullname = bbbSession.getUsername();
    String connId = Red5.getConnectionLocal().getSessionId();

    String remoteHost = Red5.getConnectionLocal().getRemoteAddress();
    int remotePort = Red5.getConnectionLocal().getRemotePort();

    Map<String, Object> logData = new HashMap<String, Object>();
    logData.put("meetingId", meetingId);
    logData.put("connType", connType);
    logData.put("connId", connId);
    logData.put("conn", remoteHost + ":" + remotePort);
    logData.put("userId", userId);
    logData.put("externalUserId", externalUserID);
    logData.put("sessionId", sessionId);
    logData.put("username", userFullname);
    logData.put("event", "user_joining_bbb_apps");
    logData.put("description", "User joining BBB Apps.");

    Gson gson = new Gson();
    String logStr = gson.toJson(logData);

    log.info("User joining bbb-apps: data={}", logStr);

    userConnections.addUserConnection(userId, connId);

    return super.roomConnect(connection, params);
  }
 public String getMyUserId() {
   BigBlueButtonSession bbbSession =
       (BigBlueButtonSession) Red5.getConnectionLocal().getAttribute(Constants.SESSION);
   assert bbbSession != null;
   return Long.toString(bbbSession.getUserid());
 }