6.8.0-beta.1 • Published 3 years ago

@conclurer/message-stream v6.8.0-beta.1

Weekly downloads
-
License
-
Repository
-
Last release
3 years ago

Message Stream

How to Use

To use the MessageStreamService, you have to provide it in your component or module first.

import {Component} from '@angular/core';
import {MessageStreamService} from '@conclurer/message-stream';

@Component({
  providers: [
    MessageStreamService,
  ],
})
export class YourComponent {
}

MessageStreamService allows you to create one or more streams for objects. After the stream is initialized, you can listen to events or emit new messages:

import {MessageStreamService} from '@conclurer/message-stream';

export class YourComponent {
  constructor(
    private readonly messageStream: MessageStreamService,
  ) {
    const stream = this.messageStream.streamFor('YOUR OBJECT UUID');

    // Subscribes to all messages
    stream.message$.subscribe();

    // Subscribes to the ids of all subscribers of the same object
    stream.activeSubscriberIds$.subscribe();

    // Emits the given data to the server and therefor all subscribers of this object.
    stream.emit({your: 'data'});
  }
}