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

true-smart-messaging

v1.3.0

Published

``` npm install true-smart-messaging or yarn add true-smart-messaging ```

Downloads

32

Readme

Installation

  npm install true-smart-messaging
  or
  yarn add true-smart-messaging

Create Socket

import trueSmartMessaging from 'true-smart-messaging';
const socket = trueSmartMessaging.connect('http://host.com');

List of methods

Socket State

Listening to State from Socket server has change.

socket.socketState(state => {
  // Do Something
});

Socket Disconnect

Disconnects the socket manually.

socket.disconnect();

Connection State

socket.connection.connect(() => console.log('Connected'));
socket.connection.disconnect(() => console.log('Disconnect'));
socket.connection.connectError(() => console.log('Connect Error'));
socket.connection.reconnecting(() => console.log('Reconnecting'));

Create Room

For Setting page that read a config from the registry.

const configs = {
  shop: {
    id: '001',
    name: 'Shop 1'
  },
  counter: {
    id: '1',
    name: 'Counter 1'
  }
};

socket.createRoom(configs);

Join Room

Room's format is {shop.id}-{counter.id}

socket.joinRoom('room', 'clientName', response => {
  // response will be { status, message }
});

Leave Room

socket.leaveRoom();

Broadcast Room

Listen

Listening to broadcast from the room.

socket.broadcastRoom.listen(data => {
  // Do Something
});

Send

Send broadcast to the room.

socket.broadcastRoom.send(room, data);

Destroy

Remove listener

socket.broadcastRoom.destroy();

Events

| Event | KEY | | ----------- | ------------ | | ID Card | idCard | | E Signature | eSignature | | Image | image | | Info | info |

Use event with KEY

socket.KEY.waitingForRequest;
socket.KEY.request;
socket.KEY.send;
socket.KEY.listen;
socket.KEY.destroy;

How to use

Waiting for request

Listening to another clients call request

socket.KEY.waitingForRequest(response => {
  // response will be { clientId, data }
});

Request

Call request for trigger waitingForRequest.

You can send data to target.

socket.KEY.request(data);

Send

Send Data to Client that requested.

const data = {
  status: 'SUCCESS', // BUSY, ERROR, CANCEL or etc.
  data: '' // any
};
socket.KEY.send(clientId, data);

Listen

Listening to data when client sent.

socket.KEY.listen(data => {
  // Do Something
});

Destroy

Remove all listeners when go out of the page or component will unmount.

socket.KEY.destroy();

Example Usage

Sender

import trueSmartMessaging from 'true-smart-messaging';

const socket = trueSmartMessaging.connect('http://host.com');

// Room's format is {shop.id}-{counter.id}
const room = '001-1';
const clientName = 'Agent';
socket.joinRoom(room, clientName);

socket.broadcastRoom.listen(() => alert('Broadcast'));

socket.idCard.waitingForRequest(({ clientId, data }) => {
  socket.idCard.send(clientId, {
    status: 'SUCCESS', // BUSY, ERROR
    data: {} // ID Card data
  });
});

// Destroy when go out of the page or component will unmount
socket.idCard.destroy();

Receiver

import trueSmartMessaging from 'true-smart-messaging';

const socket = trueSmartMessaging.connect('http://host.com');

// Room's format is {shop.id}-{counter.id}
const room = '001-1';
const clientName = 'CLIENT-NAME';
socket.joinRoom(room, clientName);

socket.broadcastRoom.listen(() => alert('Broadcast'));

socket.idCard.listen(respone => {
  if (respone.status === 'SUCCESS') {
    doSomething(respone.data);
  }
});

socket.idCard.request();

// Destroy when go out of the page or component will unmount
socket.idCard.destroy();

Socket State Helper

| Name | Param required (Object) | | ----------------------- | ----------------------------- | | getConnectionInRoom() | { state, room } | | isClientInRoom() | { state, room, clientName } |

Example

import trueSmartMessagingHelper from 'true-smart-messaging/helper';

socket.socketState((state, options) => {
  const room = '001-1';
  const clientName = 'CLIENT-NAME';

  const connections = trueSmartMessagingHelper.getConnectionInRoom({ state, room });

  // Do Something
});