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

sockly

v0.1.1

Published

Sockly is the easiest way to work with WebSockets or a WebRTC data channel.

Downloads

12

Readme

sockly 🧦

Sockly is the easiest way to work with an API over WebSockets or a WebRTC data channel.

Instead of endless message passing, you expose a function or object at one end. At the other end of the connection you simply call the function or use the object properties and mehods.

For example, using a WebSocket, on the server you would:

const calculator = {
  name: 'Awesome calculator',
  add(a, b) {
    return a + b;
  },
  subtract(a, b) {
    return a - b;
  }
};
sockly.expose(calculator, webSocket);

On the client, simply call that calculator

const calculator = sockly.link(webSocket);
await calculator.add(4, 6);       // 10
await calculator.subtract(6, 4);  // 2
await calculator.name;            // Awesome calculator

Use Cases

Any time you use WebSockets or RTCDataChannel for p2p applications on the web (Chat app, games, etc).

Yes, one could manually add message handling easily, but it gets really annoying to maintain as more API is added over the socket.

It's just easier to add the new API method and just call it from the client without making any other changes!

Note: Sockly does not deal with creation/connection/lifecycle of WebSockets or WebRTC channels.

Install

Install from npm:

npm install --save sockly

ES6 import:

import {link, expose} from 'sockly'

Or using pika in the browser

import * as sockly from 'https://cdn.pika.dev/sockly';

Usage

expose a function or an object

and then link the exposed object at the other end.

Examples

See the live version of the calculator example above:

Socket server code

Client code

How does it work

Sockly creates a Proxy when you link a connection. This proxy intercepts property gets/sets, and method calls. The proxy does the underlying message passing with the other end of the socket.

License

MIT License (c) Preet Shihn