Skip to content

liuyunxiong/rtmpsharp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rtmp-sharp (v0.3) NuGet

rtmp-sharp is a fast and lightweight data-oriented RTMP(S) library for .NET Desktop and .NET Core. Install from NuGet, or compile from source.

Example Usage

var context = new SerializationContext();
var options = new RtmpClient.Options()
{
    // required parameters:
    Url         = "rtmp://ingress.winky.com:1234",
    Context     = context,

    // optional parameters:
    AppName     = "demo-app",                                  // optional app name, passed to the remote server during connect.
    PageUrl     = "https://example.com/rtmpsharp/demo.html",   // optional page url, passed to the remote server during connect.
    SwfUrl      = "",                                          // optional swf url,  passed to the remote server during connect.
    ChunkLength = 4192,                                        // optional outgoing rtmp chunk length.
    Validate    = (sender, certificate, chain, errors) => true // optional certificate validation callback. used only in tls connections.
};

var client = await RtmpClient.ConnectAsync(options);
var exists = await client.InvokeAsync<bool>("storage", "exists", new { name = "music.pdf" });

The Serialization Context

The SerializationContext isolates different serialization domains, and holds information mappings for type serialization. this allows you to have separate serialization domains for different services and not worry about namespace collisions: twitchtv + youtube may both expose an rtmp interface, but have slightly different definitions for what constitutes a video object.

The SerializationContext constructor accepts an optional array of types that the instance should serialize into their respective concrete types. If rtmp-sharp receives a type that isn't registered, it will by default deserialize that object into an AsObject. If you don't like this, and want to fail deserialization, then turn AsObjectFallback off. So if you do not pass it any types, then all objects will be deserialized into anonymous AsObjects.

// constructor definition:
//     new SerializationContext(params Type[] types);

AsObjects support the DLR and can thus be used with dynamic - this may be more convenient for some use cases.

dynamic d = await client.InvokeAsync<dynamic>("greeter-service", "greet", "hello!");

Console.WriteLine(d.items[0].greeting)
// => hello!

Type Annotations

By default, rtmp-sharp will serialize all public fields and public properties using their field names. You may instruct rtmp-sharp to use a different name for serialization by simply annotating the interested types or members with the RtmpSharp attribute. Ignore a field by annotating it with RtmpIgnore.

namespace Winky
{
    // without annotation: `Winky.StorageEntry`
    // with annotation:    `org.winky.StorageEntry`
    [RtmpSharp("org.winky.StorageEntry")]
    public class StorageEntry
    {
        // without the `RtmpSharp` annotation, this field would be encoded as `Name` over the wire. with this
        // annotation, it is instead encoded as the field `display_name`.
        [RtmpSharp("display_name")]
        public string Name;

        // this field does not have any annotations, but because it is a public field, it will still be serialized.
        public byte[] Hash;

        // this attribute directs `rtmp-sharp` to ignore this field: it will not be considered during serialization and
        // deserialization.
        [RtmpIgnore]
        public int State;
    }
}

About

a fast and lightweight data-oriented rtmp(s) client library. now with .net core support.

Resources

License

Stars

Watchers

Forks

Packages

No packages published