Wampy.js - Simple WAMP Javascript client-side implementation

1,045 views
Skip to first unread message

Konstantin Burkalev

unread,
Feb 10, 2014, 2:08:46 PM2/10/14
to wam...@googlegroups.com
Hi, guys!

I made another JS client-side implementation of a WAMP v1.

I've tested it with ratchet php (btw, fixed some bugs there :) ) and it works pretty well.


Any comments and feedback are appreciated. 

It could also be great, to list it on http://wamp.ws/implementations/

BTW, i'll have a look at WAMP v2 spec :)


Alexander Gödde

unread,
Feb 11, 2014, 12:26:28 PM2/11/14
to wam...@googlegroups.com
Cool! Added wampy.js to the list of implementations!

Konstantin Burkalev

unread,
Feb 12, 2014, 1:17:19 PM2/12/14
to wam...@googlegroups.com
Yeah! Thanks!

Konstantin Burkalev

unread,
Mar 8, 2014, 4:17:43 PM3/8/14
to wam...@googlegroups.com
Hi, Alexander!

I've updated wampy.js for v2 spec. It implements 3 roles: publisher, subscriber and caller with basic profile.
I've tested basic functionality with AutobahnPython - looks good.

Could you update http://wamp.ws/implementations/ for new version ? :)

Tobias Oberstein

unread,
Mar 8, 2014, 4:41:04 PM3/8/14
to wam...@googlegroups.com
Hello Konstantin,

> I've updated wampy.js for v2 spec. It implements 3 roles: publisher,
> subscriber and caller with basic profile.

Awesome!! Wampy is now officially the first 3rd party WAMP v2
implementation;)

I've had a short look .. Wampy supports both JSON and MsgPack
serialization, right? Cool. MsgPack is currently still missing in
AutobahnJS. Could you test MsgPack with AutobahnPython?

Also: could you give a short statement in which aspects you would see
Wampy being different or at advantage compared to AutobahnJS?

Don't get me wrong: I absolutely welcome a 2nd JS WAMPv2 implementation!
But it could help developers to make an informed decision which library
to use ..

Cheers,
/Tobias

> I've tested basic functionality with AutobahnPython - looks good.
>
> Could you update http://wamp.ws/implementations/
> <http://wamp.ws/implementations/> for new version ? :)
>
> --
> You received this message because you are subscribed to the Google
> Groups "WAMP" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to wampws+un...@googlegroups.com
> <mailto:wampws+un...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout.

Konstantin Burkalev

unread,
Mar 9, 2014, 5:12:05 AM3/9/14
to wam...@googlegroups.com
Hi, Tobias!

> Awesome!! Wampy is now officially the first 3rd party WAMP v2 
implementation;) 

Thats great! :)

Well, i've just tried to use msgpack with AutobahnPython, but have no luck. May be you can advice me what i am doing wrong...
Do i need to do something special to use msgpack in AutobahnPython?
My first step was to send both subprotocols during web socket handshake: 
  1. Sec-WebSocket-Protocol:
    wamp.2.json, wamp.2.msgpack
In this case server selects wamp.2.json, that's all.
If i try to send only wamp.2.msgpack as subprotocol, i am receiving 
WebSocket connection to 'ws://127.0.0.1:8080/ws' failed: Error during WebSocket handshake: Unexpected response code: 400 

And thats all.

Also: could you give a short statement in which aspects you would see 
> Wampy being different or at advantage compared to AutobahnJS?
> Don't get me wrong: I absolutely welcome a 2nd JS WAMPv2 implementation!

Yeah. It's a good idea. I'll try to formulate my thoughts about that. 

Tobias Oberstein

unread,
Mar 9, 2014, 9:12:18 AM3/9/14
to wam...@googlegroups.com
> Well, i've just tried to use msgpack with AutobahnPython, but have no
> luck. May be you can advice me what i am doing wrong...
> Do i need to do something special to use msgpack in AutobahnPython?
> My first step was to send both subprotocols during web socket handshake:
>
> 1.
> Sec-WebSocket-Protocol:
> wamp.2.json, wamp.2.msgpack

You should send

wamp.2.msgpack, wamp.2.json

since the server will select the first subprotocol announced by the
client it supports.

Hers is how you can test that with AutobahnPython.

Make sure you have the necessary deps installed:

pip install --upgrade autobahn[twisted,msgpack]

Then, open 2 terminals and:

Terminal 1:

cd AutobahnPython/examples/twisted/wamp/basic
python server.py -d --component "rpc.timeservice.backend.Component"

Terminal 2:

cd AutobahnPython/examples/twisted/wamp/basic
python client.py -d --component "rpc.timeservice.frontend.Component"

This should result in logs (also see attached screenshot):

Log 2:

2014-03-09 14:07:03+0100 [Uninitialized] GET /ws HTTP/1.1
User-Agent: AutobahnPython/0.8.4-3
Host: 127.0.0.1:8080
Upgrade: WebSocket
Connection: Upgrade
Pragma: no-cache
Cache-Control: no-cache
Sec-WebSocket-Key: XlQLvqzCgyQylV5XucgzPg==
Sec-WebSocket-Protocol: wamp.2.msgpack,wamp.2.json
Sec-WebSocket-Version: 13

...
2014-03-09 14:07:04+0100 [WampWebSocketClientProtocol,client] received
HTTP response:

HTTP/1.1 101 Switching Protocols
Server: AutobahnPython/0.8.4-3
Upgrade: WebSocket
Connection: Upgrade
Sec-WebSocket-Protocol: wamp.2.msgpack
Sec-WebSocket-Accept: +3dFCFU/I8TE8vW9mPxSveJSjuI=

>
> In this case server selects wamp.2.json, that's all.
> If i try to send only wamp.2.msgpack as subprotocol, i am receiving
> WebSocket connection to 'ws://127.0.0.1:8080/ws' failed: Error during
> WebSocket handshake: Unexpected response code: 400
>
> And thats all.

If you enable debug on the server, you should see the actual reason (eg
the "-d" option in above example enables debug log output) ..

>
>>Also: could you give a short statement in which aspects you would see
> > Wampy being different or at advantage compared to AutobahnJS?
> > Don't get me wrong: I absolutely welcome a 2nd JS WAMPv2 implementation!
>
> Yeah. It's a good idea. I'll try to formulate my thoughts about that.
>
Clipboard01.png

Tobias Oberstein

unread,
Mar 9, 2014, 9:27:23 AM3/9/14
to wam...@googlegroups.com
Done.

Konstantin Burkalev

unread,
Mar 9, 2014, 5:03:37 PM3/9/14
to wam...@googlegroups.com
Thanks, Tobias, for advice!

I've got web socket to switch to wamp.2.msgpack :) 
But then i've faced another problem: there is no working browser javascript msgpack implementation :(
At first, i had tried to use official https://github.com/msgpack/msgpack-javascript but i think this repo is abandoned, last commit is 3 years old. Of course it doesn't know about v5 spec. But even without it, this lib cannot decode wamp_features object, received in welcome message.


Then i had tried to find another lib. The only one, which i'd found was - https://github.com/creationix/msgpack-js-browser
But with this library i also had no luck. This time it does not understand hash-table object and interprets it as ArrayBuffer

I'll try to examine and fix this, but may be you know another working libs/code? How do you plan to make support for msgpack in your library? Do you wanna write your own implementation or use something external?


Tobias Oberstein

unread,
Mar 9, 2014, 5:20:06 PM3/9/14
to wam...@googlegroups.com
Hi Konstantin,

Am 09.03.2014 22:03, schrieb Konstantin Burkalev:
> Thanks, Tobias, for advice!
>
> I've got web socket to switch to wamp.2.msgpack :)

Great!

> But then i've faced another problem: there is no working browser
> javascript msgpack implementation :(

Mmh .. not good.

> At first, i had tried to use official
> https://github.com/msgpack/msgpack-javascript but i think this repo is
> abandoned, last commit is 3 years old. Of course it doesn't know about
> v5 spec. But even without it, this lib cannot decode wamp_features
> object, received in welcome message.
>
> <https://lh6.googleusercontent.com/-w-jPQqxZdp0/UxzTkUi0N9I/AAAAAAAAH6w/s9tLJhCd26g/s1600/msgpack.decode.png>
>
>
> Then i had tried to find another lib. The only one, which i'd found was
> - https://github.com/creationix/msgpack-js-browser
> But with this library i also had no luck. This time it does not
> understand hash-table object and interprets it as ArrayBuffer
>
> <https://lh6.googleusercontent.com/-yXHl_M80NxY/UxzWCax8YbI/AAAAAAAAH68/VqLiV8o-36g/s1600/msgpack.err2.png>
>

I would expect the Python MsgPack library used by AutobahnPython

https://github.com/msgpack/msgpack-python

to be fully compliant to the spec V5 ... but I did not test it. So bugs
could be there also. Probably less likely than bugs in above, but could be.

> I'll try to examine and fix this, but may be you know another working
> libs/code? How do you plan to make support for msgpack in your library?
> Do you wanna write your own implementation or use something external?

To be honest, I just "assumed" there would be at least one working
library for a serialization format as widely used as MsgPack. Well,
seems not so easy.

I am not keen on writing one, but if necessary, it should be possible in
roughly 1k lines of code .. so 2 days work should be sufficient to write
one from scratch.

Probably start by "steeling" from the creationix repo or fix issues
remaining in

https://www.npmjs.org/package/msgpack-js-v5

We definitely do need:

- MsgPack V5
- Browser _and_ Nodejs

Thanks for testing and feedback here .. pls keep me updated on your
findings!

Cheers,
/Tobias

Konstantin Burkalev

unread,
Mar 10, 2014, 8:52:36 AM3/10/14
to wam...@googlegroups.com
Hehey! It's me again :)

I've continued my investigations in msgpack and reached the following:
1) I forked creationix/msgpack-js-browser into https://github.com/KSDaemon/msgpack-js-browser
2) Make some code review and refactoring based on https://github.com/chakrit/msgpack-js (this one with v5 support, but for node.js)
3) While coding, i've found, that there is no support for big integers, probably because of there are no such methods in native browser DataView object (see https://developer.mozilla.org/en-US/docs/Web/API/DataView). So i've found great lib jDataView (https://github.com/jDataView/jDataView), and extended msgpack-js-browser.
4) Also there were some tests, i've updated them a little, not all, but acceptable for this time. You can open tests/index.html to see. (branch: int64support, not master)
5) Added jDataView as git submodule.
6) I've tried to use this brand new msgpack lib with wampy and AutobahnPython. As i can see, on decoding step, every time i am falling into bin8 case while trying to decode key name of wamp server features object, instead of string. (line 240 of msgpack.js). But in browser tests encoding/decoding goes well. 

The next steps are: try to research msgpack-python or try to use some other msgpack libs and somehow transport this binary data to browser to test it with msgpack-js-browser



To be honest, I just "assumed" there would be at least one working
library for a serialization format as widely used as MsgPack. Well,
seems not so easy.
Yeah, i thought so until, you know... 
 
That's it...

Konstantin Burkalev

unread,
Mar 10, 2014, 9:04:38 AM3/10/14
to wam...@googlegroups.com
I've just pushed https://github.com/KSDaemon/wampy.js/tree/msgpack-support branch, where all latest code is. 
So if someone else wants to check/fix msgpack issue - welcome!

You need page with all scripts included
<script src="jdataview.js"></script>
<script src="msgpack.js"></script>
<script src="wampy.js"></script>

and then in console try to connect to wamp server, like so:
var ws = new Wampy('ws://127.0.0.1:8080/ws', { realm: 'test1', transportEncoding: 'msgpack'});

after successful connection dump ws._cache.server_wamp_features. It should contain hash-table. 

Right now it contains [object ArrayBuffer]: Object > [object ArrayBuffer]: Object > [object ArrayBuffer]: Object ....


Tobias Oberstein

unread,
Mar 10, 2014, 12:36:26 PM3/10/14
to wam...@googlegroups.com
Am 10.03.2014 13:52, schrieb Konstantin Burkalev:
> Hehey! It's me again :)

Hi Konstantin,

>
> I've continued my investigations in msgpack and reached the following:
> 1) I forked creationix/msgpack-js-browser
> into https://github.com/KSDaemon/msgpack-js-browser
> 2) Make some code review and refactoring based
> on https://github.com/chakrit/msgpack-js (this one with v5 support, but
> for node.js)

Did you push your changes to

https://github.com/KSDaemon/msgpack-js-browser

? Since I can't see new commits (last one is 9 months old ..)

> 3) While coding, i've found, that there is no support for big integers,
> probably because of there are no such methods in native browser DataView

Might be. JavaScript represents _all_ numbers a IEEE double internally
.. which limits the integer range that can be fully represented.

> object (see https://developer.mozilla.org/en-US/docs/Web/API/DataView).

Yeah, also lacks UInt64 ..

> So i've found great lib jDataView
> (https://github.com/jDataView/jDataView), and extended msgpack-js-browser.

you mean https://github.com/jDataView/jDataView/wiki/64-bit-integers ??


> 4) Also there were some tests, i've updated them a little, not all, but
> acceptable for this time. You can open tests/index.html to see.
> (branch: int64support, not master)
> 5) Added jDataView as git submodule.
> 6) I've tried to use this brand new msgpack lib with wampy and
> AutobahnPython. As i can see, on decoding step, every time i am falling
> into bin8 case while trying to decode key name of wamp server features
> object, instead of string. (line 240 of msgpack.js). But in browser
> tests encoding/decoding goes well.

Probably easier to test "manually" (outside of AutobahnPython):

$ python
Python 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import msgpack
>>> msgpack.packb("hello", use_bin_type = True)
'\xc4\x05hello'
>>> import binascii
>>> binascii.hexlify(msgpack.packb("hello", use_bin_type = True))
'c40568656c6c6f'
>>> binascii.hexlify(msgpack.packb({"a": "my", "b": "awesome", "c":
"dict", "d": 23}, use_bin_type = True))
'84c40161c4026d79c40163c40464696374c40162c407617765736f6d65c4016417'
>>>


Mmmh. And also:

>>> binascii.hexlify(msgpack.packb({"a": 23}, use_bin_type = True))
'81c4016117'
>>> binascii.hexlify(msgpack.packb({u"a": 23}, use_bin_type = True))
'81a16117'
>>> v1 = msgpack.packb({u"a": 23}, use_bin_type = True)
>>> msgpack.unpackb(v1, encoding = 'utf-8')
{u'a': 23}
>>> v2 = msgpack.packb({"a": 23}, use_bin_type = True)
>>> msgpack.unpackb(v2, encoding = 'utf-8')
{'a': 23}
>>> v1 == v2
False
>>>

the lower-case "u" before a string literal marks the literal as Unicode.

I am wondering if there is an issue with Unicode literals ..

Could you check if you can decode / roundtrip above?

https://github.com/tavendo/AutobahnPython/blob/master/autobahn/autobahn/wamp/serializer.py#L178



>
> The next steps are: try to research msgpack-python or try to use some
> other msgpack libs and somehow transport this binary data to browser to
> test it with msgpack-js-browser
>
>
>
> To be honest, I just "assumed" there would be at least one working
> library for a serialization format as widely used as MsgPack. Well,
> seems not so easy.
>
> Yeah, i thought so until, you know...
> That's it...
>

Konstantin Burkalev

unread,
Mar 10, 2014, 1:51:11 PM3/10/14
to wam...@googlegroups.com

Did you push your changes to

https://github.com/KSDaemon/msgpack-js-browser

? Since I can't see new commits (last one is 9 months old ..)

Yeah. Just check the int64support branch, not master. 'Cause the work is not over, i decided not to merge this in main branch. 
 
> 3) While coding, i've found, that there is no support for big integers,
> probably because of there are no such methods in native browser DataView

Might be. JavaScript represents _all_ numbers a IEEE double internally
.. which limits the integer range that can be fully represented.

> object (see https://developer.mozilla.org/en-US/docs/Web/API/DataView).

Yeah, also lacks UInt64 ..

> So i've found great lib jDataView
> (https://github.com/jDataView/jDataView), and extended msgpack-js-browser.

you mean https://github.com/jDataView/jDataView/wiki/64-bit-integers ??

Yes. While debugging msgpack/wampy/AutobahnPython i saw that msgpack falls into that type of encoded data and resulted in fail, so this was the easy way to fix that.


Probably easier to test "manually" (outside of AutobahnPython):  
 Could you check if you can decode / roundtrip above? 

Message has been deleted

Konstantin Burkalev

unread,
Mar 15, 2014, 4:06:03 AM3/15/14
to wam...@googlegroups.com
Hi Tobias!
How are you?

Just for relax time i've extended my wampy.js and added some [stable] advanced features.

Wampy.js now supports next WAMP roles and features:

  • publisher: advanced profile with features:
    • subscriber blackwhite listing
    • publisher exclusion
    • publisher identification
  • subscriber: basic profile.
  • caller: advanced profile with features:
    • callee blackwhite listing.
    • caller exclusion.
    • caller identification.
  • callee: basic profile.

Also i added some thoughts about difference between Wampy and AutobahnJS, which you can find in docs at: https://github.com/KSDaemon/wampy.js#quick-comparison-to-other-libs

Please, take a look. May be you have some remarks. Feel free to discuss.

Also, could you update wampy info on http://wamp.ws/implementations/ page.

Well, i'll continue investigation on msgpack. We need to win! :)

Tobias Oberstein

unread,
Mar 15, 2014, 6:51:58 AM3/15/14
to wam...@googlegroups.com
Hi Konstantin,

Am 15.03.2014 09:04, schrieb Konstantin Burkalev:
> Hi Tobias!
> How are you?

Overworked;)

>
> Just for relax time i've extended my wampy.js and added some [stable]
> advanced features.
>
> Wampy.js now supports next WAMP roles and features:
>
> * publisher: advanced profile with features:
> o subscriber blackwhite listing
> o publisher exclusion
> o publisher identification
> * subscriber: basic profile.
> * caller: advanced profile with features:
> o callee blackwhite listing.
> o caller exclusion.
> o caller identification.
> * callee: basic profile.
>


Awesome!!

I've updated the WAMP web site accordingly.


>
> Also i add some thoughts about difference between Wampy and AutobahnJS,
> which you can found in docs at:
> https://github.com/KSDaemon/wampy.js#quick-comparison-to-other-libs
>
> Please, take a look. May be you have some remarks. Feel free to discuss.


This is nice (in particular):

"Also Wampy is clever enough to understand some specific options, for
example, if you specify a success or error callback to publish method,
Wampy will automatically set acknowledge flag to true."

Possible since Wampy opts for callbacks instead of promises ..

I think the comparison table gives users a good basis for choosing.

From my perspective, the most fundamental difference is:

- wampy uses callbacks
- AutobahnJS uses Promises

Both approaches are fine .. and a developer can use what he likes.
Choice and freedom is good.

>
> Also, could you update wampy info on http://wamp.ws/implementations/ page.

Done.

>
> Well, i'll continue investigation on msgpack. We need to win! :)

Yes, I'd be very interested in that also for AutobahnJS .. obviously.
And I have a bit of bad consciousness for not trying your branch .. but
I have enough work already for a 48h day;)

Cheers,
/Tobias

Konstantin Burkalev

unread,
Mar 15, 2014, 9:42:01 AM3/15/14
to wam...@googlegroups.com


суббота, 15 марта 2014 г., 14:51:58 UTC+4 пользователь Tobias Oberstein написал:
Hi Konstantin,

Am 15.03.2014 09:04, schrieb Konstantin Burkalev:
> Hi Tobias!
> How are you?

Overworked;)
O,Yeah!
Yep. I've tried just to show the difference. 

Which one library to use - choice is yours!
  

>
> Also, could you update wampy info on http://wamp.ws/implementations/ page.

Done.

Great! Thanks!

Tobias Oberstein

unread,
Mar 15, 2014, 3:04:58 PM3/15/14
to wam...@googlegroups.com
Hi Konstantin,

OT: just stumbled over

http://youtu.be/VloIE0_W-78?t=16m1s

Not that I understand anything .. but .. WAMP;)

/Tobias

Konstantin Burkalev

unread,
Mar 16, 2014, 3:25:27 AM3/16/14
to wam...@googlegroups.com
Haha! Wow!

I know that conf. 

Well, speaker says about wamp, especially about v1 version and its implementations in most of the languages, and Tavendo, and your full Autobahn stack. 
That's great, i think! 

суббота, 15 марта 2014 г., 23:04:58 UTC+4 пользователь Tobias Oberstein написал:
Reply all
Reply to author
Forward
0 new messages