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

@jnk/uc-client

v0.1.23

Published

## Getting started 1. Go to ulti-chat.com, create an account and create your first stack for free. 2. Install client using yarn: yarn add @jnk/uc-client` 3. Save the ulti-chat public key in your project

Downloads

3

Readme

UltiChat Client

Getting started

  1. Go to ulti-chat.com, create an account and create your first stack for free.
  2. Install client using yarn: yarn add @jnk/uc-client`
  3. Save the ulti-chat public key in your project

Usage

Initialize Client

  1. Import the client import { WSClient } from '@jnk/uc-client'
  2. In order to create a user-token you need to create a client with the root-token and run the function createUser().
  3. Create a new client: const client = new WSClient(userToken, publicKey)
  4. Open the connection: await client.open()

Create User

In or to create a user using the UltiChat API you need to initialize the client with a root-token. Then use the createUser() function:

const response: User = await client.createUser();

type User = {
  userToken: string;
  userId: string;
};

Create Channel

Channels can be created with root- and user-tokens using the createChannel() function:

client.createChannel(userIds);

userIds are the IDs of users which will be added to the newly created channel. In case you use the client as a 'user' the user's ID is automatically added to the newly created channel - you don't have to put it in the array of userIds but if you do it's fine as well. createChannel does not has a return value - you need to set the channelListEventHandler to get notified if you have been added to a new channel.

Get Channel-List

Retrieve the channels the current user is part of / has been added to:

const channels: ChannelListChannel[] = await client.getChannelList();

type ChannelListChannel = {
  id: string;
  lastMessage: {
    text: string;
    timestamp: string;
  } | null;
};

Send Message

Providing a channelId and a message you can send messages in specifc chats. For now only plain text messages are possible:

client.sendMessage(channelId, message);

Hint for testing purpose: If you send a message in a channel the client assumes that you previously have fetched the channel-list for the current user (see Get Channel-List) as well as the messages for the specific channel (see Get Channel Messages) .

Get Channel Messages

Retrieve all messages for a specific channel:

const messages: Message[] = await client.getChannelMessages(channelId);

type Message = {
  text: string;
  timestamp: string;
  userId: string;
};

ChannelListEventHandler

You want to set this event handler to get an updated channelList everytime an one of 3 events occurs:

  1. Current user has been added to a channel
  2. Current user has been removed from a channel
  3. A new message has been sent in a channel the user is part of The method setChannelListEventHandler takes a callback as an argument and in case of one of the above event it is called with 2 arguments
  • eventType (added_to_channel || removed_from_channel || new_message)
  • channelList (complete updated channelList)
client.setChannelListEventHandler((eventType, channelList) => {
  ...
})

ChannelEventHandler

You want to set a channel event handler if a chat window is currently showed in your application. The method setChannelEventHandler takes a callback as an argument. In case of a new_message in the active channel the callback is called with 3 arguments:

  • activeChannelId
  • newMessageChannelId
  • newMessageContent
client.setChannelEventHandler((activeChannelId, newMessageChannelId, newMesssageContent) => {
  ...
})

Active Channel

In order to gain full flexibility in the ChannelEventHandler you want to set the active channel if your a chat is currently showed in your application:

client.setActiveChannel(channelId)

Mock test data

  • Use tests (e.g. createChannel or sendMessage) to create test data
  • Make sure to use it.only to only run the one test you want to run