/** {@inheritDoc} */ @Override public void messageReceived(IoSession session, Object message) throws Exception { if (log.isTraceEnabled()) { log.trace("messageReceived session: {} message: {}", session, message); log.trace("Filter chain: {}", session.getFilterChain()); } String sessionId = (String) session.getAttribute(RTMPConnection.RTMP_SESSION_ID); if (log.isTraceEnabled()) { log.trace("Message received on session: {} id: {}", session.getId(), sessionId); } RTMPMinaConnection conn = (RTMPMinaConnection) RTMPConnManager.getInstance().getConnectionBySessionId(sessionId); if (conn != null) { if (message != null) { if (message instanceof Packet) { byte state = conn.getStateCode(); // checking the state before allowing a task to be created will hopefully prevent rejected // task exceptions if (state != RTMP.STATE_DISCONNECTING && state != RTMP.STATE_DISCONNECTED) { conn.handleMessageReceived((Packet) message); } else { log.info( "Ignoring received message on {} due to state: {}", sessionId, RTMP.states[state]); } } } } else { log.warn("Connection was not found for {}, force closing", sessionId); forceClose(session); } }
/** {@inheritDoc} */ @Override public void sessionCreated(IoSession session) throws Exception { log.debug("Session created RTMP"); // add rtmpe filter, rtmp protocol filter is added upon successful handshake session.getFilterChain().addFirst("rtmpeFilter", new RTMPEIoFilter()); // create a connection RTMPMinaConnection conn = createRTMPMinaConnection(); // add session to the connection conn.setIoSession(session); // add the handler conn.setHandler(handler); // add the connections session id for look up using the connection manager session.setAttribute(RTMPConnection.RTMP_SESSION_ID, conn.getSessionId()); // create an inbound handshake InboundHandshake handshake = new InboundHandshake(); // set whether or not unverified will be allowed handshake.setUnvalidatedConnectionAllowed( ((RTMPHandler) handler).isUnvalidatedConnectionAllowed()); // add the in-bound handshake, defaults to non-encrypted mode session.setAttribute(RTMPConnection.RTMP_HANDSHAKE, handshake); }
/** {@inheritDoc} */ @Override public void messageSent(IoSession session, Object message) throws Exception { log.trace("messageSent session: {} message: {}", session, message); String sessionId = (String) session.getAttribute(RTMPConnection.RTMP_SESSION_ID); if (log.isTraceEnabled()) { log.trace("Message sent on session: {} id: {}", session.getId(), sessionId); } if (sessionId != null) { RTMPMinaConnection conn = (RTMPMinaConnection) RTMPConnManager.getInstance().getConnectionBySessionId(sessionId); if (conn != null) { final byte state = conn.getStateCode(); switch (state) { case RTMP.STATE_CONNECTED: if (message instanceof Packet) { handler.messageSent(conn, (Packet) message); } else if (log.isDebugEnabled()) { log.debug( "Message was not of Packet type; its type: {}", message != null ? message.getClass().getName() : "null"); } break; case RTMP.STATE_CONNECT: case RTMP.STATE_HANDSHAKE: if (log.isTraceEnabled()) { log.trace("messageSent: {}", Hex.encodeHexString(((IoBuffer) message).array())); } break; case RTMP.STATE_DISCONNECTING: case RTMP.STATE_DISCONNECTED: default: } } else { log.warn( "Destination connection was null, it is already disposed. Session id: {}", sessionId); } } }