0.2.1 • Published 3 years ago

kodi-api v0.2.1

Weekly downloads
18
License
ISC
Repository
github
Last release
3 years ago

Kodi API

A complete implementation of Kodi JSON-RPC calls in an easy-to-use Javascript/TypeScript client.

Installation and usage

Available via npm:

npm install --save kodi-api

Then import or require:

import { KodiClient } from 'kodi-api'
const { KodiClient } = require('kodi-api')

async function main () {
  // Expects localhost and port 9090.
  const client = KodiClient.tcp()
  const result = await client.JSONRPC.Ping()

  console.log(result) // Expected output: 'pong'
}

main()

Documentation

Documentation for the client is available in ./docs.

Documentation for the Kodi API is available in their wiki.

How it works

First, the library makes a connection for the desired type, such as tcp. Then it dynamically caches the output from JSONRPC.Introspect. This metadata is then used to make and validate calls to Kodi's JSON-RPC api. No functions are predefined on the client class itself; the class self-mutates to conform to the metadata from JSONRPC.Introspect.

This makes it possible to use the most up-to-date API documentation available from Kodi's website, or to output the documentation by executing JSONRPC.Introspect yourself. Kodi themselves recommend the self-documenting functionality over their own wiki.

Future

Eventually, the plan is to generate TypeScript definitions from Kodi for the latest two major releases and include them in ./lib/api/<version>. The generator will also be included in the library so that types can be generated on-the-fly for use in other projects.

Why

Kodi's support today for syncing and sharing is fairly limited. This module is one leg of a strategy for a server sync based on CouchDB and the Kodi API. However, this module is fully stand-alone and only requires a running instance of Kodi to communicate with.