Exemplo n.º 1
0
 @Override
 public void onData(MessageInfo mi, RTMPCommand command) {
   String handlerName = (String) command.getArguments().get(0);
   if (HANDLER_NAME_SET_DATA_FRAME.equals(handlerName)) {
     metaData = (Map) command.getArguments().get(2);
     System.err.println("metadata: " + command.getArguments());
   } else {
     System.err.println("Unknown data: " + command.getArguments());
   }
 }
Exemplo n.º 2
0
  protected void cmdPublish(MessageInfo mi, RTMPCommand command) {

    Object arg1 = command.getArguments().get(0);
    if (!(arg1 instanceof String)) {
      sendSuccess(mi, command);
      return;
    }

    String streamName = (String) command.getArguments().get(0);
    int separatorPos = streamName.indexOf(STREAM_NAME_SEPARATOR);
    if (separatorPos == -1) {
      Map<String, Object> info = new HashMap<>();
      info.put("code", "NetStream.Publish.BadName"); // with lack of better choice
      info.put("level", "error");
      info.put("description", "Stream password required.");
      terminateWithError(mi, command, null, info);
      return;
    }
    String clientStreamID = streamName.substring(0, separatorPos);
    String clientSecret = streamName.substring(separatorPos + 1);

    String streamProperty = props.getProperty("streams." + clientStreamID);
    if (!"true".equals(streamProperty) && !"1".equals(streamProperty)) {
      Map<String, Object> info = new HashMap<>();
      info.put("code", "NetStream.Publish.BadName"); // with lack of better choice
      info.put("level", "error");
      info.put("description", "Stream does not exist.");
      terminateWithError(mi, command, null, info);
      return;
    }

    String streamSectret = props.getProperty("streams." + clientStreamID + ".password");
    if (streamSectret == null) {
      Map<String, Object> info = new HashMap<>();
      info.put("code", "NetStream.Publish.BadName"); // with lack of better choice
      info.put("level", "error");
      info.put("description", "Stream does not exist.");
      terminateWithError(mi, command, null, info);
      return;
    }
    if (!clientSecret.equals(streamSectret)) {
      Map<String, Object> info = new HashMap<>();
      info.put("code", "NetStream.Publish.BadName"); // with lack of better choice
      info.put("level", "error");
      info.put("description", "Authentication error.");
      terminateWithError(mi, command, null, info);
      return;
    }

    // raise limit after successful authentication
    context.getLimit().assemblyBufferSize = 256 * 1024;
    context.getLimit().assemblyBufferCount = 16;
    context.getLimit().chunkStreamCount = 32;

    streamID = clientStreamID;

    AMFPacket response = new AMFPacket();
    response.writeString("onStatus");
    response.writeNumber(fcpublishTxID);

    response.writeMixed(null);

    Map<String, Object> arg2 = new HashMap<>();
    arg2.put("level", "status");
    arg2.put("code", "NetStream.Publish.Start");
    arg2.put("description", "");
    arg2.put("details", command.getArguments().get(0));
    arg2.put("clientId", 1d);
    arg2.put("objectEncoding", 0d);
    response.writeObject(arg2);

    context.writeCommand(mi.chunkStreamID, mi.messageStreamID, response);
  }