0.0.13 • Published 2 years ago

ngx-socksjs v0.0.13

Weekly downloads
-
License
-
Repository
github
Last release
2 years ago

ngx-socksjs

SocksJS module for Angular

Description

Socket.IO inspired wrapper over Stomp Websocket for Angular.

Install

Since this is a wrapper of already existing Angular Stomp library, first install the core one:

  1. npm i @stomp/ng2-stompjs

and then the wrapper.

  1. npm install ngx-socksjs

How to use

Import and configure SocksJSModule

import { SocksJSModule } from 'ngx-socksjs';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    SocksJSModule.forRoot({ url: 'ws://<domain>:<port>/<server_endpoint>', options: {} })
  ],
  providers: [],
  bootstrap: [ AppComponent ]
})
export class AppModule { }

We need to configure SocksJSModule module using the object config of type SocksConfig.

Now we pass the configuration to the static method forRoot of SocksJSModule

Using your SocksJS Instance

The SocksJSModule provides now a configured Socket service that can be injected anywhere inside the AppModule.

import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { SocksJS } from 'ngx-socksjs';

@Injectable({ providedIn: 'root' })
export class SocketService {

  constructor(
    private socksJS: SocksJS
  ) { }

  onEvent(): Observable<any> {
    return this.socksJS.fromEvent<any>('/receive');
  }

  send(payload: any): void {
    this.socksJS.emit('/send', payload);
  }
}

API

Most of the functionalities here you are already familiar with.

The only addition is the fromEvent method, which returns an Observable that you can subscribe to.

socksJS.emit(eventName: string, payload: any): void

Sends a message to the server. Works the same as in Socket.IO.

socksJS.fromEvent<T>(eventName: string): Observable<T>

Takes an event name and returns an Observable that you can subscribe to.

LICENSE

MIT

0.0.13

2 years ago

0.0.12

2 years ago

0.0.11

2 years ago

0.0.10

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago