https://github.com/calico32/solid-use-lanyard
SolidJS wrapper for the Lanyard API
https://github.com/calico32/solid-use-lanyard
discord javascript lanyard solid-js typescript websocket
Last synced: about 1 month ago
JSON representation
SolidJS wrapper for the Lanyard API
- Host: GitHub
- URL: https://github.com/calico32/solid-use-lanyard
- Owner: calico32
- License: mit
- Created: 2022-08-30T21:41:58.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2022-08-31T00:21:05.000Z (almost 4 years ago)
- Last Synced: 2025-03-03T23:51:18.549Z (over 1 year ago)
- Topics: discord, javascript, lanyard, solid-js, typescript, websocket
- Language: TypeScript
- Homepage:
- Size: 1.17 MB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# `solid-use-lanyard`
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() && (
{(activity) => (
{activity.name}
{activity.details}
{activity.state}
)}
)
}
```