npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@radiolise/metadata-client

v1.0.1

Published

Library for subscribing to metadata of ICY radio streams; powered by the Radiolise API, based on WebSockets

Downloads

38

Readme

@radiolise/metadata-client

version license

Library for subscribing to metadata of ICY radio streams.
Powered by the Radiolise API, based on WebSockets.

🪶 Zero dependencies: 1.5 kiB minified
✨ Reactive: Compatible with RxJS & Co.

Usage

Example projects

If you want to use this library with a JS framework, check out the official example setups. Visit https://gitlab.com/radiolise/radiolise.gitlab.io/-/blob/master/examples to see more.

From npm

npm install @radiolise/metadata-client

Code example (pure JavaScript):

import { createMetadataClient } from '@radiolise/metadata-client'

const nowPlaying = createMetadataClient({
  // Official instance URL
  url: 'wss://backend.radiolise.com/api/data-service',
})

// Register subscription handler
const subscription = nowPlaying.subscribe(({ title, error }) => {
  if (!error) {
    console.log('new title': title)
  }
})

nowPlaying.trackStream('https://liveradio.swr.de/sw282p3/swr3/play.mp3')

From CDN

<script src="//unpkg.com/@radiolise/[email protected]"></script>
<script>
  const nowPlaying = RadioliseMetadata.createMetadataClient({ url: '...' })
</script>

You can also use the modern ESM build:

<script type="module">
  import { createMetadataClient } from '//unpkg.com/@radiolise/[email protected]/dist/index.js'
  const nowPlaying = createMetadataClient({ url: '...' })
</script>

Declarations

TypeScript definitions included.

The createMetadataClient function could be declared like this:

declare function createMetadataClient(options: {
  url: string | URL
  /** @default true */
  reconnect?: boolean
  /** @default 2000 */
  reconnectDelay?: number | undefined
  onSocketError?: (this: MetadataClient, code: number) => void
})

More actions

Unregister subscription handler

subscription.unsubscribe()

Stop tracking metadata

nowPlaying.trackStream(undefined)

To resume, just call trackStream again providing a regular stream URL.

Error handling

import { createMetadataClient, ErrorTypes } from '@radiolise/metadata-client'

const nowPlaying = createMetadataClient({ url: '...' })

nowPlaying.subscribe(({ title, error }) => {
  if (!error) {
    console.log('new title': title)
    return
  }
  switch (error) {
    case ErrorTypes.MALFORMED_PAYLOAD:
      // The API server was unable to parse the payload because something has
      // been omitted or is invalid.
      break
    case ErrorTypes.SERVER_UNREACHABLE:
      // The provided host is unreachable.
      break
    case ErrorTypes.SERVER_HTTP_ERROR:
      // The streaming server responded with an HTTP status error.
      break
    case ErrorTypes.NON_ICY_RESOURCE:
      // The resource does not appear to be an ICY audio stream.
      break
    default:
      // Other error not documented yet.
  }
})

License

MIT

Copyright (c) 2023-present Marco Bauer