Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ngx-socksjs

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

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).

  • 0.0.13
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
10
increased by150%
Maintainers
1
Weekly downloads
 
Created
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

Package last updated on 09 Jan 2022

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc