src/LiveDevelopment/MultiBrowserImpl/transports/remote/NodeSocketTransportRemote.js
function (url) {
            var self = this;
            this._ws = new WebSocket(url);

            // One potential source of confusion: the transport sends two "types" of messages -
            // these are distinct from the protocol's own messages. This is because this transport
            // needs to send an initial "connect" message telling the Brackets side of the transport
            // the URL of the page that it's connecting from, distinct from the actual protocol
            // message traffic. Actual protocol messages are sent as a JSON payload in a message of
            // type "message".
            //
            // Other transports might not need to do this - for example, a transport that simply
            // talks to an iframe within the same process already knows what URL that iframe is
            // pointing to, so the only comunication that needs to happen via postMessage() is the
            // actual protocol message strings, and no extra wrapping is necessary.

            this._ws.onopen = function (event) {
                // Send the initial "connect" message to tell the other end what URL we're from.
                self._ws.send(JSON.stringify({
                    type: "connect",
                    url: global.location.href
                }));
                console.log("[Brackets LiveDev] Connected to Brackets at " + url);
                if (self._callbacks && self._callbacks.connect) {
                    self._callbacks.connect();
                }
            };
            this._ws.onmessage = function (event) {
                console.log("[Brackets LiveDev] Got message: " + event.data);
                if (self._callbacks && self._callbacks.message) {
                    self._callbacks.message(event.data);
                }
            };
            this._ws.onclose = function (event) {
                self._ws = null;
                if (self._callbacks && self._callbacks.close) {
                    self._callbacks.close();
                }
            };
            // TODO: onerror
        }
function (url) {
            var self = this;
            this._ws = new WebSocket(url);

            // One potential source of confusion: the transport sends two "types" of messages -
            // these are distinct from the protocol's own messages. This is because this transport
            // needs to send an initial "connect" message telling the Brackets side of the transport
            // the URL of the page that it's connecting from, distinct from the actual protocol
            // message traffic. Actual protocol messages are sent as a JSON payload in a message of
            // type "message".
            //
            // Other transports might not need to do this - for example, a transport that simply
            // talks to an iframe within the same process already knows what URL that iframe is
            // pointing to, so the only comunication that needs to happen via postMessage() is the
            // actual protocol message strings, and no extra wrapping is necessary.

            this._ws.onopen = function (event) {
                // Send the initial "connect" message to tell the other end what URL we're from.
                self._ws.send(JSON.stringify({
                    type: "connect",
                    url: global.location.href
                }));
                console.log("[Brackets LiveDev] Connected to Brackets at " + url);
                if (self._callbacks && self._callbacks.connect) {
                    self._callbacks.connect();
                }
            };
            this._ws.onmessage = function (event) {
                console.log("[Brackets LiveDev] Got message: " + event.data);
                if (self._callbacks && self._callbacks.message) {
                    self._callbacks.message(event.data);
                }
            };
            this._ws.onclose = function (event) {
                self._ws = null;
                if (self._callbacks && self._callbacks.close) {
                    self._callbacks.close();
                }
            };
            // TODO: onerror
        }
function ( url ) { var self = this ; this . _ws = new WebSocket ( url ) ; // One potential source of confusion: the transport sends two "types" of messages - // these are distinct from the protocol's own messages. This is because this transport // needs to send an initial "connect" message telling the Brackets side of the transport // the URL of the page that it's connecting from, distinct from the actual protocol // message traffic. Actual protocol messages are sent as a JSON payload in a message of // type "message". // // Other transports might not need to do this - for example, a transport that simply // talks to an iframe within the same process already knows what URL that iframe is // pointing to, so the only comunication that needs to happen via postMessage() is the // actual protocol message strings, and no extra wrapping is necessary. this . _ws . onopen = function ( event ) { // Send the initial "connect" message to tell the other end what URL we're from. self . _ws . send ( JSON . stringify ( { type : "connect" , url : global . location . href } ) ) ; console . log ( "[Brackets LiveDev] Connected to Brackets at " + url ) ; if ( self . _callbacks && self . _callbacks . connect ) { self . _callbacks . connect ( ) ; } } ; this . _ws . onmessage = function ( event ) { console . log ( "[Brackets LiveDev] Got message: " + event . data ) ; if ( self . _callbacks && self . _callbacks . message ) { self . _callbacks . message ( event . data ) ; } } ; this . _ws . onclose = function ( event ) { self . _ws = null ; if ( self . _callbacks && self . _callbacks . close ) { self . _callbacks . close ( ) ; } } ; // TODO: onerror }
Connects to the NodeSocketTransport in Brackets at the given WebSocket URL.
@param {string} url
Connects to the NodeSocketTransport in Brackets at the given WebSocket URL .