Gathering detailed insights and metrics for @helveg/ngx-socket-io
Gathering detailed insights and metrics for @helveg/ngx-socket-io
npm install @helveg/ngx-socket-io
Typescript
Module System
Node Version
NPM Version
65.2
Supply Chain
93.1
Quality
74.7
Maintenance
100
Vulnerability
98.9
License
TypeScript (100%)
Love this project? Help keep it running — sponsor us today! 🚀
Total Downloads
556
Last Day
2
Last Week
6
Last Month
26
Last Year
114
MIT License
264 Stars
170 Commits
91 Forks
18 Watchers
1 Branches
25 Contributors
Updated on Feb 09, 2025
Minified
Minified + Gzipped
Latest Version
1.1.1
Package Id
@helveg/ngx-socket-io@1.1.1
Unpacked Size
55.42 kB
Size
14.23 kB
File Count
17
NPM Version
8.3.1
Node Version
16.13.2
Cumulative downloads
Total Downloads
Last Day
0%
2
Compared to previous day
Last Week
-14.3%
6
Compared to previous week
Last Month
100%
26
Compared to previous month
Last Year
-30.9%
114
Compared to previous year
3
Socket.IO module for Angular
npm install ngx-socket-io
Important:
Make sure you're using the proper corresponding version of socket.io on the server.
Package Version | Socket-io Server Version |
---|---|
v3.4.0 | v2.2.0 |
v4.1.0 | v4.0.0 |
1import { SocketIoModule, SocketIoConfig } from 'ngx-socket-io'; 2 3const config: SocketIoConfig = { url: 'http://localhost:8988', options: {} }; 4 5@NgModule({ 6 declarations: [AppComponent], 7 imports: [BrowserModule, SocketIoModule.forRoot(config)], 8 providers: [], 9 bootstrap: [AppComponent], 10}) 11export class AppModule {}
We need to configure SocketIoModule
module using the object config
of type SocketIoConfig
, this object accepts two optional properties they are the same used here io(url[, options]).
Now we pass the configuration to the static method forRoot
of SocketIoModule
The SocketIoModule
provides now a configured Socket
service that can be injected anywhere inside the AppModule
.
1import { Injectable } from '@angular/core'; 2import { Socket } from 'ngx-socket-io'; 3import { map } from 'rxjs/operators'; 4 5@Injectable() 6export class ChatService { 7 constructor(private socket: Socket) {} 8 9 sendMessage(msg: string) { 10 this.socket.emit('message', msg); 11 } 12 getMessage() { 13 return this.socket.fromEvent('message').pipe(map((data) => data.msg)); 14 } 15}
In this case we do not configure the SocketIoModule
directly using forRoot
. What we have to do is: extend the Socket
service, and call super()
with the SocketIoConfig
object type (passing url
& options
if any).
1import { Injectable, NgModule } from '@angular/core'; 2import { Socket } from 'ngx-socket-io'; 3 4@Injectable() 5export class SocketOne extends Socket { 6 constructor() { 7 super({ url: 'http://url_one:portOne', options: {} }); 8 } 9} 10 11@Injectable() 12export class SocketTwo extends Socket { 13 constructor() { 14 super({ url: 'http://url_two:portTwo', options: {} }); 15 } 16} 17 18@NgModule({ 19 declarations: [ 20 //components 21 ], 22 imports: [ 23 SocketIoModule, 24 //... 25 ], 26 providers: [SocketOne, SocketTwo], 27 bootstrap: [ 28 /** AppComponent **/ 29 ], 30}) 31export class AppModule {}
Now you can inject SocketOne
, SocketTwo
in any other services and / or components.
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.
socket.of(namespace: string)
Takes an namespace. Works the same as in Socket.IO.
socket.on(eventName: string, callback: Function)
Takes an event name and callback. Works the same as in Socket.IO.
socket.removeListener(eventName: string, callback?: Function)
Takes an event name and callback. Works the same as in Socket.IO.
socket.removeAllListeners(eventName?: string)
Takes an event name. Works the same as in Socket.IO.
socket.emit(eventName:string, ...args: any[])
Sends a message to the server. Works the same as in Socket.IO.
socket.fromEvent<T>(eventName: string): Observable<T>
Takes an event name and returns an Observable that you can subscribe to.
socket.fromEventOnce<T>(eventName: string): Promise<T>
Creates a Promise for a one-time event.
You should keep a reference to the Observable subscription and unsubscribe when you're done with it.
This prevents memory leaks as the event listener attached will be removed (using socket.removeListener
) ONLY and when/if you unsubscribe.
If you have multiple subscriptions to an Observable only the last unsubscription will remove the listener.
For error TS2345
you need to add this to your tsconfig.json
.
1{ 2 ... 3 "compilerOptions": { 4 ... 5 "paths": { 6 "rxjs": ["node_modules/rxjs"] 7 } 8 }, 9}
MIT
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
1 existing vulnerabilities detected
Details
Reason
7 commit(s) and 1 issue activity found in the last 90 days -- score normalized to 6
Reason
Found 6/22 approved changesets -- score normalized to 2
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
security policy file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-02-03
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More