@conclurer/web-socket
    TypeScript icon, indicating that this package has built-in type declarations

    6.8.0-beta.1 • Public • Published

    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'});
      }
    }

    Keywords

    none

    Install

    npm i @conclurer/web-socket

    DownloadsWeekly Downloads

    1

    Version

    6.8.0-beta.1

    License

    none

    Unpacked Size

    102 kB

    Total Files

    16

    Last publish

    Collaborators

    • julian_bm
    • lemonlime
    • can557
    • mc17uulm
    • unkn0wn9009
    • maehldom
    • marvinscharle