Socket
Socket
Sign inDemoInstall

ngx-socksjs

Package Overview
Dependencies
9
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    ngx-socksjs

Easy to use, plug and play type of Stomp Websocket for Angular based on (ng2-stompjs).


Version published
Weekly downloads
9
decreased by-25%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

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

Keywords

FAQs

Last updated on 09 Jan 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc