Coder Social home page Coder Social logo

github2017luo / rtmpsharp Goto Github PK

View Code? Open in Web Editor NEW

This project forked from liuyunxiong/rtmpsharp

0.0 0.0 0.0 204 KB

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

License: MIT License

Smalltalk 0.26% C# 99.74%

rtmpsharp's Introduction

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;
    }
}

rtmpsharp's People

Contributors

liuyunxiong avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.