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

trixi

v1.1.3

Published

If you need to send a payload with out the possibility of a response, then you can send a unidirectional payload, otherwise knon as an assertion. Both the client and server can send an assertion to each other, once the assertion is sent, it cannot be rep

Downloads

34

Readme

Trixi is a WebSocket wrapper that enables developers to create better and stricter acpplications. The way we do this is that we use scoped socket interactions which allows you to have a scope for unidirectional payloads, operator based payloads, and bidirectional payloads. All of this is done through the use of a standardized payload schema.

Unidirectional Payloads

If you need to send a payload with out the possibility of a response, then you can send a unidirectional payload, otherwise knon as an assertion. Both the client and server can send an assertion to each other, once the assertion is sent, it cannot be replied to in any way.

import trixi from 'trixi';
import { Server } from 'http';

const httpServer = new Server();
const app = trixi();

/**
 * Server Example
 */
httpServer.listen(8080, () => {
  const server = app.createServer({ httpServer });

  server.onConnection(connection => {
    console.log("A new socket connection has been established from", connection.remoteAddress);

    // Send your assertion message on start
    connection.assert("Welcome...");

    // Create a listener for assertions from the client
    connection.onAssert(assertion => {
      console.log("New assertion from client:", assertion.data);
    });
  });
});

/**
 * Client Example
 */
const client = app.createClient({ url: "ws://localhost:8080" });
client.assert("I have arrived!!"); 

client.onAssert(assertion => {
  console.log("New assertion from server:", assertion.data);
});

Bidirectional Payloads

Sometimes you want to be able to hear back from your client when you send a message, so with bidirectional payloads, you'll be able to send a payload, and recieve payload in response if you so choose. When you response, it will be sent directionally to the original payload which you can start a listener for a response on.

import trixi from 'trixi';
import { Server } from 'http';

const httpServer = new Server();
const app = trixi();

/**
 * Server Example
 */
httpServer.listen(8080, () => {
  const server = app.createServer({ httpServer });

  server.onConnection(connection => {
    console.log("A new socket connection has been established from", connection.remoteAddress);

    // Create your listener
    connection.onPayload(msg => {
      console.log("Recieved a payload from the client", msg.data);
      msg.reply({ recieved: true });
    })
  });
});

/**
 * Client Example
 */
const client = app.createClient({ url: "ws://localhost:8080" });

// Send a message to the server and await a response
client.send({ hello: "world" }).then(payload => {
  payload.onResponse(response => {
    console.log("Recieved response from the server", response.data);
  })
});

Operator Payloads

Operator payloads are something that you can use to send a payload with a specific operator code attached to it. Once you send the operator payload, the client can listen for it and if it choose to, it can reply in the same manor as the bidrectional payload.

import trixi from 'trixi';
import { Server } from 'http';

const httpServer = new Server();
const app = trixi();

/**
 * Server Example
 */
httpServer.listen(8080, () => {
  const server = app.createServer({ httpServer });

  server.onConnection(connection => {
    console.log("A new socket connection has been established from", connection.remoteAddress);

    // When a new connection is established, send the "hello:world" operator.
    connection.sendOp("hello:world", { greeting: "Hello World" });
  });
});

/**
 * Client Example
 */
const client = app.createClient({ url: "ws://localhost:8080" });

// Create a listener on the operator "hello:world"
client.onOp("hello:world", e => {
  console.log("New message on 'hello:world':", e.data);
});

NOTE: You can send a string or a json object as a payload.