A fork of Jeff Mesnil stomp-websocket adapted as a npm mobule and webpack compatible
Fist, install stomp-websockets
npm install stomp-websockets --save
import Stomp from 'stomp-websockets'
let stomp = Stomp.client(serverURL)
let headers = {
login: 'my login',
passcode: 'my passcode',
'client-id': 'myclientid'
}
stomp.connect(headers,
() => { // On success
stomp.subscribe(topicName, msg => {
alert('Received message')
})
},
error => { // On error
console.log('STOMP Error - Connection')
console.log(error)
if (!stomp.connected) {
setTimeout(function () {
console.log('Connection: retry')
// try to reconnect
}, 10000) // 10 secondi
}
})
This version of Stomp uses ES6 syntax. To transiple it in ES5 to support older browsers, use thi command:
npm run build
The generated javascript file is dist/Stomp.js