npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ngx-sails-socketio

v0.1.3

Published

An Angular module for connecting SailsJs backend through SocketIO.

Downloads

17

Readme

ngx-sails-socketio

npm version Build Status Coverage Status

An Angular module for connecting to your SailsJs Backend/API through SocketIO.

Installation

npm i ngx-sails-socketio

Usage

Add SailsModule to your application module.

// Override options to configure connection to your sailsjs backend
const options: SailsOptions = {
   url: "ws://127.0.0.1:1337",
   prefix: "/api", // Optional uri prefix
   environment: SailsEnvironment.DEV,
   query: "__sails_io_sdk_version=0.11.0&__sails_io_sdk_platform=windows&__sails_io_sdk_language=javascript",
   reconnection: true,
   autoConnect: false
};

@NgModule({
 declarations: [
   AppComponent
 ],
 imports: [
   SailsModule.forRoot(options, [AuthInterceptor,])
   ...
 ],
 providers: [],
 bootstrap: [AppComponent]
})

export class AppModule { }

An implementation of the AuthInterceptor class

@Injectable()
export class AuthInterceptor implements SailsInterceptorInterface {

   constructor(private router: Router, private jobs: JobsService) {
   }

   intercept(request: SailsRequestOptions, next: SailsInterceptorHandlerInterface): Observable<SailsResponse> {
       request.clone({
           headers: request.headers.set("Authorization", [token]) // Replace [token] with your auth token
       });
       const response = next.handle(request);

       return response.map(res => {
           if (res.getStatusCode() === 401) {
             // handle unauthorised request.
           }
           return res;
       });
   }
}

Inject the Sails into your components/services and instatiate classes specific to your objective.

class ExampleComponent implements OnInit {

 data: any;

 constructor(private sails: SailsClient) { }

 ngOnInit() {
   const req = new SailsRequest(this.sails);
   req.get('/model/action').subscribe(res => {
     this.data = res.getBody();
   });
 }

}

API

class SailsRequest

Makes a request for a resource to the configured sails server. Has methods that maps to the various supported RESTful API verbs.

Methods

  • get(url: string): Observable<SailsResponse>
  • post(url: string, data: any): Observable<SailsResponse>
  • put(url: string, data: any): Observable<SailsResponse>
  • patch(url: string, body: any): Observable<SailsResponse>
  • delete(url: string): Observable<SailsResponse>

class SailsSubscription

A class for subscribing to resourceful Pub-Sub events emitted from a sailsjs backend.

Methods

  • on(eventName: string): Observable<SailsEvent>
  • off(eventName: string): Observable<SailsEvent>

Example(s)

Under construction

class SailsEvent

A class representing an event on a resource from the server. This follows the structure as described in the sailsjs Pub-Sub event documentation.

class SailsQuery

A class for querying records from the server. Similar to SailsRequests but has methods mapping actions as detail on waterline api used by sailsjs.

interface SailsInterceptorInterface

An interface to construct an iterceptor to use for requests.

Example(s)

An authentication interceptor to set the Authorization header on every request.

@Injectable()
export class AuthInterceptor implements SailsInterceptorInterface {

    constructor(private router: Router) {
    }

    intercept(request: SailsRequestOptions, next: SailsInterceptorHandlerInterface): Promise<SailsResponse> {
        request.clone({
            headers: request.headers.set("Authorization", token)
        });
        
        const response = next.handle(request);

        return response.then(res => {
            if (res.getStatusCode() === 401) {
                this.router.navigateByUrl("login");
            }
            return res;
        });
    }
}