Javascript 插件sdk websocket保持断开连接

Javascript 插件sdk websocket保持断开连接,javascript,firefox,websocket,firefox-addon,firefox-addon-sdk,Javascript,Firefox,Websocket,Firefox Addon,Firefox Addon Sdk,我想在firefox扩展中打开到服务器的永久websocket连接。所以我在main.js中创建了页面mod _stickyInterface = pageWorker.Page({ contentURL : self.data.url('wsInterface.html') }); 界面如下所示: <html> <head> <script> //const HOST = 'ws://localhost:9099'; con

我想在firefox扩展中打开到服务器的永久websocket连接。所以我在main.js中创建了页面mod

_stickyInterface = pageWorker.Page({
    contentURL : self.data.url('wsInterface.html')
});
界面如下所示:

<html>
<head>
    <script>
    //const HOST = 'ws://localhost:9099';
    const HOST = 'ws://10.0.0.32:9099';
    // subprotocol-key: used when server handles communication of more applications.
    // With subprotocol is server able to delegate messages for this purpose
    //const STICKY_SUBPROTOCOL_KEY = "Myris_JsApi"; 
    const STICKY_SUBPROTOCOL_KEY = 'sticky-protocol';
    // internal identifier of this app
    const APP_KEY = "Myris_Chrome";

    var _connection = null;

    var _requestQueue = [];

    _connection = new WebSocket(HOST, STICKY_SUBPROTOCOL_KEY);

    _connection.onopen = function () {

        console.log("Sticky Interface: Connection opened.");
        var JSONObject = new Object;
        JSONObject.appKey = APP_KEY;

        _connection.send(JSON.stringify(JSONObject));
        console.log('sent');
    };

    _connection.onerror = function (evt) {
        console.log("Error ");
        console.log(evt);
        _connection.close();
    }

    //ok
    _connection.onclose = function (evt) {
        console.log("Close ");
        _connection.close();
    }

    _connection.onmessage = function(evt) {
        console.log('MESSAGE');
    }


    </script>
</head>
<body></body>
</html>
即使在那之后,也会有一些超时

"Error " StickyInterface.html:30
error { target: WebSocket, isTrusted: true, NONE: 0, CAPTURING_PHASE: 1, AT_TARGET: 2, BUBBLING_PHASE: 3, ALT_MASK: 1, CONTROL_MASK: 2, SHIFT_MASK: 4, META_MASK: 8, currentTarget: WebSocket } StickyInterface.html:31
"Close " StickyInterface.html:37
The connection to ws://10.0.0.32:9099/ was interrupted while the page was loading.     StickyInterface.html:17
GET http://localhost/extensions-dummy/blocklistURL [HTTP/1.1 404 Not Found 13ms]

连接失败,即使没有活动法师。使用freshy安装的Firefox 33。

电子邮件nils@mozilla.org他用网袋帮了很多忙。
"Error " StickyInterface.html:30
error { target: WebSocket, isTrusted: true, NONE: 0, CAPTURING_PHASE: 1, AT_TARGET: 2, BUBBLING_PHASE: 3, ALT_MASK: 1, CONTROL_MASK: 2, SHIFT_MASK: 4, META_MASK: 8, currentTarget: WebSocket } StickyInterface.html:31
"Close " StickyInterface.html:37
The connection to ws://10.0.0.32:9099/ was interrupted while the page was loading.     StickyInterface.html:17
GET http://localhost/extensions-dummy/blocklistURL [HTTP/1.1 404 Not Found 13ms]