Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@stomp/stompjs

Package Overview
Dependencies
Maintainers
2
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@stomp/stompjs

STOMP client for Javascript and Typescript

  • 7.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
196K
increased by3.43%
Maintainers
2
Weekly downloads
 
Created

What is @stomp/stompjs?

@stomp/stompjs is a JavaScript library that provides a STOMP (Simple Text Oriented Messaging Protocol) client for WebSocket communication. It allows you to connect to a STOMP broker over WebSocket, send and receive messages, and handle various messaging scenarios in real-time applications.

What are @stomp/stompjs's main functionalities?

Connect to a STOMP broker

This feature allows you to connect to a STOMP broker using WebSocket. You can specify the broker URL, connection headers, and callback functions for connection success and error handling.

const Stomp = require('@stomp/stompjs');
const client = new Stomp.Client({
  brokerURL: 'ws://localhost:8080/stomp',
  connectHeaders: {
    login: 'user',
    passcode: 'password'
  },
  onConnect: () => {
    console.log('Connected to the broker');
  },
  onStompError: (frame) => {
    console.error('Broker reported error: ' + frame.headers['message']);
    console.error('Additional details: ' + frame.body);
  }
});
client.activate();

Subscribe to a topic

This feature allows you to subscribe to a specific topic on the STOMP broker. When a message is sent to that topic, the provided callback function is executed, and the message is processed.

client.onConnect = () => {
  client.subscribe('/topic/messages', (message) => {
    console.log('Received message: ' + message.body);
  });
};

Send a message

This feature allows you to send a message to a specific destination (topic or queue) on the STOMP broker. The message body can be any string.

client.onConnect = () => {
  client.publish({
    destination: '/topic/messages',
    body: 'Hello, world!'
  });
};

Handle disconnection

This feature allows you to handle disconnection from the STOMP broker. You can specify a callback function to execute when the client disconnects, and you can also deactivate the client.

client.onDisconnect = () => {
  console.log('Disconnected from the broker');
};
client.deactivate();

Other packages similar to @stomp/stompjs

Keywords

FAQs

Package last updated on 08 Feb 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

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc