GithubHelp home page GithubHelp logo

josesaribeiro / lyre Goto Github PK

View Code? Open in Web Editor NEW

This project forked from alexwiese/lyre

0.0 0.0 1.0 18 KB

Chrome Native Messaging implementation for .NET and .NET Core

License: MIT License

JavaScript 28.51% HTML 5.96% C# 65.53%

lyre's Introduction

Lyre

Chrome Native Messaging implementation for .NET and .NET Core. Allows easy communication with a Chrome extension using Chrome Native Messaging protocol.

Usage

var host = new NativeMessagingHost();

try
{
    while (true)
    {
        var response = await host.Read<dynamic>();

        // Echo response
        await host.Write(new { value = $"You said {response.value} at {response.dateTime}", dateTime = DateTime.Now });
    }
}
catch (EndOfStreamException)
{
    // Disconnected
}

Example/Chrome Extension

See https://github.com/alexwiese/Lyre/tree/master/src/Lyre.ConsoleTest for an example of a Chrome extension communicating with a Native Messaging Host.

Customization

The NativeMessagingHost uses JSON.NET for serialization. This can be customized by passing in a JsonSerializerSettings object. The Encoding and Stream objects used for communications can also be passed into the constructor.

var host = new NativeMessagingHost(Console.OpenStandardInput(), Console.OpenStandardOutput(), Encoding.UTF8, new JsonSerializerSettings{ Formatting = Formatting.None});

Supressing Console Output

By default Chrome Native Messaging uses stdin and stdout to communicate. If any other code writes to the Console, for example by calling Console.WriteLine(string), then this would cause the Chrome Native Messaging pipe to fail due to unexpected output. Helper methods are provided by the NativeMessagingEnvironment class to supress or redirect the Console output.

Supress console output

// Redirects any calls to Console.Write() or Console.WriteLine() to TextWriter.Null
NativeMessagingEnvironment.SupressConsoleOutput();

Redirect to stderr

// This will redirect calls to Console.Write() and Console.WriteLine() to stderr
NativeMessagingEnvironment.RedirectConsoleOutputToErrorOutput();

Redirect to Debug output

// Redirects any calls to Console.Write() or Console.WriteLine() to the Debug output
NativeMessagingEnvironment.RedirectConsoleOutputToDebugStream();

Redirect to a TextWriter

// This will redirect calls to Console.Write() and Console.WriteLine() to a file
var writer = new StreamWriter(File.OpenWrite("console.out")) { AutoFlush = true };
NativeMessagingEnvironment.RedirectConsoleOutput(writer);

lyre's People

Contributors

alexwiese avatar

Forkers

weiderson

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.