【发布时间】:2014-10-01 03:00:30
【问题描述】:
我正在尝试使用 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 上编写了简单的测试,以查看后端中的所有设置是否正确。
但在这个测试中,我目前使用 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>
这个测试完全符合我的需要,但是在我尝试在实际项目中实现它之后,我无法使用 requireJS 加载 autobahn 0.8.2,它一直给我一个错误 ab 未定义。
我真的不明白发生了什么,根据autobahn getting started,它应该可以工作。
这是我在 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']
}
}
});
希望有人可以帮助我,我真的很喜欢让它工作!
任何帮助将不胜感激! 谢谢
【问题讨论】:
-
嘿,导致这两个错误的问题是什么?我正在使用 RatchetPHP 编写一个应用程序,并且在使用最新的 Autobahn 并使用他们的“getting sarted”时出现了相同的两个错误,但该应用程序似乎在 0.8.2 上运行良好:(
标签: websocket durandal durandal-2.0 autobahn autobahnws