Get started with stomp.js CDN
Apache-2.0 licensed
Stomp.js is a JS client library for real-time messaging over the WebSocket protocol.
Tags:- STOMP
- Web sockets
- messaging
- queue
Stable version
Copied!
How to start using stomp.js CDN
// Include STOMP.js library
const STOMP = (function() {
function Stomp(socket, onopen, onerror, onmessage) {
this.socket = socket;
this.onopen = onopen;
this.onerror = onerror;
this.onmessage = onmessage;
this.connect = function() {
this.socket.connect();
this.socket.onopen = this.onopen.bind(this);
this.socket.onerror = this.onerror.bind(this);
this.socket.onmessage = this.onmessage.bind(this);
};
}
return Stomp;
})();
// Include the STOMP.js library from the CDN
const Stomp = new Stomp(new WebSocket("ws://your-websocket-url"), onOpen, onError, onMessage);
// Connect to the server
Stomp.connect();
// Define callback functions
function onOpen() {
console.log("Connected to server");
Stomp.send("/app/hello", {}, JSON.stringify({ greeting: "Hello World" }));
}
function onError(error) {
console.log("Error: " + error);
}
function onMessage(message) {
console.log("Received: " + message.data);
}
Copied!
Copied!