# crosswalk-channels

> A crosswalk shared module to send data to clients

Latest version **0.1.3** (published 2024-05-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install crosswalk-channels
pnpm add crosswalk-channels
yarn add crosswalk-channels
bun add crosswalk-channels
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.3 |
| Published | 2024-05-15 |
| First published | 2023-11-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 29.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | jeparlefrancais <jeparlefrancais21@gmail.com> |
| Maintainers | jeparlefrancais |
| Keywords | luau, roblox, crosswalk |

## Links

- npm: https://www.npmjs.com/package/crosswalk-channels
- Repository: https://github.com/seaofvoices/crosswalk-channels
- Homepage: https://github.com/seaofvoices/crosswalk-channels#readme
- npm.io page: https://npm.io/package/crosswalk-channels

## Dependencies (2)

- [luau-signal](https://npm.io/package/luau-signal.md) ^0.1.0
- [luau-teardown](https://npm.io/package/luau-teardown.md) ^0.1.4

## Recent versions

- 0.1.3 (latest) — 2024-05-15
- 0.1.2 — 2024-03-17
- 0.1.1 — 2024-01-22
- 0.1.0 — 2023-11-15

## README

[![checks](https://github.com/seaofvoices/crosswalk-channels/actions/workflows/test.yml/badge.svg)](https://github.com/seaofvoices/crosswalk-channels/actions/workflows/test.yml)
![version](https://img.shields.io/github/package-json/v/seaofvoices/crosswalk-channels)
[![GitHub top language](https://img.shields.io/github/languages/top/seaofvoices/crosswalk-channels)](https://github.com/luau-lang/luau)
![license](https://img.shields.io/npm/l/crosswalk-channels)
![npm](https://img.shields.io/npm/dt/crosswalk-channels)

# Channels

A crosswalk shared module to easily send data **one way** from the server to client(s). Values can be sent to individual players or to all players.

**IMPORTANT**

This module will make use of `PlayerGui` to store instances, so to prevent them from being deleted when the character reloads, you must disable the `ResetPlayerGuiOnSpawn` property of `StarterGui`. Disable this property by running this line in the command bar:

```lua
game.StarterGui.ResetPlayerGuiOnSpawn = false
```

# Installation

## Using the npm package

Add `crosswalk-channels` in your dependencies:

```bash
yarn add crosswalk-channels
```

Or if you are using `npm`:

```bash
npm install crosswalk-channels
```

## Roblox asset

Put the Channels.rbxm file inside your crosswalk **shared modules** folder.

# License

This plugin for crosswalk is available under the MIT license. See [LICENSE.txt](LICENSE.txt) for details.

# API

## Server API

### Send

Publish values on a channel that any player can listen to.

```lua
Channels.Send(channelName: string, value: unknown)
```

### SendLocal

Publish values on a channel **for a single player**.

```lua
Channels.SendLocal(player: Player, channelName: string, value: unknown)
```

### Bind

Listen for changes on a channel (using `Channels.Send`).

```lua
Bind<T>(channelName: string, func: (T) -> ()): () -> ()
```

- Listen to data sent on global signals (sent to all players with `Send`).
- The returned function disconnects from the channel

### BindPlayer

Listen for changes on a local channel (using `Channels.SendLocal`).

```lua
BindPlayer<T>(channelName: string, func: (Player, T) -> ()): () -> ()
```

- Listen to data sent on local signals (sent to individual players with `SendLocal`).
- The returned function disconnects from the channel


## Client API

### Bind

Listen for changes on a channel.

```lua
Bind<T>(channelName: string, func: (T) -> ()): () -> ()
```

- Each client can connect to values that are sent to its own player or to all players.
- The returned function disconnects from the channel

```lua
local disconnect = Channels.Bind("timer", function(newValue)

end)

-- ... when needed, you can disconnect the callback by calling the `disconnect` function

disconnect()
```

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