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

faatlab-chat-engine

v1.0.0

Published

chat-engine

Downloads

3

Readme

📦 Chat Engine

🕸️ Installation

npm install @faatlab/chat-engine

🛠️ Usage

Initial setup

import { ChatEngine } from "chat-engine";

// Create HTTP server
const server = http.createServer(app);

const chat_engine = new ChatEngine(
  {
    database_url: "mysql://user:user@123@localhost:3306/chat-engine",
    dialect: "mysql",
  },
  server
);

await chat_engine.connect();

Passing server to chat engine is optional. If you want to use only the chat engine methods and not the socket methods, pass the database details as arguments

const chat_engine = new ChatEngine({
  database_url: "mysql://user:user@123@localhost:3306/chat-engine",
  dialect: "mysql",
});

await chat_engine.connect();

Chat Engine Methods

createNewUser

const user = await chat_engine.createNewUser({
  user_id: "123456",
  name: "hulk",
  thumbnail: "path/user_profile.png",
  metadata: {
    email: "[email protected]",
    phone: "9876543210",
  },
});

// thumbnail and metadata are optional. metadata can be any json object.

console.log("User: ", user);

createBulkUsers

const users = await chat_engine.createBulkUsers([
  {
    user_id: "1011",
    name: "tony stark",
    thumbnail: "path/user_profile.png",
  },
  {
    user_id: "1012",
    name: "batman",
  },
  {
    user_id: "1013",
    name: "deadpool",
    metadata: {
      email: "[email protected]",
      phone: "9876543210",
    },
  },
  {
    user_id: "1014",
    name: "captain america",
  },
]);

getUserAuthToken

const token = await chat_engine.getUserAuthToken("123456");
console.log("Token: ", token);

createNewChat

const chat = await chat_engine.createNewChat({
  sender_id: "123456",
  receiver_id: "101178",
  message: "Hello",
  metadata: {
    additional_info: "json_data",
  },
});

// metadata is optional and can be any json object

console.log("Chat: ", chat);

createBulkChats

const bulk_chats = await chat_engine.createBulkChats([
  { sender_id: "1011", receiver_id: "1012", message: "Hello World! 1" },
  { sender_id: "1012", receiver_id: "1013", message: "Hello World! 2" },
  { sender_id: "1013", receiver_id: "1014", message: "Hello World! 3" },
  { sender_id: "1012", receiver_id: "1011", message: "Hello World! 4" },
]);

listChatUsers

const users = await chat_engine.listChatUsers({
  user_id: "1011",
  page: 0,
  size: 10,
});
console.log(users);

getChatsBetweenUsers

const chats = await chat_engine.getChatsBetweenUsers({
  user1_id: "1011",
  user2_id: "1012",
  seen: true,
  page: 0,
  size: 10,
});

// argument 'seen' is optional. pass argument 'seen:true' for receivers,
// to mark the chats has been seen by the receiver

console.log(chats);

markChatAsSeen

  const result = await chat_engine.markChatAsSeen(
    user1_id: "1011",
    user2_id: "1012",
  );

  console.log(result);

Web Socket Methods

user:connect

socket.emit("user:connect");

send:personal_chat

socket.emit("send:personal_chat", { message, receiver_id });

receive:personal_chat

socket.on("receive:personal_chat", {(...args) => {
  // ...
});

error

socket.on("error", {(...args) => {
  // ...
});