ng2-django-channels-demultiplexing
Version:
Angular 2 library for interacting with a Django Channels demultiplexing backend.
66 lines (49 loc) • 1.49 kB
Markdown
# ng2-django-channels-demultiplexing
## Installation
To install this library, run:
```bash
$ npm install ng2-django-channels-demultiplexing --save
```
## Usage
Sample Angular `AppModule`:
```typescript
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
// Import library
import { Ng2DjangoChannelsDemultiplexingModule } from 'ng2-django-channels-demultiplexing';
export class AppModule { }
```
Once imported, you can use WebSocketDemultiplexingService in your Angular application:
```typescript
import { Injectable } from '@angular/core';
import { Demultiplexing, WebSocketDemultiplexingService } from 'ng2-django-channels-demultiplexing';
export class SomeService {
constructor(private webSocketDemultiplexerService: WebSocketDemultiplexerService) {
this.webSocketDemultiplexerService.subscribe('some_stream', (payload: Object) => {
...
});
}
sendData(stream: string, data: Object): void {
this.webSocketDemultiplexerService.sendData(
stream,
data
);
}
}
```
## License
MIT © [Fabian Schaffert](mailto:fabian@schaffert.cc)