1

I'm trying to implement autobahn 0.9.5 on my SPA project using DurandalJS.

        var ab = require('autobahn');

        live = new ab.Connection(
        {
            url: 'ws://localhost:8080',
            realm: 'realm1'
        });

        live.onopen = function(session, details)
        {
            console.log('Autobahn open successfully!', session);
        };

        live.onclose = function(reason, details)
        {
            console.log('Autobahn connection lost', reason + ' - ' + details);
        };

        live.open();

i received an error on firefox and chrome browser

Firefox:

 InvalidAccessError: A parameter or an operation is not supported by the underlying object
 websocket.close(code, reason);

Chrome:

WebSocket connection to 'ws://localhost:8080/' failed: Error during WebSocket handshake: Sent non-empty 'Sec-WebSocket-Protocol' header but no response was received 

I have no idea what happened..

BEFORE I STARTED WITH - autobahn 0.9.5

I have write simple test on test.html to see if everything setup in backend is correct.
But on this test i currently used autobahn 0.8.2

test.html

<script src="http://autobahn.s3.amazonaws.com/js/autobahn.min.js"></script>
<script>
    var conn = new ab.Session(

        // Websocket host
        'ws://localhost:8080',

        // Callback on connection established
        function() {
            // Once connect, subscribe to channel
            conn.subscribe('3', function(topic, data) {
                console.log(topic, data);              
            });
        },

        // Callback on connection close
        function() {
            console.warn('WebSocket connection closed');
        },

        // Additional AB parameters
        {'skipSubprotocolCheck': true}
    );
</script>

This test working perfectly as what i need, but after I try to implement it inside real project, I can't make autobahn 0.8.2 loaded using requireJS, It keep give me an error ab not defined.

I don't really understand what is happening, according of autobahn getting started, it should work.

and here is how I define it on main.js (requirejs paths and shim config)

requirejs.config({
  paths: {
      'autobahn'          : 'https://autobahn.s3.amazonaws.com/autobahnjs/latest/autobahn.min',
      'when'              : 'https://cdnjs.cloudflare.com/ajax/libs/when/2.7.1/when'
  },
  shim: {
     'autobahn': {
         deps: ['when']
     }
  }
});

Hopefully somebody can help me, I really love to make it working !

Any help will be greatly appreciated! Thanks

Fariz Azmi
  • 713
  • 1
  • 6
  • 21
  • Hey, what was the issue that was causing the two errors? I'm writing an app with RatchetPHP and I have the same two errors showing up when using latest Autobahn and playing with their 'getting sarted', but the app seems to be working fine with the 0.8.2 :( – Strayobject Oct 12 '15 at 00:23

1 Answers1

1

Probably late, but for further reference.

This is probably not a complete answer to SO question.

First of all, everything should be written either for AutobahnJS v0.8.2 (which supports WAMPv1) or for AutobahnJS v0.9.5 (WAMPv2).

Check API documentation.

WAMP v1

WAMP v2

Vladimir Vukanac
  • 944
  • 16
  • 29
  • Thanks @MrW, I've successfully make it work! Things causes I was unable to connect (with error returned) is something we missed on backend stuff. So, i vote you up for a good reference! – Fariz Azmi Dec 16 '14 at 03:35
  • Thank you! That is helped a lot for clear stuff for my self also, after a lot of reading. – Vladimir Vukanac Dec 16 '14 at 10:36