🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

@w3bstream/w3bstream-http-client-simulator

Package Overview
Dependencies
Maintainers
5
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@w3bstream/w3bstream-http-client-simulator

[![npm](https://img.shields.io/npm/v/@w3bstream/w3bstream-http-client-simulator)](https://www.npmjs.com/package/@w3bstream/w3bstream-http-client-simulator)

latest
Source
npmnpm
Version
3.1.1
Version published
Weekly downloads
42
425%
Maintainers
5
Weekly downloads
 
Created
Source

Simulator README

npm

This README provides an overview of the Simulator module, which is designed to generate and send simulated data points to the W3BSTREAM server.

Table of Contents

Getting Started

To use the Simulator module, you need to import it along with some dependencies:

import {
  Simulator,
  DataPointGenerator,
} from "@w3bstream/w3bstream-http-client-simulator";

And provide DEVICE_TOKEN and HTTP_ROUTE that can be found in W3bstream project.

const apiKey = "API_KEY";
const httpRoute = "HTTP_ROUTE";

Usage

Create message generator

Deside what the shape of the data point should be:

type TemperatureDataPoint = {
  temperature: number;
  timestamp: number;
};

And how the data point should be generated, you can use randomizer or timestampGenerator methods of DataPointGenerator:

const generatorFunction = () => ({
  temperature: DataPointGenerator.randomizer(0, 100),
  timestamp: DataPointGenerator.timestampGenerator(),
});

And finally, to generate messages, instantiate data generator:

const dataGenerator = new DataPointGenerator<TemperatureDataPoint>(
  generatorFunction
);

Simulator initialization

Create a new instance of the Simulator class, initialize it and set a DataPointGenerator that you created earlier:

const simulator = new Simulator(apiKey, httpRoute);
simulator.init();
simulator.dataPointGenerator = dataGenerator;

(OPTIONAL) You can also provide a pathToPrivateKey parameter:

simulator.init(pathToPrivateKey);

Now you can generate a message with a single or multiple events:

const message = simulator.generateEvents(numberOfDataPoints);

Sending Messages

To send a single message to the server, call the sendSingleMessage method:

const eventType = "TEMPERATURE";

const { res, msg } = await simulator.sendSingleMessage(eventType);

console.log("response: ", res?.data);
console.log("w3bstream message: ", msg);

To send messages at a specified interval, use the powerOn method:

const intervalInSec = 1;
const eventType = "TEMPERATURE";

simulator.powerOn(intervalInSec, eventType);

To stop sending messages, call the powerOff method:

simulator.powerOff();

Keywords

w3bstream

FAQs

Package last updated on 14 Aug 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts