Code Monkey home page Code Monkey logo

kodirpc's Introduction

Build Status GoDoc License-MIT

kodirpc

-- import "github.com/pdf/kodirpc"

Package kodirpc is a JSON-RPC client for the TCP socket of the Kodi home theatre software.

Usage

const (
	// DefaultReadTimeout is the default time a call will wait for a response.
	DefaultReadTimeout = 5 * time.Second
	// DefaultConnectTimeout is the default time re-/connection will be
	// attempted before failure.
	DefaultConnectTimeout = 5 * time.Minute
	// DefaultReconnect determines whether the client reconnects by default.
	DefaultReconnect = true
	// DefaultConnectBackoffScale is the default back-off scaling factor
	DefaultConnectBackoffScale = 2
)

func SetLogger

func SetLogger(l LevelledLogger)

SetLogger enables logging for the library and wraps the supplied logger with a logPrefixer to denote locally generated logs

type Client

type Client struct {
	sync.RWMutex
}

Client is a TCP JSON-RPC client for Kodi.

func NewClient

func NewClient(address string, config *Config) (c *Client, err error)

NewClient connects to the specified address and returns the resulting Client.

func (*Client) Call

func (c *Client) Call(method string, params interface{}) (interface{}, error)

Call an RPC method and return the result.

func (*Client) Close

func (c *Client) Close() error

Close the client connection, not further use of the Client is permitted after this method has been called.

func (*Client) Handle

func (c *Client) Handle(method string, handler NotificationHandler)

Handle the notification method, using the specificed handler. The handler will be passed the data parameter from the incoming notification.

func (*Client) Notify

func (c *Client) Notify(method string, params interface{}) error

Notify sends the RPC request and does not wait for a response.

type Config

type Config struct {
	// ReadTimeout is the time a call will wait for a response before failure.
	ReadTimeout time.Duration
	// ConnectTimeout is the time a re-/connection will be attempted before
	// failure. A value of zero attempts indefinitely.
	ConnectTimeout time.Duration
	// Reconnect determines whether the client will attempt to reconnect on
	// connection failure
	Reconnect bool
	// ConnectBackoffScale sets the scaling factor for back-off on failed
	// connection attempts
	ConnectBackoffScale int
}

Config represents the user-configurable parameters for the client

func NewConfig

func NewConfig() (c *Config)

NewConfig returns a config instance with default values.

type Error

type Error struct {
	Code    int         `json:"code"`
	Message string      `json:"message"`
	Data    interface{} `json:"data,omitempty"`
}

Error response.

func (*Error) Error

func (e *Error) Error() string

Error satisfies the error interface.

type LevelledLogger

type LevelledLogger interface {
	// Debugf handles debug level messages
	Debugf(format string, args ...interface{})
	// Infof handles info level messages
	Infof(format string, args ...interface{})
	// Warnf handles warn level messages
	Warnf(format string, args ...interface{})
	// Errorf handles error level messages
	Errorf(format string, args ...interface{})
	// Fatalf handles fatal level messages, and must exit the application
	Fatalf(format string, args ...interface{})
	// Panicf handles debug level messages, and must panic the application
	Panicf(format string, args ...interface{})
}

LevelledLogger represents a minimal levelled logger

type NotificationHandler

type NotificationHandler func(method string, data interface{})

NotificationHandler is a callback handler for notifications.

kodirpc's People

Contributors

pdf avatar

Stargazers

 avatar open source avatar Philip avatar Mark Schumacher avatar Pushpahas Janardhan avatar Paulo Pereira avatar Aleksei Melnik avatar Janez Troha avatar Wojciech Lichota avatar Lucas Florio avatar  avatar Mikael Berthe avatar

Watchers

 avatar Mikael Berthe avatar James Cloos avatar  avatar  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.