https://github.com/harunurhan/rx-socket.io-client
rxjs powered socket.io-client wrapper
https://github.com/harunurhan/rx-socket.io-client
reactivex rxjs socket-io socket-io-client typescript
Last synced: about 1 year ago
JSON representation
rxjs powered socket.io-client wrapper
- Host: GitHub
- URL: https://github.com/harunurhan/rx-socket.io-client
- Owner: harunurhan
- Created: 2018-01-22T23:10:38.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2023-02-27T15:30:00.000Z (over 3 years ago)
- Last Synced: 2025-04-12T23:13:58.289Z (about 1 year ago)
- Topics: reactivex, rxjs, socket-io, socket-io-client, typescript
- Language: TypeScript
- Size: 124 KB
- Stars: 2
- Watchers: 2
- Forks: 2
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## rx-socket.io-client
Easy to use `rxjs` powered wrapper for `socket.io-client`.
*Although current API is experimental and limited, there __won't__ be any breaking release without major release*
### Install
`npm install --save rx-socket.io-client`
Requires `socket.io-client` and `rxjs` as `peerDependency`, incase you don't have them also run:
`npm install --save socket.io-client rxjs`
### Use
```typescript
import { RxSocket } from 'rx-socket.io-client';
const socket = new RxSocket('/url/to/socket.io/server'); // javascript
const event$ = socket.subject('event_name'); // get rxjs/Subject for a specific event
event$.subscribe((data) => { // read data
console.log(data.foo)
});
event$.next({foo: 'bar'}); // send data
// create observables for events that you want to only listen (receive data)
const event$ = socket.observable('event_name'); // get rxjs/Observable for a specific event
event$.subscribe((data) => { // read data
console.log(data.foo)
});
```
### Generics
If you are using typescript, it's best to use generic types
```typescript
// all observables and subject that are generated will emit/subscribe an object with string `foo` property
const socket = new RxSocket<{ foo: strig }>('/url/to/socket.io/server');
// unless type is given to the class methods when they are called.
// like below:
socket.subject('event_name');
socket.observable('event_name');
```
[See tests for more detailed and up to date examples](./src/index.spec.ts)