Socket
Socket
Sign inDemoInstall

rtlayer-node

Package Overview
Dependencies
1
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    rtlayer-node

Send updates to your users in realtime in just few lines of code and you don't even have to think about the infrastructure.


Version published
Weekly downloads
46
decreased by-41.03%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

Overview

rtlayer-node is a Node.js library that provides an easy-to-use interface for interacting with the RTLayer API. RTLayer is a real-time messaging platform that enables you to integrate real-time functionality into your applications.

This documentation will guide you through the installation process, initialization of the RTLayer client, and demonstrate how to send messages using the library.

Installation

To install the rtlayer-node package, use npm:

npm install rtlayer-node

Usage

Importing the RTLayer module

const RTLayer = require('rtlayer-node').default;

Initializing RTLayer

To use the RTLayer API, you need to initialize an instance of the RTLayer class with your API key. You can obtain an API key by signing up for an RTLayer account.

const rtlayer = new RTLayer("your-api-key");

Sending Messages

Use the message method to send real-time messages. The method takes two parameters:

  • message (string or object): The content of the message, which can be either a string or a JSON object.
  • options (object): An optional parameter with the following properties:
    • ttl (number): Time to live for the message in seconds (optional).
    • channel (string): The channel on which to send the message (optional).
// Sending a string message
rtlayer.message("Welcome to MARS!",{
	ttl: 60, // Optional: Time to live for the message in seconds
  channel: "user-id" // // Optional: Channel on which to send the message
});

// Sending a JSON message
rtlayer.message({ headline: "AI Revolution: How Artificial Intelligence is Transforming the Job Market" }, {
    channel: "news"
});

Note: Make sure to replace "your-api-key" with your actual RTLayer API key.

Example

Here is a complete example of using rtlayer-node to send a real-time message:

const RTLayer = require('rtlayer-node').default;

// Replace "your-api-key" with your actual RTLayer API key
const rtlayer = new RTLayer("your-api-key");

// Sending a string message with a personal touch
const personalMessage = "Hello Developers! Just wanted to remind you to take a break and stay hydrated. Happy coding! 😊";

rtlayer.message(personalMessage, {
    ttl: 1,         // Optional: Time to live for the message in seconds
    channel: "devs" // Optional: Channel on which to send the message
});

// Sending a JSON message for a more structured update
const jsonMessage = {
    update: "New version of your favorite programming language released!",
    version: "v3.0.0",
    details: "This release includes exciting new features and performance improvements. Check the documentation for more information."
};

rtlayer.message(jsonMessage, {
    ttl: 1,
    channel: "devs"
});

Conclusion

Experience real-time communication effortlessly with RTLayer. In just 30 minutes, transform your application into a dynamic, engaging experience without the hassle of managing infrastructure.

Keywords

FAQs

Last updated on 16 Dec 2023

Did you know?

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc