xbmc_jsonrpc

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2014 License: MIT Imports: 9 Imported by: 0

README

xbmc_jsonrpc

GoDoc License-MIT

import "github.com/StreamBoat/xbmc_jsonrpc"

Package xbmc_jsonrpc provides an interface for communicating with an XBMC server via the raw JSON-RPC socket

Extracted from the xbmc-callback-daemon.

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

Usage

const (
	VERSION = `0.0.1`

	// Minimum XBMC API version
	XBMC_MIN_VERSION = 6

	// Logger properties
	LOG_FORMAT = `[%{color}%{level}%{color:reset}] %{message}`
	LOG_MODULE = `xbmc_jsonrpc`
)
func SetLogLevel
func SetLogLevel(level string) error

SetLogLevel adjusts the level of logger output

type Connection
type Connection struct {
	Notifications chan Notification
}

Main type for interacting with XBMC

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 version query is not returned 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 XBMC connection

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

Send an RPC Send to the XBMC 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).

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 XBMC 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"`
}

RPC Request type

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

RPC Response provides a reader for returning responses

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

Return the result and any errors from the response channel

Documentation

Overview

Package xbmc_jsonrpc provides an interface for communicating with an XBMC server via the raw JSON-RPC socket

Extracted from the xbmc-callback-daemon.

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

Index

Examples

Constants

View Source
const (
	VERSION = `0.0.3`

	// Minimum XBMC API version
	XBMC_MIN_VERSION = 6

	// Logger properties
	LOG_FORMAT = `[%{color}%{level}%{color:reset}] %{message}`
	LOG_MODULE = `xbmc_jsonrpc`
)

Variables

This section is empty.

Functions

func SetLogLevel

func SetLogLevel(level string) error

SetLogLevel adjusts the level of logger output

Types

type Connection

type Connection struct {
	Notifications chan Notification
	// contains filtered or unexported fields
}

Main type for interacting with XBMC

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 version query is not returned within this time.

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

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

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

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

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

if err != nil {
	panic(fmt.Sprintf(`XBMC 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 XBMC connection

func (*Connection) Send

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

Send an RPC Send to the XBMC 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).

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 XBMC 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"`
}

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
}

RPC Response provides a reader for returning responses

func (*Response) Read

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

Return the result and any errors from the response channel

Jump to

Keyboard shortcuts

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