Giter Club home page Giter Club logo

webstomp-client's Introduction

webstomp-client

This library provides a stomp client for Web browsers and nodejs through Web Sockets.

Project Status

This is a fork of the original stomp-websocket re-written in ES6 and incorporate pending pull requests. All credits goes to the original authors: Jeff Mesnil & Jeff Lindsay.

Browsers support

Only ES5 compatible modern browsers are supported. If you need a websocket polyfill you can use sockjs

nodejs support

As nodejs does not have a WebSocket object like browsers have, you must choose a websocket client and use webstomp.over instead of webstomp.client. Choosing a good client is maybe the most difficult part:

Example

npm run example will open examples in browser and try to connect to RabbitMQ Web-Stomp default Web Sockets url. node run example/broadcast-node.js will run a dead simple nodejs example.

Use

npm install webstomp-client

Web browser old fashion style

<script type="text/javascript" src="node_modules/webstomp-client/dist/webstomp.min.js"></script>

webstomp will be a global variable.

CommonJS

var webstomp = require('webstomp-client');

ES6 modules

import webstomp from 'webstomp-client';

By default it will load dist/webstomp.js, but the npm package.json es6 entry point to the es6 src file if you prefer loading this version.

API

Jeff Mesnil stomp-websocket documentation is still a must read even if the API evolved a little

webstomp

client(url, [options])

Uses global WebSocket object for you to return a webstomp Client object.

url

Web Sockets endpoint url

options
  • protocols: default to ['v10.stomp', 'v11.stomp', 'v12.stomp']
  • binary: default to false. See binary section.
  • heartbeat: default to {incoming: 10000, outgoing: 10000}. You can provide false to cut it (recommended when the server is a SockJS server) or a definition object.
  • debug: default to true. Will log frame using console.log

over(ws, [options])

Takes a WebSocket alike object instance to return a webstomp Client object. Allows you to use another WebSocket object than the default one. 2 cases for this:

  • you do not want webstomp.client to create a default instance for you.
  • you are in an old browser or nodejs and do not have a global WebSocket object that webstomp.client can use.
ws

WebSocket object instance

options
  • binary: default to false. See binary section.
  • heartbeat: default to {incoming: 10000, outgoing: 10000}. You can provide false to cut it (recommended when the server is a SockJS server) or a definition object.
  • debug: default to true. Will log frame using console.log

VERSIONS

supportedVersions()

List all STOMP specifications supported.

supportedProtocols()

List all websocket STOMP protocols supported. Useful when creating your own WebSocket instance, although optional, protocols is often the second parameter.

Client

A client instance can and should be created through webstomp.client or webstomp.over

connect

  • connect(headers, connectCallback)
  • connect(headers, connectCallback, errorCallback)
  • connect(login, passcode, connectCallback)
  • connect(login, passcode, connectCallback, errorCallback)
  • connect(login, passcode, connectCallback, errorCallback, host)

disconnect(disconnectCallback, headers={})

send(destination, body='', headers={})

subscribe(destination, callback, headers={})

unsubscribe(id, header={})

It is preferable to unsubscribe from a subscription by calling unsubscribe() directly on the object returned by client.subscribe()

var subscription = client.subscribe(destination, onmessage);
...
subscription.unsubscribe(headers);

headers are optionals

onreceive(frame)

If defined on the client instance this function will be called whenever a message is received and in the absence of an explicit subscribe(). Some brokers (at least RabbitMQ) will setup an internal routing topology for RPC patterns when a message is sent with certain headers.

In RabbitMQ it's called Direct Reply-To

On the client

let onreceive(frame)=>{
        console.log('Message received',frame)
}

client.onreceive=onreceive

let headers = {
        'reply-to'  :'/temp-queue/webstomp',
}

client.send('/topic/public.echo.hi.mom','a message')

On the server (using Amqplib for example)

ch.publish('',raw_message.properties.replyTo,Buffer.from('a reply'))

begin([transaction])

If no transaction ID is passed, one will be created automatically

commit(transaction)

It is preferable to commit a transaction by calling commit() directly on the object returned by client.begin():

var tx = client.begin(txid);
...
tx.commit();

abort(transaction)

It is preferable to abort a transaction by calling abort() directly on the object returned by client.begin():

var tx = client.begin(txid);
...
tx.abort();

ack(messageID, subscription, headers={})

It is preferable to acknowledge a message by calling ack() directly on the message handled by a subscription callback:

client.subscribe(destination, (message) => {
        // process the message
        // acknowledge it
        message.ack();
    }, {'ack': 'client'}
);

nack(messageID, subscription, headers={})

It is preferable to nack a message by calling nack() directly on the message handled by a subscription callback:

client.subscribe(destination, (message) => {
        // process the message
        // acknowledge it
        message.nack();
    }, {'ack': 'client'}
);

debug

Will use console.log by default. Override it to update its behavior.

Binary

It is possible to use binary frame instead of string frame over Web Sockets.

  • client side: set the binary option to true.
  • server side: use a compatible websocket server, like with RabbitMQ Web-Stomp since 3.6

Heartbeat

Not all server are compatible, you may have to deactivate this feature depending the server you are using. For example RabbitMQ Web-Stomp is compatible only since 3.6 with native Web Sockets server.

Authors

webstomp-client's People

Contributors

affemaen avatar elmarquez avatar jimic avatar jsteunou avatar mamoru1234 avatar ms88privat avatar nathangloyn avatar noelblaschke avatar pepijno avatar yeyu456 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

webstomp-client's Issues

Outdated npm package

The package published in npm is the 1.0.8.

Is there a time to update this on npm?

Typescript definition file

First of all, thank you very much for the energy you're putting in the project.

I am, as a lot of Angular 2 developers, working more and more with TypeScript.
And, as you may know, TypeScript needs typings for external librairies. So it would be great if you could add the typings to the DefinitelyTyped repository, or better, within the NPM module (as recent TypeScript compilers can pick it up automatically).

This is not a new issue, as you can see on the original repo jmesnil/stomp-websocket#61

I'm not a TypeScript expert, but I slightly modified one of the propositions to have the bare minimum for my case (I don't know enough the library to make something more exhaustive).

declare module 'webstomp-client' {

  interface webstomp {
    over(socketType: any) : webstomp;
    connect(headers: any, connectCallback: () => any);
    subscribe(destination: string, callback: (message: StompMessage) => any);
  }

  interface StompMessage {
    body : string;
  }

  var webstomp: webstomp;
  export = webstomp;

}

Deprecation Warning

We are using SockJS as default websocket type:

const socket = new SockJS(url);
const stompClient = Stomp.over(socket);

Unfortunately this always leads to the deprecation warning

DEPRECATED: is not a recognized STOMP version. In next major client version, this will close the connection

because 'protocol' is an empty string in SockJS. I can't find a way to specify protocol in such a case.

Could you please deactivate the deprecation warning in such a case?

Version 1.05 from npm doesn't include index.d.ts

Hello,

when installing the latest version from npm, the file index.d.ts is not present at the root of the webstomp-client folder in node_modules.

I'm importing the module in an Angular2 app like this:
import * as WebStomp from 'webstomp-client';

It works fine if i add the file index.d.ts manually though.

node examples

The html examples are great, but what about an example from a node app?
For example: do we need to import a WebSocket object before creating a client?

React native: Cannot connect by android

Hi JSteunou, my app use last version and client always return Whoops! Lost connection
Can you help me ?

Mycode:
const options = {debug: true, protocols: webstomp.VERSIONS.supportedProtocols()};
let client = webstomp.client(url, options);
client.connect({}, function connectCallback(frame){
console.log('OK')
}, (error) => {
console.log('Error');
});

It work very good in ios but in android:
Opening Web Socket...
Web Socket Opened...

CONNECT
accept-version:1.2,1.1,1.0
heart-beat:10000,10000
frame: {
body: undefined,
command: "CONNECT",
headers: {accept-version: "1.2,1.1,1.0", heart-beat: "10000,10000"}
}
Whoops! Lost connection to undefined: {event: WebSocketEvent}
WebSocketEvent {type: "close", target: WebSocket, currentTarget: WebSocket, eventPhase: 2, bubbles: false, …}

Client sends wrong CONNECT headers on reconnect

I've run into a problem where during a reconnect, headers are included in the CONNECT message that were part of a previous SEND message, specifically the 'destination' header. This leads to problems for me. Not entirely sure yet how it happens

Potential Stomp/Chrome compatibility issue: Error during WebSocket handshake: Sent non-empty 'Sec-WebSocket-Protocol' header but no response was received

It seems like the latest version of Chrome has broken my websocket functionality in my application. I am utilising the following code to use Stomp with a SockJS websocket.

import SockJS from 'sockjs-client';
import Stomp from 'webstomp-client';

class WebSocket {

    static register(registrations, endpoint) {
        var socket = SockJS(endpoint);
        var stompClient = Stomp.over(socket);
        stompClient.connect({}, (frame) => {
            console.log('Connected: ' + frame);
            registrations.forEach(function (registration) {
                stompClient.subscribe(registration.route, registration.callback);
            });
        });
    }
}

export default WebSocket;

I am using spring boot in the backend which is also unchanged. I assumed that using Stomp.over would not send that header (or some sort of default one), and it has been working fine for a long time without sending the response header from the server for the subprotocol. I cannot see any 'Sec-WebSocket-Protocol' header in the dev tools either. Any ideas what may have happened here?

Thanks.

Failed to execute 'send' on 'WebSocket': Still in CONNECTING state.

Hello there!

I'm getting lots of error reports with:
Chrome:
Failed to execute 'send' on 'WebSocket': Still in CONNECTING state.
Safari complains with:
InvalidStateError: The object is in an invalid state.
and in Firefox it's:
An attempt was made to use an object that is not, or is no longer, usable

Im not 100% sure if I'm doing everything right, so here is how i do it in TypeScript

connect(): void {
    this.stompClient = client(this.hostname, {
        debug: false,
        protocols: ['v10.stomp', 'v11.stomp', 'v12.stomp'],
        binary: false,
        heartbeat: {incoming: 25000, outgoing: 25000}
    });
    this.stompClient.connect(this.username, this.password, this.onConnect, this.onError, this.vhost);
}


private onConnect = () => {
    this.stompClient.subscribe('/exchange/sync/' + this.userUuid, this.onMessage);
}

private onError = (err) => {
    this.logger.warn(`Live sync change to: not available: error: ${JSON.stringify(err)}`);
}

I expect the WebSocket to be ready when the connect callback gets called (onConnect).
Or am I misunderstanding something?

Stomp.connect should accept custom headers

Hi, I'm using webstomp in Aurelia project, cause of possibility of .subscribe. In original repo .connect() accepts custom headers, like:
.connect({'Authorization': 'Bearer 123'})

In your 'index.d.ts' i see, that connect accepts only:

  • headers: ConnectionHeader
  • login: string, passcode: string

... before callback function, but ConnectionHeader interface contains only:
login: string; passcode: string; host?: string;
If I change it to any, Stomp sends request as ussualy with my custom header.

My example:

websocketConnect(){
	var socket = new SockJS('https://my-rul');
	var stompClient = Stomp.over(socket);
	var token = `Bearer ${this.authService.getAccessToken()}`;
	stompClient.connect({'Authorization' : token}, frame => {
		stompClient.subscribe('/some-subchannel', msg => {
			// ...
		});
	});
}

e6 not working

Hi!

I can't import the e6 module...

Error: Could not find module webstomp-client imported from plhw-client/services/realtime-stomp

npm install webstomp-client --save-dev
ember serve
// services/realtime-stomp.js
import webstomp from 'webstomp-client';

...

Version on npm isn't latest code

I went to use the npm package but found it is the code from before my PR was accepted fixing the issue with heart-beat settings.

Could the latest version be put on npm?

Disconnect and reconnect issue

I read the source code to get a better knowledge of auto reconnect. I found that disconnect method sends a 'DISSCONNECT' frame and wait for a receipt before cleanup and close websocket.
There may be chances that websocket onClose is invoked when doing disconnect, so I think a disconnecting flag should be added to handle this situation.

Diferences between Firefox and Chrome

Hi, first at all, congrats for this job.

I observed a difference between Firefox and Chrome after lost connection ( this can be view at broadcast.html example ). Using Chrome, onError is called after several PINGS sent and Firefox calls onError after the first PING to change status ( disconnnected ).
For me the Chrome´s behavior is better.

thanks

Custom logs with frame object as the 2nd param

Hi there,

this is a kind of a feature request. I am aware that it's possible to override the logs via client.debug = (log) => ...myLogic. It is cumbersome to do anything with the plain text. You could send the text and, as the 2nd parameter, the frame object. Then we developers can strip headers, shorten some access tokens, etc. ...

At the moment the debug methods accepts a vararg ...args. Every method in src/client.js is using only 1 arg (the message). See the code:

debug(...args) {
        if (this.hasDebug) console.log(...args);
}

I will create a PR in a moment so that you can verify it will make no harm, you'll see.

Documentation insufficient to move from original library

The documentation about moving from perfectly documented original library to this one is actually missing.

There was method over that worked with SockJS for me. Currently doc says

"over(ws, [options])
Takes a WebSocket alike object instance to return a webstomp Client object. "

Initailly, it is confusing to guess what would be the "websocket alike object". To my understanding, the only thing that should be present in technical documentation is exact codebase types, so readed won't left to guessing.

Usage of this functiuon in place of old call is resulting in

vendor.js:118 TypeError: WebSocket.over is not a function
at doInitConnections (mainPageController.js:355)
at m.$scope.initConnections (mainPageController.js:332)
at fn (eval at compile (vendor.js:233), :4:236)
at b (vendor.js:126)
at e (vendor.js:276)
at m.$eval (vendor.js:145)
at m.$apply (vendor.js:146)
at HTMLButtonElement. (vendor.js:276)

while JS file should be attached to the code.

Kindly provide enough documentation to start using the library and migrating from original library.

bower library

I got used to bower, so I do not integrate anything in node environment but simply can attach bower configuration to my project.

It would be good to have bower version of the library.

Version 1.2.4 not working anymore on browsers

I upgraded my code to use the latest version of this library and while it still work fine under node, it stops working (it does not complete the connection) while running in the browser.

I think it has something to do with the way you handle the supported protocols but I've not yet been able to pinpoint exactly.

Multiple subscribes

hi
I want to use Multiple subscribes, like this:

connecting() {
        const socket = new SockJS('/rest/websocket/chat');
        this.stompClient = Stomp.over(socket);
        const headers = {};
        this.stompClient.connect(headers, this.onConnected());
    }

    onConnected() {
        
        this.stompClient.subscribe('/topic/channel/' + '1', (message) => {
         // SOMETHING TO DO
        });
        this.stompClient.subscribe('/topic/seenUpdate/' + '1', (message) => {
        // SOMETHING TO DO
        });
}

but when i run this, only my first subscribe work, here is the log on console.

>>> SUBSCRIBE
id:sub-1513079223083-564
destination:/topic/channel/1

so how can i make it work with multiple subscribe? btw i'm using Angular 4+ with webpack.
Thanks in advance

webstomp.over() not working from a callback

There is a problem when establishing connection over SockJS from a callback function. The original stomp client had the same issue.

The following code works

var ws = new SockJS(GLOBAL.apiUrl.replace('/v3', '') + '/notifications');
ws.onopen = function () {
    var client = webstomp.client('ws:/localhost/notifications');
    client.connect({}, function () {});
}

but if I replace webstomp.client(...); with webstomp.over(ws);, the client is stuck on "Opening Web Socket..." message.

Also this is not a scoping issue, because I can console.log the ws variable from within the callback. I have tried switching ws for this in the callback (as this in the context points to ws), but that does not work either.

Request: release with type definitions

Hi

Do you think you can do a release with the newly added type definitions?
Also I noticed that 1.0.4 is not available in npm registry.

Thanks
Murali

Support install via Bower

Hi, I'm using the original version by jmesnil via Bower. But that version is no longer maintained, and I want to move to your library.
Can you provide support to install your project via Bower? Thanks!

Escaping backslashes in headers

I have a use case where I need to send a backslash in a header of a SUBSCRIBE frame.

The STOMP specification states that:

C style string literal escapes are used to encode any colons and newlines that are found within the UTF-8 encoded headers. When decoding frame headers, the following transformations MUST be applied:

\n (octet 92 and 110) translates to newline (octet 10)
\c (octet 92 and 99) translates to : (octet 58)
\\ (octet 92 and 92) translates to \ (octet 92)

Currently, webstomp-client (as well as jmesnil's stomp-websocket) does not escape \ into \\:

Object.keys(this.headers).forEach(name => {
    let value = this.headers[name];
    lines.push(`${name}:${value}`);
});

What are your thoughts on this? Shouldn't this be implemented in the library, since it's something defined in the specification, and should therefore not a responsability of the client application?

Thanks.

Failed to parse TextMessage payload=[UNSUBSCRIB..]

I try to use stomp with spring backend, most of things works fine, but i get error with unsubscribe

o.s.w.s.m.StompSubProtocolHandler Failed to parse TextMessage payload=[UNSUBSCRIB..], byteCount=86, last=true] in session qa2pleno. Sending STOMP ERROR to client.

org.springframework.messaging.simp.stomp.StompConversionException: Illegal header: ' [native code]'. A header must be of the form :[].
at org.springframework.messaging.simp.stomp.StompDecoder.readHeaders(StompDecoder.java:224) ~[spring-messaging-4.2.7.RELEASE.jar:4.2.7.RELEASE]
at org.springframework.messaging.simp.stomp.StompDecoder.decodeMessage(StompDecoder.java:138) ~[spring-messaging-4.2.7.RELEASE.jar:4.2.7.RELEASE]
at org.springframework.messaging.simp.stomp.StompDecoder.decode(StompDecoder.java:111) ~[spring-messaging-4.2.7.RELEASE.jar:4.2.7.RELEASE]
at org.springframework.messaging.simp.stomp.BufferingStompDecoder.decode(BufferingStompDecoder.java:133) ~[spring-messaging-4.2.7.RELEASE.jar:4.2.7.RELEASE]
at org.springframework.web.socket.messaging.StompSubProtocolHandler.handleMessageFromClient(StompSubProtocolHandler.java:234) ~[spring-websocket-4.2.7.RELEASE.jar:4.2.7.RELEASE]
at org.springframework.web.socket.messaging.SubProtocolWebSocketHandler.handleMessage(SubProtocolWebSocketHandler.java:307) [spring-websocket-4.2.7.RELEASE.jar:4.2.7.RELEASE]
at org.springframework.web.socket.handler.WebSocketHandlerDecorator.handleMessage(WebSocketHandlerDecorator.java:75) [spring-websocket-4.2.7.RELEASE.jar:4.2.7.RELEASE]
at org.springframework.web.socket.handler.LoggingWebSocketHandlerDecorator.handleMessage(LoggingWebSocketHandlerDecorator.java:56) [spring-websocket-4.2.7.RELEASE.jar:4.2.7.RELEASE]
at org.springframework.web.socket.handler.ExceptionWebSocketHandlerDecorator.handleMessage(ExceptionWebSocketHandlerDecorator.java:58) [spring-websocket-4.2.7.RELEASE.jar:4.2.7.RELEASE]
at org.springframework.web.socket.sockjs.transport.session.AbstractSockJsSession.delegateMessages(AbstractSockJsSession.java:409) [spring-websocket-4.2.7.RELEASE.jar:4.2.7.RELEASE]
at org.springframework.web.socket.sockjs.transport.session.WebSocketServerSockJsSession.handleMessage(WebSocketServerSockJsSession.java:194) [spring-websocket-4.2.7.RELEASE.jar:4.2.7.RELEASE]
at org.springframework.web.socket.sockjs.transport.handler.SockJsWebSocketHandler.handleTextMessage(SockJsWebSocketHandler.java:92) [spring-websocket-4.2.7.RELEASE.jar:4.2.7.RELEASE]
at org.springframework.web.socket.handler.AbstractWebSocketHandler.handleMessage(AbstractWebSocketHandler.java:43) [spring-websocket-4.2.7.RELEASE.jar:4.2.7.RELEASE]
at org.springframework.web.socket.adapter.standard.StandardWebSocketHandlerAdapter.handleTextMessage(StandardWebSocketHandlerAdapter.java:110) [spring-websocket-4.2.7.RELEASE.jar:4.2.7.RELEASE]
at org.springframework.web.socket.adapter.standard.StandardWebSocketHandlerAdapter.access$000(StandardWebSocketHandlerAdapter.java:42) [spring-websocket-4.2.7.RELEASE.jar:4.2.7.RELEASE]
at org.springframework.web.socket.adapter.standard.StandardWebSocketHandlerAdapter$3.onMessage(StandardWebSocketHandlerAdapter.java:81) [spring-websocket-4.2.7.RELEASE.jar:4.2.7.RELEASE]
at org.springframework.web.socket.adapter.standard.StandardWebSocketHandlerAdapter$3.onMessage(StandardWebSocketHandlerAdapter.java:78) [spring-websocket-4.2.7.RELEASE.jar:4.2.7.RELEASE]
at org.apache.tomcat.websocket.WsFrameBase.sendMessageText(WsFrameBase.java:399) [tomcat-embed-websocket-8.0.36.jar:8.0.36]
at org.apache.tomcat.websocket.WsFrameBase.processDataText(WsFrameBase.java:500) [tomcat-embed-websocket-8.0.36.jar:8.0.36]
at org.apache.tomcat.websocket.WsFrameBase.processData(WsFrameBase.java:295) [tomcat-embed-websocket-8.0.36.jar:8.0.36]
at org.apache.tomcat.websocket.WsFrameBase.processInputBuffer(WsFrameBase.java:131) [tomcat-embed-websocket-8.0.36.jar:8.0.36]
at org.apache.tomcat.websocket.server.WsFrameServer.onDataAvailable(WsFrameServer.java:71) [tomcat-embed-websocket-8.0.36.jar:8.0.36]
at org.apache.tomcat.websocket.server.WsHttpUpgradeHandler$WsReadListener.onDataAvailable(WsHttpUpgradeHandler.java:185) [tomcat-embed-websocket-8.0.36.jar:8.0.36]
at org.apache.coyote.http11.upgrade.AbstractServletInputStream.onDataAvailable(AbstractServletInputStream.java:198) [tomcat-embed-core-8.0.36.jar:8.0.36]
at org.apache.coyote.http11.upgrade.AbstractProcessor.upgradeDispatch(AbstractProcessor.java:96) [tomcat-embed-core-8.0.36.jar:8.0.36]
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:647) [tomcat-embed-core-8.0.36.jar:8.0.36]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1520) [tomcat-embed-core-8.0.36.jar:8.0.36]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1476) [tomcat-embed-core-8.0.36.jar:8.0.36]
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [na:1.8.0_101]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [na:1.8.0_101]
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-8.0.36.jar:8.0.36]
at java.lang.Thread.run(Unknown Source) [na:1.8.0_101]

Implement a reconnect option

There is no really great way to reconnect available it seems.

I'm currently implementing a timeout which recreates the client after a failure. That just seems like a very poor approach. stomp should have some kind of autoreconnect.

Symbol is undefined after ws connected

After websocket connected the "Symbol" is undefined while using IE11.
And ws is not work.
image
When I use Chrome to connect ws, "Symbol" is a function.
image

location: /dist/webstomp.js line 757.

used npm to install the webstomp-client.
version: "webstomp-client": "^1.0.7"

Send text message on topic

Hello, can you please tell me if it is possible to send text messages to an ActiveMq Topic? I tried to do this but testing with a Java program it tells me that on the topic there is an ActiveMQBytesMessage not a TextMessage.
It is possible to do it directly from the javascript client or I had to call my server to send a text message to the topic?
Many thanks

WebSocket is not defined when running using electron

As per the documentation if i'm using node.js i need to use client.over with a specified websocket library (ws for example). But do i need to also do this if i'm making an electron app - because doesnt that have access to the browser style socket?

Whoops! Lost connection

Hi, vue2.0 use this client always Whoops! Lost connection
Can you help m ?

My Code :
Vue.use(webstomp)
Vue.use(Router)

let client = webstomp.client('ws://192.168.31.191:8080/gate/endpoint/websocket', {
heartbeat: {incoming: 2000, outgoing: 2000},
debug: true
})
client.connect({}, m => {
console.log(m)
if (client.connected) {
client.subscribe('/user/111111/auth', (message) => {
message.ack()
console.log('#############' + JSON.stringify(message))
}, {'ack': 'client'})
}
}, e => {
console.log(e)
})

WebSocket is not defined when running using node.js

ReferenceError: WebSocket is not defined
at Object.client (/Users/pongli/my/git/sandbox/JavaScript/ActivemqTest/node_modules/webstomp-client/dist/webstomp.js:881:18)
at Object. (/Users/pongli/my/git/sandbox/JavaScript/ActivemqTest/webstomp-client.js:12:23)

I think you may need to import ws.

Re-write connect

try to avoid all actual closures inside client.connect and also check if onopen is still ok if connect is called not immediately after ws creation #5

Error frame confusion

It looks like when an error frame is received, it is always handled by the connect error callback.

For example:

  1. CONNECT -- server returns success
  2. SUBSCRIBE -- server returns error response e.g. permission denied
  3. client calls CONNECT error callback

This is pretty confusing and hard to program against -- one would expect some sort of error callback related to the SUBSCRIBE for step 2 and 3.

Mismatch Between Sec-WebSocket-Protocol & accept-version

It's possible for the headers to state:

GET ws://myhost:8080/websocket HTTP/1.1
Host: myhost:8080
Connection: Upgrade
...
Sec-WebSocket-Protocol: v11.stomp, v12.stomp  // <-- only v1.1 and v1.2

But the CONNECT frame to state:

CONNECT
accept-version:1.2,1.1,1.0   // <-- Are we able to accept 1.0?

IMO, I don't think it's valid to declare the STOMP protocol on the Sec-WebSocket-Protocol header and then disregard it in the accept-version.

Issue found in v1.2.0.

Apparently broken when using over SockJS

Loving the ES6 and webpack. Unfortunately I cannot use yet. It seems it does not work over SockJS. I am working on a sample application based loosly on Rossen's here:

https://github.com/rstoyanchev/spring-websocket-portfolio/blob/master/src/main/webapp/static/js/services.js

All the internal refs appear to be null during creation (see the init function) leading to the first assign to fail I believe it was some binary thing. Not sure if you have tested this or not. I went back to the original one and it appears to be working fine.

Thanks,

Subscription to second channel overrides the first subscriber

This error happens when you send headers object to subscription method like this:

var headers = {'Authorization': `Bearer 123`};
var subscription1 = client.subscribe(destination1, callback1, headers);
var subscription2 = client.subscribe(destination2, callback2, headers);

If you do the second subscription you loose the reference to the first one (callback destination1 is never called). This issue came due to the fact that you break the atomicity rule:
https://github.com/JSteunou/webstomp-client/blob/master/src/client.js#L269

You should not manipulate object that are coming from outside.

Subscribing to non-durable Queues

Hi!
I'm working with RabbitMQ though CloudAMQP. I'm having my frontend connect to the service via your library and SockJS. I have two main queues that I want to be durable. A user on the frontend generates a random token and sends a request on one of those queues with the token. The server listens to those and publishes to a queue which is named by the token. It seems that the subscribe block in the frontend is creating the queue and making it durable. What headers do I set on the subscribe call so that the queue is not durable and auto-deletes? Here's what I attempted:

const ws = new SockJS('https://url.cloudamqp.com/stomp');
const client = webstomp.over(ws);
client.connect(username, password, () => {
  client.subscribe(token, callback, {"durable": false, "auto_delete": true});
}, failurecallback, vhost);

webstomp.over is not a function anymore?

Bumping from 1.2.0 and 1.2.2 I stared to get an exception saying webstomp.over is not a function.

    const WebSocket = require('ws'); // v5.2.1
    const webstomp = require('webstomp-client');

    const webSocket = new WebSocket('ws://127.0.0.1:15674/ws');
    // https://github.com/JSteunou/webstomp-client#overws-options
    const client = webstomp.over(webSocket, {debug: false}); // This line throws

Make a distinction between error frame and close event callback?

I check the souce code. And found that error frame and close event share the same callback.Shouldn't we use two different function since they are different case.For now i have to use connect failed callback function below:

function callback(evtOrFrame) {
    if (evtOrFrame) {
        if (evtOrFrame.hasOwnProperty("type") && evtOrFrame["type"] === "close") {
            //do something with close event obj
        } else if (evtOrFrame.command === "ERROR") {
            // do something with error frame obj
        }
    }
}

headerLines.reverse() error in stomp.js

undefined is not a function (evaluating 'headerLines.reverse()typeof Symbol === 'function' ? Symbol.iterator :'@@iterator'')

When I connect two android devices simultaneously, I encounter this error.

Please help me!

Thanks in advance.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.