我在chrome扩展中使用ddp和browserify包,通过ddp客户端与Meteor应用程序通信。
然而,当我实例化连接时,我遇到了错误:
Uncaught SyntaxError: Failed to execute 'connect' on 'WebSocket': The subprotocol '[object Object]' is invalid.创建new Websocket(uri='ws://localhost:3000/websocket', protocols={})时会发生这种情况
我在How to access app hosted on meteor.com by DDP (WebSocket) protocol?上看到了类似的错误,但他们必须将端口更改为443的解决方案不起作用。
有谁有变通办法吗?
发布于 2013-12-20 17:20:56
协议参数是可选的,必须是字符串或协议数组,如described here (在您的代码中提供了一个对象)
一旦解决了这个问题,显然你将需要附加所有其他的强制回调,通常是:
exampleSocket.onopen = function (event) {
exampleSocket.send("Here's some text that the server is urgently awaiting!");
};以及用于处理服务器消息的回调
exampleSocket.onmessage = function (event) {
console.log(event.data);
}https://stackoverflow.com/questions/20254129
复制相似问题