Development Notes
Creating Your Own RTMP Messages
For the messages that the RtmpClient does not support
you can create your own using the message classes derived from RtmpMessage.
There are two ways to create your own RTMP messages.
Create an instance of the whichever message class correspondents to a message type, for example, a Command(AMF0) message could be created using the RtmpMessage_CommandAmf0 class.
Or create a raw message, and format the binary content yourself, which is a lot harder.
The following is an example of creating a "play" command message, starting with a new RtmpMessage_CommandAmf0 object.
The ComandAmf0 class has a property "Parameters", which is a reference to a list of parameters. The "Amf0" refers to the formatting of the parameters of the message.
RtmpMessage_CommandAmf0
cmd = new
RtmpMessage_CommandAmf0(
m_rtmpConnection.GetNextAmfStreamId(),
m_rtmpConnection.Timestamp,
1
);
cmd.Parameters.Add( new
RtmpParameter_String(null,"play") );
cmd.Parameters.Add( new
RtmpParameter_Number(null,0) );
cmd.Parameters.Add( new RtmpParameter_Null(null) );
cmd.Parameters.Add( new
RtmpParameter_String(null,"mp3:song01.mp3") );
cmd.Parameters.Add( new
RtmpParameter_Number(null,0) );
cmd.Parameters.Add( new
RtmpParameter_Number(null,-1) );
cmd.Parameters.Add( new
RtmpParameter_Undefined(null) );
To send this message, pass the message to the connection's SendMessage function.
Customizing How You Connect
Some users will want to customize their connection message by adding additional parameters.
To do this, first create a vanilla connection message, using the function:
RtmpMessage_CommandAmf0 RtmpMessage_CommandAmf0.Build_NetConnection_Connect( ... );
This function takes the same parameters as the alternative
ConnectToApplication function, and returns a valid Amf0 connection message.
Next,
customize this message with your own parameters. Below is an example of how to do this. Here, I search
for the OBJECT parameter in the Amf0 message, and add my own parameters to this. If I had added the parameter to the message itself, it is unlikely the
RTMP server that receives it would see it as a connection message.
RtmpParameter[] paramList =
connectionMsg.Parameters.FindByType(
RtmpParameter.eAmfDataType.Object
);
RtmpParameter_Object
obParam = paramList[0] as
RtmpParameter_Object;
obParam.Parameters.Add(
new
RtmpParameter_String("ExtraParamLabel","ParamValue")
);
Finally, I call the ConnectToApplication function with my customized message as the only parameter.
rtmpConn.ConnectToApplication(connectionMsg);
This code is included in the
FileDump project code,
FileDump.cs.