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

@chat-e2ee/service

v1.5.0

Published

SDK to create realtime messaging with chat-e2ee

Downloads

4

Readme

This is a client-side SDK to interact with chat-e2ee service. It allows dev to build own chat client on top of chate2ee service. It uses socket.io for websocket connection.

npm version size

npm i @chat-e2ee/service

@chat-e2ee/service exports the following modules:

  • createChatInstance - core chat ops.
  • utils
    • generateUUID - util func to generate UUID.
    • decryptMessage - to decrypt encrypted messages.
  • setConfig - configuration - set URLs i.e. API endpoints, debugging etc.

Example and flow:

1. Import and initialize the SDK:

import { createChatInstance, utils, setConfig } from '@chat-e2ee/service';
const chatInstance = createChatInstance(config);
await chatInstance.init();

Note that the config is optional.

2. Setup channel:

First, you have to set up a channel. To set up a channel you need to generate a hash, user ID.

const userId = utils.generateUUID(); // you can use your own user id.
const { hash } = await chatInstance.getLink();

await chatInstance.setChannel(hash, userId);

Once you set up a channel, user2 can join the channel by passing the same hash to setChannel with their own userid. Note that userid should be unique.

3. Send message:

When both users have joined the channel, you are ready to send a message.

await chatInstance.encrypt('some message').send();

4. Receive messages:

Setup listener to receive messages from user2 and use your private key to decrypt messages.

const { privateKey } = chatInstance.getKeyPair();
chatInstance.on('chat-message', async () => {
    const msgInPlainText = await utils.decryptMessage(msg.message, privateKey);
    console.log(msgInPlainText);
});

chatInstance.getLink():

One user needs to create a link and share it with other user.
Each instance is unique to each link. To create a separate link, another instance needs to be created.

const linkDescription = chatInstance.getLink();

linkDescription contains basic info:

{
    hash: string;
    link: string;
    expired: boolean;
    deleted: boolean;
    pin: string;
    pinCreatedAt: number;
}

Send message:
1 - Auto encryption by @chat-e2ee/service

@chat-e2ee/service will encrypt message with publicKey before sending to network.

chatInstance.encrypt({ image, text }).send();

2 - Custom encryption / No encryption:

Simply call .sendMessage() with encrypted or plain text.

chatInstance.sendMessage({ image, message: <message> });

Event listeners:

chate2ee.on(events, callback);

Events:
on-alice-join - reveiver joined the link
chat-message - new message received

chate2ee.on('chat-message', (msg) => {
    console.log('message received',msg)
})

msg object:

{
    channel: string,
    sender: string,
    message: string,
    id: number,
    timestamp: number,
    image?: string
}

on-alice-disconnect - receiver left/disconnected from the link
limit-reached - 2 users already join a link
delivered - a message is delivered to the receiver callback returns the ID of the message that's delivered.

chate2ee.on('delivered', (id) => {
    console.log('delivered',id)
})

Config:

Call setConfig with config object to override default config parameters.

config follows:

{
    apiURL: string | null,
    socketURL: string | null,
    settings: {
        disableLog: boolean,
    }
}

Note that @chat-e2ee/service will make request to / in local env and to hosted server in production env by default. If you want to use a custom server, use setConfig({ apiURL, socketURL });


Debugging:

Open the browser console and filter your logs by @chat-e2ee/service

to disable logging set the settings.disableLog to true in configContext:

setConfig({
    settings: {
        disableLog: boolean
    }
})