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

murysock

v0.0.6

Published

Murysock is a framework to create your own client websocket applications that interact with servers using the Event-Message architecture with few decorators.

Downloads

15

Readme

Getting started into Murysock!

  1. @WebSockClient()
  2. @WebSockConnected()
  3. @WebSockGateway([address])
  4. @WebSockData()
  5. @WebSockDisconnected()
  6. @WebSockError()
  7. @WebSockEvent([eventname])
  8. @WebSockException()
  9. @WebSockInjectClient()

Each event is automatically routed to its respective handler, as long as the message payload received via the websocket is in the following JSON format:

{
  "event": "[event-name]",
  "data": "[event-data]"
}

Installation

npm install murysock --save

How to use?

The first thing to do to create your gateway and interact with a server that supports event-driven websocket is to create a class and annotate it with @WebSockGateway, then add at least one event method annotated by @WebSockEvent. After create the class, you need call websockConnect to start the lifecycle of your gateway.

In Murysock, the lifecycle of a WebSocket connection is regulated by 4 decorators, they are: @WebSockConnected, @WebSockDisconnected, @WebSockError, @WebSockException. Whenever the connection is successfully established, the method decorated with @WebSockConnected is invoked, just as when the connection is terminated the method decorated with @WebSockDisconnected is invoked. In Murysock there are 2 types of exceptions, those caused by network failures and those caused by application code failures. These are handled by methods decorated with @WebSockError and @WebSockException respectively.

To send a response in each event you can use the reply function and specify a remote event name and the data to be sent. You can call the reply function more than one time in an event.

For a more detailed overview see the example of integration below using a Gateway to receive events:

import { 
  reply, 
  websockConnect, 
  WebSocket,
  WebSockClient, 
  WebSockConnected, 
  WebSockGateway, 
  WebSockData, 
  WebSockDisconnected, 
  WebSockError, 
  WebSockEvent, 
  WebSockException, 
  WebSockInjectClient 
} from 'murysock';

@WebSockGateway('ws://localhost')
export class Gateway {

  @WebSockInjectClient()
  public clientSock?: WebSocket;

  @WebSockEvent('message')
  async onMessage(
    @WebSockClient() client: WebSocket,
    @WebSockData() data: any)
  {
    return reply('broadcast', { hello: 'world' });
  }

  @WebSockEvent('broadcast')
  onBroadcast(
    @WebSockData() data: any)
  {
    console.log('broadcast', data)
  }

  @WebSockConnected()
  onConnect(evt: any)
  {
    console.log('connected')
  }

  @WebSockDisconnected()
  onDisconnect(evt: any)
  {
    console.log('disconnected')
  }

  @WebSockError()
  onError(error: any)
  {
    console.log('error')
  }

  @WebSockException()
  onException(exception: Error)
  {
    console.log('exception');
  }

}

websockConnect(Gateway);

Metadata

Muryllo Pimenta de Oliveira – [email protected]

Distributed under MIT license. See LICENSE for more informations.

Contributing

  1. Create a fork (https://github.com/MurylloEx/murysock/fork)
  2. Create a feature branch (git checkout -b feature/fooBar)
  3. Commit your changes (git commit -am 'Add some fooBar')
  4. Send a push of your commit (git push origin feature/fooBar)
  5. Open a new Pull Request