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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@arthurdevfrontend/miniwebsocket

v1.2.1

Published

Blibioteca MiniWebSocket minimalista para comunicação em tempo real

Readme

MiniWebSocket

MiniWebSocket é uma biblioteca JavaScript minimalista para criar conexões WebSocket em tempo real, tanto no servidor quanto no cliente.
Com ela, você consegue criar chats, notificações e sistemas que precisam de comunicação instantânea de forma fácil e rápida.


💡 Funcionalidades

  • Conexão simples via new MiniWebSocket(url)
  • Reconexão automática com tentativas configuráveis
  • Fila de mensagens offline (não perde msgs se mandar antes de conectar)
  • Broadcast para todos os clientes
  • Salas (rooms) com usuários
  • Histórico de mensagens com limite configurável
  • Sistema de eventos estilo Node (on("message"), on("open"), etc.)
  • Ping/Pong automático para verificar se cliente está online
  • Leve, sem dependências externas
  • Logs opcionais com debug: true

⚡ Instalação

Se você estiver usando Node.js, basta instalar via npm:

npm i @arthurdevfrontend/miniwebsocket

ou, se usar Yarn

yarn add @arthurdevfrontend/miniwebsocket

Prontinho! Agora a blibioteca está instalada 🎉

Uso Básico🧩

1️⃣ Criar o servidor

Crie um arquivo chamado server.js e escreva assim:


const { WebSocketServer } = require("arthurdevfrontend/miniwebsocket)

// Criar o servidor na porta 8080
const server = new WebSocketServer({ port: 8080});

// Quando alguém se conectar
server.on("connection", (socket) => {
    console.log("Alguém se conectou!")

    // Receber mensagem de um cliente
    socket.on("message", (msg) => {
        console.log("Mensagem Recebida")


        // Mandar a mensagem para todo mundo
        server.broadcast(`Alguem disse: ${msg}`);

    });



    socket.send("Bem vindo ao MiniWebSocket")
});

2️⃣ Criar o Cliente (Node.js)

Crie um arquivo chamado Client.js

const { WebSocket } = require("@arthurdevfrontend/miniwebsocket")

// Conectar ao servidor
const socket = new WebSocket("ws://localhost:8080",{
  reconnectInterval: 3000,
  maxReconnectAttempts: 10
  debug: true,
});

// Quando receber mensagem
socket.on("message", (msg) => {
  console.log("Servidor diz:", msg);
});

// Mandar mensagem para o servidor
socket.send("Oi, servidor!");

3️⃣ Rodar

No terminal primeiro rode o servidor:

node server.js

Depois em outro terminal rode o cliente

node client.js

4️Testando recursos extras do MiniWebSocket

  • Broadcast: envia para todos os clientes:
server.broadcast("Mensagem global pra todos!");
  • Salas(Rooms):
socket.joinRoom("sala1");
socket.sendToRoom("sala1", "Mensagem só pra essa sala");
  • Ping: testar se o cliente está online
socket.ping();
  • Reconexão automática: se o cliente perder a conexão ele tentar reconectar sozinho, conforme você definiu no reconnectInterval e maxReconnectAttempts. Você vera mensagem rodando em tempo real!🥳

🎯Dicas fáceis para começar

  • Pense Que Cada Cliente e um amiguinho para conversar
  • send() manda mensagem
  • on("message", ...) escuta quando alguém manda mensagem
  • broadcast()manda mensagem para todos tudo de uma vez. Com isso voce consuege criar um chat divertido ou avisos em tempo real🐱‍👤

💡 Dica final: Pense nos WebSockets como um telefone mágico, onde todo mundo pode falar e ouvir ao mesmo tempo, sem presisar desligar e ligar o telefone. 📞