Modules (188)

NodeSocketTransport

Description

Dependencies

Functions

Public API

getRemoteScript

Returns the script that should be injected into the browser to handle the other end of the transport.

Returns: string
    function getRemoteScript() {
        return "<script>\n" +
            NodeSocketTransportRemote +
            "this._Brackets_LiveDev_Socket_Transport_URL = 'ws://localhost:" + SOCKET_PORT + "';\n" +
            "</script>\n";
    }

    // Events

    // We can simply retrigger the events we receive from the node domain directly, since they're in
    // the same format expected by clients of the transport.

    ["connect", "message", "close"].forEach(function (type) {
        NodeSocketTransportDomain.on(type, function () {
            console.log("NodeSocketTransport - event - " + type + " - " + JSON.stringify(Array.prototype.slice.call(arguments, 1)));
            // Remove the event object from the argument list.
            exports.trigger(type, Array.prototype.slice.call(arguments, 1));
        });
    });

    EventDispatcher.makeEventDispatcher(exports);

    // Exports
    exports.getRemoteScript = getRemoteScript;

    // Proxy the node domain methods directly through, since they have exactly the same
    // signatures as the ones we're supposed to provide.
    ["start", "send", "close"].forEach(function (method) {
        exports[method] = function () {
            var args = Array.prototype.slice.call(arguments);
            args.unshift(method);
            console.log("NodeSocketTransport - " + args);
            NodeSocketTransportDomain.exec.apply(NodeSocketTransportDomain, args);
        };
    });

});