Home Reference Source Repository
import Kodi from 'kodi-socket/src/index.js'
public class | source

Kodi

Kodi/XBMC class exposes JSON-RPC API and notifications

Example:

let kodi = new Kodi({ host, port, connectImmediately: true })
kodi.api.Player.PlayPause();
kodi.api.VideoLibrary.GetMovies().then(movies => ... );

Static Method Summary

Static Public Methods
public static

createKodiUrl(host: *, port: *): *

Constructor Summary

Public Constructor
public

constructor(config: Object)

Constructor takes an configuration object where you specify the host and TCP port for your Kodi/XBMC instance.

Member Summary

Public Members
public

api: *

public get
public

host: *

public
public
public
public

port: *

public

socket: *

public

url: *

public

waiting: *

Method Summary

Public Methods
public

connect(): *

Establish web socket connection and clear any existing API.

public

execute(method: string, params: Object): Promise<object, error>

Execute an arbitrary Kodi/XBMC JSON-RPC method over web socket.

public

off(method: string, fn: function): *

Unsubscribe for notifications from Kodi/XBMC connection.

public

on(method: string, fn: function): *

Subscribe for notifications from Kodi/XBMC connection.

public

once(method: string, fn: function): *

Subscribe to a notification from Kodi/XBMC connection one time

public

setUrl(host: string, port: string): *

Set the host and port

Static Public Methods

public static createKodiUrl(host: *, port: *): * source

Params:

NameTypeAttributeDescription
host *
port *

Return:

*

Public Constructors

public constructor(config: Object) source

Constructor takes an configuration object where you specify the host and TCP port for your Kodi/XBMC instance.

Params:

NameTypeAttributeDescription
config Object

Configuration object

config.host String
  • optional
  • default: "localhost"

Kodi/XBMC Hos

config.port String
  • optional
  • default: "9999"

Kodi/XBMC TCP Port

config.connectImmediately boolean
  • optional
  • default: true

Automatically establish connection or not. If false will wait for manual Kodi#connect call.

Public Members

public api: * source

public get connected: boolean source

public host: * source

public lastError: * source

public listeners: * source

public messageId: number source

public port: * source

public socket: * source

public url: * source

public waiting: * source

Public Methods

public connect(): * source

Establish web socket connection and clear any existing API.

Return:

*

public execute(method: string, params: Object): Promise<object, error> source

Execute an arbitrary Kodi/XBMC JSON-RPC method over web socket.

Params:

NameTypeAttributeDescription
method string

The method to invoke

params Object

The params for the command (see individual method documentation)

Return:

Promise<object, error>

Promise resolving with JSON-RPC result value or rejecting with JSON-RPC error value.

See:

public off(method: string, fn: function): * source

Unsubscribe for notifications from Kodi/XBMC connection. Also applies for three websocket events 'open', 'error', and 'close'.

Params:

NameTypeAttributeDescription
method string

Method name

fn function

The callback to be removed.

Return:

*

this

See:

public on(method: string, fn: function): * source

Subscribe for notifications from Kodi/XBMC connection. Can also subscribe to three websocket events 'open', 'error', and 'close'.

Params:

NameTypeAttributeDescription
method string

Method name

fn function

The callback to be called.

Return:

*

this

See:

public once(method: string, fn: function): * source

Subscribe to a notification from Kodi/XBMC connection one time

Params:

NameTypeAttributeDescription
method string

Method name

fn function

The callback to be called.

Return:

*

this

See:

public setUrl(host: string, port: string): * source

Set the host and port

Params:

NameTypeAttributeDescription
host string
  • optional
  • default: "Existing

host"] - Kodi/XBMC host

port string
  • optional
  • default: "Existing

port"] - Kodi/XBMC port

Return:

*