Autobahn 0.9.5(AMD)-WebSocket握手过程中出错



我正试图使用DurandalJS在我的SPA项目上实现高速公路0.9.5

        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();

我在firefox和chrome浏览器上收到一个错误

Firefox:

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

铬:

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

我不知道发生了什么。。

在我开始使用-高速公路0.9.5之前

我在test.html上写了一个简单的测试,看看后端的所有设置是否正确
但在这次测试中,我目前使用高速公路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>

这个测试完全符合我的需求,但在我尝试在实际项目中实现它之后,我无法使用requireJS加载autobahn 0.8.2,它一直给我一个错误ab未定义

我真的不明白发生了什么,根据高速公路的起步,它应该起作用。

以下是我如何在main.js(requirejs路径和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']
     }
  }
});

希望有人能帮助我,我真的很想让它发挥作用!

任何帮助都将不胜感激!感谢

可能晚了,但供进一步参考。

这可能不是SO问题的完整答案。

首先,所有内容都应该为AutobahnJS v0.8.2(支持WAMPv1)或AutobahnJSv0.9.5(WAMPv2)编写。

查看API文档。

WAMP v1

  • 高速公路JS v0.8.2 API-http://autobahn.ws/js/reference_wampv1.html
  • 它从加载http://autobahn.s3.amazonaws.com/js/autobahn.js
  • 高速公路的全局变量是ab
  • var conn = new ab.Session(wuri, onOpenCallback, onCloseCallback, options);连接

WAMP v2

  • 高速公路JS v0.9.5 API-http://autobahn.ws/js/reference.html
  • 它从加载https://autobahn.s3.amazonaws.com/autobahnjs/latest/autobahn.min.jgz
  • 高速公路的全局变量是高速公路
  • new autobahn.Connection({url: wuri, realm: yourRealm});连接

最新更新