Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/s-r-x/phx-wildcard
Wildcard support for phoenix channels
https://github.com/s-r-x/phx-wildcard
phoenix phx websocket websockets wildcard
Last synced: about 21 hours ago
JSON representation
Wildcard support for phoenix channels
- Host: GitHub
- URL: https://github.com/s-r-x/phx-wildcard
- Owner: s-r-x
- Created: 2020-12-08T14:25:44.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2022-04-20T04:23:12.000Z (over 2 years ago)
- Last Synced: 2024-12-09T18:56:56.355Z (14 days ago)
- Topics: phoenix, phx, websocket, websockets, wildcard
- Language: TypeScript
- Homepage:
- Size: 226 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# phx-wildcard
Wildcard support for phoenix channels
## Installation
```sh
npm i phx-wildcard
```## Usage
```typescript
import { Socket } from 'phoenix';
import { Wildcard } from 'phx-wildcard';const socket = new Socket('url');
socket.connect();
const ch = socket.channel('ch');
ch.join();// phx-wildcard mutates channel's onMessage property(but saves the old one),
// so if you need to rewrite onMessage(for logging or whatever)
// do your thing before creating a wildcard instance
const wc = new Wildcard(ch);
const cb1 = (e: string, payload: any) => {});
const cb2 = (e: string, payload: any) => {});
// any pattern supported by Matcher(https://github.com/sindresorhus/matcher)
wc.on('*', cb1);
wc.on(['event-*', '*-123'], cb2);
wc.off('*', cb1);
wc.off(['event-*', '*-123'], cb2);
wc.destroy();
```