kodi_jsonrpc

package module
v2.0.6+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 9, 2016 License: MIT Imports: 10 Imported by: 0

README

DEPRECATED

This package is no longer maintained, please consider migrating to github.com/pdf/kodirpc

kodi_jsonrpc

GoDoc License-MIT

import "github.com/StreamBoat/kodi_jsonrpc"

Package kodi_jsonrpc provides an interface for communicating with a Kodi/XBMC server via the raw JSON-RPC socket

Extracted from the kodi-callback-daemon.

Released under the terms of the MIT License (see LICENSE).

Usage

const (
	VERSION = `1.0.3`

	// Minimum Kodi/XBMC API version
	KODI_MIN_VERSION = 6

	LogDebugLevel = log.DebugLevel
	LogInfoLevel  = log.InfoLevel
	LogWarnLevel  = log.WarnLevel
	LogErrorLevel = log.ErrorLevel
	LogFatalLevel = log.FatalLevel
	LogPanicLevel = log.PanicLevel
)
func SetLogLevel
func SetLogLevel(level log.Level)

SetLogLevel adjusts the level of logger output, level must be one of:

LogDebugLevel LogInfoLevel LogWarnLevel LogErrorLevel LogFatalLevel LogPanicLevel

type Connection
type Connection struct {
	Notifications chan Notification

	Connected bool
	Closed    bool
}

Connection is the main type for interacting with Kodi

func New
func New(address string, timeout time.Duration) (conn Connection, err error)

New returns a Connection to the specified address. If timeout (seconds) is greater than zero, connection will fail if initial connection is not established within this time.

User must ensure Close() is called on returned Connection when finished with it, to avoid leaks.

func (*Connection) Close
func (c *Connection) Close()

Close closes the Kodi connection and associated channels Subsequent Sends will return an error for closed connections

func (*Connection) Send
func (c *Connection) Send(req Request, want_response bool) (res Response, err error)

Send an RPC request to the Kodi server. Returns a Response, but does not attach a channel for it if want_response is false (for fire-and-forget commands that don't return any useful response). Returns error on closed connection

type Notification
type Notification struct {
	Method string `json:"method" mapstructure:"method"`
	Params struct {
		Data struct {
			Item *struct {
				Type string `json:"type" mapstructure:"type"`
			} `json:"item" mapstructure:"item"` // Optional
		} `json:"data" mapstructure:"data"`
	} `json:"params" mapstructure:"params"`
}

Notification stores Kodi server->client notifications.

type Request
type Request struct {
	Id      *uint32                 `json:"id,omitempty"`
	Method  string                  `json:"method"`
	Params  *map[string]interface{} `json:"params,omitempty"`
	JsonRPC string                  `json:"jsonrpc"`
}

Request is the RPC request type

type Response
type Response struct {
	Pending bool // If Pending is false, Response is unwanted, or been consumed
}

Reponse provides a reader for returning RPC responses

func (*Response) Read
func (rchan *Response) Read(timeout time.Duration) (result map[string]interface{}, err error)

Read returns the result and any errors from the response channel If timeout (seconds) is greater than zero, read will fail if not returned within this time.

Documentation

Overview

Package kodi_jsonrpc provides an interface for communicating with a Kodi/XBMC server via the raw JSON-RPC socket

Extracted from the kodi-callback-daemon.

Released under the terms of the MIT License (see LICENSE).

Index

Examples

Constants

View Source
const (
	// VERSION hold the version number for this library
	VERSION = `2.0.5`

	// KODI_MIN_VERSION specifies the minimum Kodi/XBMC API version compatible
	// with this library
	KODI_MIN_VERSION = 6

	// LogDebugLevel and friends export log level constants, mapped to their
	// logrus equivalents
	LogDebugLevel = log.DebugLevel
	LogInfoLevel  = log.InfoLevel
	LogWarnLevel  = log.WarnLevel
	LogErrorLevel = log.ErrorLevel
	LogFatalLevel = log.FatalLevel
	LogPanicLevel = log.PanicLevel
)

Variables

This section is empty.

Functions

func SetLogLevel

func SetLogLevel(level log.Level)

SetLogLevel adjusts the level of logger output, level must be one of:

LogDebugLevel LogInfoLevel LogWarnLevel LogErrorLevel LogFatalLevel LogPanicLevel

Types

type Connection

type Connection struct {
	Notifications chan Notification

	Connected bool
	Closed    bool
	// contains filtered or unexported fields
}

Connection is the main type for interacting with Kodi

func New

func New(address string, timeout time.Duration) (conn Connection, err error)

New returns a Connection to the specified address. If timeout (seconds) is greater than zero, connection will fail if initial connection is not established within this time.

User must ensure Close() is called on returned Connection when finished with it, to avoid leaks.

Example
kodi, err := New(`localhost:9090`, 15) // timeout after 15 secs
defer kodi.Close()                     // always close to free resources

if err != nil {
	panic(fmt.Sprintf(`Couldn't connect to Kodi: %v`, err))
}

request := Request{Method: `JSONRPC.Version`}
response, err := kodi.Send(request, true) // second param says we need a response

if err != nil {
	panic(fmt.Sprintf(`Kodi send failed with error: %v`, err))
}

// wait indefinitely for response (timeout 0)
result, err := response.Read(0)

if err != nil {
	panic(fmt.Sprintf(`Kodi responded with error: %v`, err))
}

fmt.Println(result)
Output:

map[version:map[major:6 minor:14 patch:3]]

func (*Connection) Close

func (c *Connection) Close()

Close closes the Kodi connection and associated channels Subsequent Sends will return an error for closed connections

func (*Connection) Send

func (c *Connection) Send(req Request, wantResponse bool) (res Response, err error)

Send an RPC request to the Kodi server. Returns a Response, but does not attach a channel for it if wantResponse is false (for fire-and-forget commands that don't return any useful response). Returns error on closed connection

type Notification

type Notification struct {
	Method string `json:"method" mapstructure:"method"`
	Params struct {
		Data struct {
			Item *struct {
				Type string `json:"type" mapstructure:"type"`
			} `json:"item" mapstructure:"item"` // Optional
		} `json:"data" mapstructure:"data"`
	} `json:"params" mapstructure:"params"`
}

Notification stores Kodi server->client notifications.

type Request

type Request struct {
	Id      *uint32                 `json:"id,omitempty"`
	Method  string                  `json:"method"`
	Params  *map[string]interface{} `json:"params,omitempty"`
	JsonRPC string                  `json:"jsonrpc"`
}

Request is the RPC request type

type Response

type Response struct {
	Pending bool // If Pending is false, Response is unwanted, or been consumed
	// contains filtered or unexported fields
}

Response provides a reader for returning RPC responses

func (*Response) Read

func (rchan *Response) Read(timeout time.Duration) (result map[string]interface{}, err error)

Read returns the result and any errors from the response channel If timeout (seconds) is greater than zero, read will fail if not returned within this time.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL