Java Code Examples for org.red5.server.api.IConnection#getClient()

The following examples show how to use org.red5.server.api.IConnection#getClient() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MultiThreadedApplicationAdapter.java    From red5-server-common with Apache License 2.0 6 votes vote down vote up
/**
 * Returns disconnection result for given scope and parameters. Whether the scope is room or app level scope, this method distinguishes
 * it and acts accordingly.
 * 
 * @param conn
 *            Connection object
 * @param scope
 *            Scope
 */
@Override
public void disconnect(IConnection conn, IScope scope) {
    log.debug("disconnect: {} < {}", conn, scope);
    if (log.isInfoEnabled() && ScopeUtils.isApp(scope)) {
        // log w3c connect event
        IClient client = conn.getClient();
        if (client == null) {
            // log w3c connect event
            log.info("W3C x-category:session x-event:disconnect c-ip:{}", conn.getRemoteAddress());
        } else {
            // log w3c connect event
            log.info("W3C x-category:session x-event:disconnect c-ip:{} c-client-id:{}", conn.getRemoteAddress(), client.getId());
        }
    }
    if (ScopeUtils.isApp(scope)) {
        appDisconnect(conn);
    } else if (ScopeUtils.isRoom(scope)) {
        roomDisconnect(conn);
    }
    super.disconnect(conn, scope);
}
 
Example 2
Source File: MultiThreadedApplicationAdapter.java    From red5-server-common with Apache License 2.0 5 votes vote down vote up
/**
 * Returns connection result for given scope and parameters. Whether the scope is room or app level scope, this method distinguishes it
 * and acts accordingly. You override {@link ApplicationAdapter#appConnect(IConnection, Object[])} or
 * {@link ApplicationAdapter#roomConnect(IConnection, Object[])} in your application to make it act the way you want.
 * 
 * @param conn
 *            Connection object
 * @param scope
 *            Scope
 * @param params
 *            List of params passed to connection handler
 * @return <code>
 * true
 * </code>
 * 
 *         if connect is successful,
 * 
 *         <code>
 * false
 * </code>
 * 
 *         otherwise
 */
@Override
public boolean connect(IConnection conn, IScope scope, Object[] params) {
    // ensure the log is not null at this point
    if (log == null) {
        log = Red5LoggerFactory.getLogger(this.getClass());
    }
    log.debug("connect: {} > {}", conn, scope);
    boolean success = false;
    // hit the super class first
    if (super.connect(conn, scope, params)) {
        if (log.isInfoEnabled() && ScopeUtils.isApp(scope)) {
            // log w3c connect event
            IClient client = conn.getClient();
            if (client == null) {
                log.info("W3C x-category:session x-event:connect c-ip:{}", conn.getRemoteAddress());
            } else {
                log.info("W3C x-category:session x-event:connect c-ip:{} c-client-id:{}", conn.getRemoteAddress(), client.getId());
            }
        }
        if (ScopeUtils.isApp(scope)) {
            success = appConnect(conn, params);
        } else if (ScopeUtils.isRoom(scope)) {
            success = roomConnect(conn, params);
        } else {
            log.warn("Scope was not of app or room type, connect failed");
        }
    }
    return success;
}
 
Example 3
Source File: Scope.java    From red5-server-common with Apache License 2.0 4 votes vote down vote up
/**
 * Connect to scope with parameters. To successfully connect to scope it must have handler that will accept this connection with given
 * set of parameters. Client associated with connection is added to scope clients set, connection is registered as scope event listener.
 * 
 * @param conn
 *            Connection object
 * @param params
 *            Parameters passed with connection
 * @return true on success, false otherwise
 */
public boolean connect(IConnection conn, Object[] params) {
    log.debug("Connect - scope: {} connection: {}", this, conn);
    if (enabled) {
        if (hasParent() && !parent.connect(conn, params)) {
            log.debug("Connection to parent failed");
            return false;
        }
        if (hasHandler() && !getHandler().connect(conn, this, params)) {
            log.debug("Connection to handler failed");
            return false;
        }
        if (!conn.isConnected()) {
            log.debug("Connection is not connected");
            // timeout while connecting client
            return false;
        }
        final IClient client = conn.getClient();
        // we would not get this far if there is no handler
        if (hasHandler() && !getHandler().join(client, this)) {
            return false;
        }
        // checking the connection again? why?
        if (!conn.isConnected()) {
            // timeout while connecting client
            return false;
        }
        // add the client and event listener
        if (clients.add(client) && addEventListener(conn)) {
            log.debug("Added client");
            // increment conn stats
            connectionStats.increment();
            // get connected scope
            IScope connScope = conn.getScope();
            log.trace("Connection scope: {}", connScope);
            if (this.equals(connScope)) {
                final IServer server = getServer();
                if (server instanceof Server) {
                    ((Server) server).notifyConnected(conn);
                }
            }
            return true;
        }
    } else {
        log.debug("Connection failed, scope is disabled");
    }
    return false;
}