@conclurer/web-socket
v6.8.0-beta.1
Published
This module includes `WebSocketProvider` which is used to handle web socket connections between Edelog and a server.
Downloads
2
Keywords
Readme
Web Socket Module
This module includes WebSocketProvider
which is used to handle web socket connections between Edelog and a server.
How to Use
To use this module and WebSocketProvider
you have to provide a custom implementation of WebSocketProvider
like this:
import {NgModule} from '@angular/core';
import {WebSocketProvider} from '@conclurer/web-socket';
@NgModule({
providers: [
{provide: WebSocketProvider, useClass: YourImplementation},
],
})
export class YourModule {
}
This module includes a default provider for web sockets that works with Rails's ActionCable framework.
You can use the default provider like this:
import {NgModule} from '@angular/core';
import {WebSocketModule} from '@conclurer/web-socket';
@NgModule({
imports: [
WebSocketModule.withDefaultProviders(),
],
})
export class YourModule {
}
Stream Data
To stream data, you can use the stream
function of WebSocketProvider
:
import {Component, OnInit} from '@angular/core';
import {WebSocketProvider} from '@conclurer/web-socket';
@Component()
export class YourComponent implements OnInit {
constructor(
private readonly socket: WebSocketProvider,
) {
}
public ngOnInit() {
const channel = this.socket.channel('your-channel-name');
// Subscribe to incoming messages
channel.incomingMessage$.subscribe(message => {
console.log('INCOMING MESSAGE:', message);
});
// Push messages to channel
channel.push('your-message', {optional: 'data'});
}
}