示例#1
0
 /** Pass through all Ping events to origin except ping/pong */
 protected void onPing(RTMPConnection conn, Channel channel, Header source, Ping ping) {
   switch (ping.getEventType()) {
     case Ping.PONG_SERVER:
       // This is the response to an IConnection.ping request
       conn.pingReceived(ping);
       break;
     default:
       // forward other to origin
       Packet p = new Packet(source);
       p.setMessage(ping);
       forwardPacket(conn, p);
   }
 }
示例#2
0
  protected void handleConnect(
      RTMPConnection conn, Channel channel, Header header, Invoke invoke, RTMP rtmp) {
    final IPendingServiceCall call = invoke.getCall();
    // Get parameters passed from client to NetConnection#connection
    final Map<String, Object> params = invoke.getConnectionParams();

    // Get hostname
    String host = getHostname((String) params.get("tcUrl"));

    // App name as path, but without query string if there is one
    String path = (String) params.get("app");
    if (path.indexOf("?") != -1) {
      int idx = path.indexOf("?");
      params.put("queryString", path.substring(idx));
      path = path.substring(0, idx);
    }
    params.put("path", path);

    final String sessionId = null;

    conn.setup(host, path, sessionId, params);

    // check the security constraints
    // send back "ConnectionRejected" if fails.
    if (!checkPermission(conn)) {
      call.setStatus(Call.STATUS_ACCESS_DENIED);
      call.setResult(getStatus(NC_CONNECT_REJECTED));
      Invoke reply = new Invoke();
      reply.setCall(call);
      reply.setInvokeId(invoke.getInvokeId());
      channel.write(reply);
      conn.close();
    } else {
      synchronized (rtmp) {
        // connect the origin
        sendConnectMessage(conn);
        rtmp.setState(RTMP.STATE_EDGE_CONNECT_ORIGIN_SENT);
        Packet packet = new Packet(header);
        packet.setMessage(invoke);
        forwardPacket(conn, packet);
        rtmp.setState(RTMP.STATE_ORIGIN_CONNECT_FORWARDED);
        // Evaluate request for AMF3 encoding
        if (Integer.valueOf(3).equals(params.get("objectEncoding"))) {
          rtmp.setEncoding(Encoding.AMF3);
        }
      }
    }
  }