2013-11-27 37 views
1

我在chrome擴展中使用了ddpbrowserify包,通過ddp客戶端與Meteor應用進行通話。DDP,Node和Chrome Browserify

然而,當我實例連接,我橫跨錯誤運行:

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無法正常工作。

有沒有人有解決方法?

+0

省略第二參數回調,或者將其更改爲'[]' – rsanchez

+0

當我這樣做時,當試圖用self.socket.on('open',func ...) – user592419

+0

打開套接字時,我得到一個'TypeError:Object#'on''沒有方法。它有onopen,onclose等方法。 – user592419

回答

0

的協議參數是可選的,而且必須是一個字符串或協議的數組作爲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); 
}