繁体   English   中英

Autobahn 0.9.5(AMD)-WebSocket握手期间出错

[英]Autobahn 0.9.5 (AMD) - Error during WebSocket handshake

我正在尝试使用DurandalJS在我的SPA项目上实现autobahn 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浏览器上收到错误消息

火狐:

 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配置)

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)或为AutobahnJS v0.9.5(WAMPv2)编写所有内容。

查看API文档。

WAMP v1

WAMP v2

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM