# @y-presence/client

> Easy way to add presence (live cursors/avatars) to your multiplayer application using Yjs

Latest version **2.0.1** (published 2022-07-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install @y-presence/client
pnpm add @y-presence/client
yarn add @y-presence/client
bun add @y-presence/client
```

## Health

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

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.1 |
| Published | 2022-07-27 |
| First published | 2022-04-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 11.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 194 |
| Author | @nimeshnayaju |
| Maintainers | nimeshnayaju |
| Keywords | yjs, presence, cursors, avatars, multiplayer, typescript |

## Links

- npm: https://www.npmjs.com/package/@y-presence/client
- Repository: https://github.com/nimeshnayaju/y-presence
- Homepage: https://github.com/nimeshnayaju/y-presence#readme
- Issues: https://github.com/nimeshnayaju/y-presence/issues
- npm.io page: https://npm.io/package/@y-presence/client

## Dependencies (2)

- [y-webrtc](https://npm.io/package/y-webrtc.md) ^10.2.3
- [y-websocket](https://npm.io/package/y-websocket.md) ^1.4.3

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 2.0.1 (latest) — 2022-07-27
- 2.0.0 — 2022-05-27
- 1.1.8 — 2022-04-26
- 1.1.7 — 2022-04-20
- 1.1.6 — 2022-04-16
- 1.1.5 — 2022-04-08
- 1.1.4 — 2022-04-08

## README

# @y-presence/client

Add presence (live cursors/avatars) to any web application.

## Codesandbox demo/examples

### Vue.js

- Simple room: [Demo](https://2knp0l.sse.codesandbox.io/) | [Code](https://codesandbox.io/s/2knp0l)

### Svelte

- Multiplayer avatars: [Demo](https://t7llhs.csb.app/) | [Code](https://codesandbox.io/s/t7llhs)
- Simple room: [Demo](https://7qsg6f.csb.app/) | [Code](https://codesandbox.io/s/7qsg6f)

### Other examples/integrations:

- tldraw: [Demo](https://opuwd.csb.app/) | [Code](https://codesandbox.io/s/opuwd)

[![Edit y-presence](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/t7llhs)

## Installation

```bash
yarn add @y-presence/client
# or
npm i @y-presence/client
```

## Usage

This library exposes a `Room` object which wraps the provider's awareness to provide helper methods to listen to changes in self presence, other users' presence and all users' presence.

```ts
// Define your presence object here
interface AppPresence {
  name: string
  color: string
}

// Define your initial app presence
const initialPresence: AppPresence = { name: 'John Doe', color: 'Blue' }

const room = new Room<AppPresence>(provider.awareness, initialPresence)

// listen to changes in all users' presence
room.subscribe('users', (users) => {
  // do something
})

// listen to changes in other users' presence
room.subscribe('others', (others) => {
  // do something
})

// listen to changes in self presence
room.subscribe('self', (user) => {
  // do something
})

// Updates only the color of the current user's presence object
room.updatePresence({ color: 'Red' })

// Overrides the entire presence objecct of the current user in a single transaction
room.setPresence({ name: 'Jane Doe', color: 'red' })
```

### License

This project is licensed under MIT.

## Author

- [@nayajunimesh](https://twitter.com/nayajunimesh)

---
_Source: https://npm.io/package/@y-presence/client · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
