# solid-use-lanyard

> SolidJS wrapper for the Lanyard API

Latest version **1.0.3** (published 2022-08-31) · MIT license · 0 weekly downloads

## Install

```sh
npm install solid-use-lanyard
pnpm add solid-use-lanyard
yarn add solid-use-lanyard
bun add solid-use-lanyard
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2022-08-31 |
| First published | 2022-08-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 51.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | wiisportsresort |
| Maintainers | wiisportsresorts |
| Keywords | solid, solid-js, typescript, lanyard, websocket, discord |

## Links

- npm: https://www.npmjs.com/package/solid-use-lanyard
- Repository: https://github.com/wiisportsresort/solid-use-lanyard
- npm.io page: https://npm.io/package/solid-use-lanyard

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 1.0.3 (latest) — 2022-08-31
- 1.0.2 — 2022-08-31
- 1.0.1 — 2022-08-30
- 1.0.0 — 2022-08-30

## README

# `solid-use-lanyard`

<p>
  <a href="https://www.npmjs.com/package/solid-use-lanyard">
    <img src="https://img.shields.io/npm/v/solid-use-lanyard">
    <img src="https://img.shields.io/bundlephobia/min/solid-use-lanyard">
  </a>
</p>


A SolidJS wrapper around the [Lanyard](https://github.com/Phineas/lanyard) API. Supports both REST and WebSocket modes, and includes full support for TypeScript.



## Installation

```bash
yarn add solid-use-lanyard
npm install solid-use-lanyard
```

## Usage

```jsx
import useLanyard, { appAssetUrl, userAvatarUrl } from 'solid-use-lanyard'

const Component = () => {
  // Default: WebSocket API
  const presence = useLanyard('user_id')
  // presence: () => Presence | undefined

  // Advanced properties
  const { presence, close, closed } = useLanyard('user_id')
  // equivalent to:
  const { presence, close, closed } = useLanyard({ type: 'socket', id: 'user_id' })
  // presence: () => Presence | undefined
  // close: () => void
  // closed: () => boolean

  // Multiple users
  const { presence, close, closed, latestUpdate } = useLanyard({ type: 'socket', ids: ['user_id1', 'user_id2'] })
  // All users
  const { presence, close, closed, latestUpdate } = useLanyard({ type: 'socket', all: true })
  // presence: () => { [id: string]: Presence }
  // close: () => void
  // closed: () => boolean
  // latestUpdate: () => Presence & { user_id: string }

  // The WebSocket client will automatically reconnect if the connection is lost


  // REST API (single API call only)
  const presence = useLanyard({ type: 'rest', id: 'user_id' })
  // presence: () => Presence | undefined

  // REST with auto-refresh
  const presence = useLanyard({ type: 'rest', id: 'user_id', refreshInterval: 1000 /* ms */ })
  // presence: () => Presence | undefined
  
  // Advanced properties
  const { presence, cancel } = useLanyard({ type: 'rest', id: 'user_id', refreshInterval: 1000 /* ms */ })
  // presence: () => Presence | undefined
  // cancel: () => void


  // Helpers
  const avatar = userAvatarUrl('user_id', 'webp' | 'png' | 'jpg' | 'jpeg' | 'gif') // default: 'webp'
  // avatar: string

  const asset = appAssetUrl(activity.application_id, activity.assets?.large_image, 'webp' | 'png' | 'jpg' | 'jpeg' | 'gif') // default: 'webp'
  // asset: string

  // (easily make these reactive by wrapping them in a function)


  // Example single-user component:
  return presence() && (
    <For each={presence().activities}>
      {(activity) => (
        <div>
          <img src={appAssetUrl(activity.application_id, activity.assets?.large_image)} />
          <h1>{activity.name}</h1>
          <p>{activity.details}</p>
          <p>{activity.state}</p>
        </div>
      )}
    </For>
  )
}
```

---
_Source: https://npm.io/package/solid-use-lanyard · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
