src/LiveDevelopment/LiveDevelopment.js
function open(restart) {
        // If close() is still pending, wait for close to finish before opening
        if (_isPromisePending(_closeDeferred)) {
            return _closeDeferred.then(function () {
                return open(restart);
            });
        }

        if (!restart) {
            // Return existing promise if it is still pending
            if (_isPromisePending(_openDeferred)) {
                return _openDeferred;
            } else {
                _openDeferred = new $.Deferred();
                _openDeferred.always(function () {
                    _openDeferred = null;
                });
            }
        }
        // Send analytics data when Live Preview is opened
        HealthLogger.sendAnalyticsData(
            "livePreviewOpen",
            "usage",
            "livePreview",
            "open"
        );

        // Register user defined server provider and keep handlers for further clean-up
        _regServers.push(LiveDevServerManager.registerServer({ create: _createUserServer }, 99));
        _regServers.push(LiveDevServerManager.registerServer({ create: _createFileServer }, 0));

        // TODO: need to run _onFileChanged() after load if doc != currentDocument here? Maybe not, since activeEditorChange
        // doesn't trigger it, while inline editors can still cause edits in doc other than currentDoc...
        _getInitialDocFromCurrent().done(function (doc) {
            var prepareServerPromise = (doc && _prepareServer(doc)) || new $.Deferred().reject(),
                otherDocumentsInWorkingFiles;

            if (doc && !doc._masterEditor) {
                otherDocumentsInWorkingFiles = MainViewManager.getWorkingSet(MainViewManager.ALL_PANES).length;
                MainViewManager.addToWorkingSet(MainViewManager.ACTIVE_PANE, doc.file);

                if (!otherDocumentsInWorkingFiles) {
                    MainViewManager._edit(MainViewManager.ACTIVE_PANE, doc);
                }
            }

            // wait for server (StaticServer, Base URL or file:)
            prepareServerPromise
                .done(function () {
                    var reverseInspectPref = PreferencesManager.get("livedev.enableReverseInspect"),
                        wsPort             = PreferencesManager.get("livedev.wsPort");
                        
                    if (wsPort && reverseInspectPref) {
                        WebSocketTransport.createWebSocketServer(wsPort);
                    }
                    _doLaunchAfterServerReady(doc);
                })
                .fail(function () {
                    _showWrongDocError();
                });
        });

        return _openDeferred.promise();
    }
function open(restart) {
        // If close() is still pending, wait for close to finish before opening
        if (_isPromisePending(_closeDeferred)) {
            return _closeDeferred.then(function () {
                return open(restart);
            });
        }

        if (!restart) {
            // Return existing promise if it is still pending
            if (_isPromisePending(_openDeferred)) {
                return _openDeferred;
            } else {
                _openDeferred = new $.Deferred();
                _openDeferred.always(function () {
                    _openDeferred = null;
                });
            }
        }
        // Send analytics data when Live Preview is opened
        HealthLogger.sendAnalyticsData(
            "livePreviewOpen",
            "usage",
            "livePreview",
            "open"
        );

        // Register user defined server provider and keep handlers for further clean-up
        _regServers.push(LiveDevServerManager.registerServer({ create: _createUserServer }, 99));
        _regServers.push(LiveDevServerManager.registerServer({ create: _createFileServer }, 0));

        // TODO: need to run _onFileChanged() after load if doc != currentDocument here? Maybe not, since activeEditorChange
        // doesn't trigger it, while inline editors can still cause edits in doc other than currentDoc...
        _getInitialDocFromCurrent().done(function (doc) {
            var prepareServerPromise = (doc && _prepareServer(doc)) || new $.Deferred().reject(),
                otherDocumentsInWorkingFiles;

            if (doc && !doc._masterEditor) {
                otherDocumentsInWorkingFiles = MainViewManager.getWorkingSet(MainViewManager.ALL_PANES).length;
                MainViewManager.addToWorkingSet(MainViewManager.ACTIVE_PANE, doc.file);

                if (!otherDocumentsInWorkingFiles) {
                    MainViewManager._edit(MainViewManager.ACTIVE_PANE, doc);
                }
            }

            // wait for server (StaticServer, Base URL or file:)
            prepareServerPromise
                .done(function () {
                    var reverseInspectPref = PreferencesManager.get("livedev.enableReverseInspect"),
                        wsPort             = PreferencesManager.get("livedev.wsPort");
                        
                    if (wsPort && reverseInspectPref) {
                        WebSocketTransport.createWebSocketServer(wsPort);
                    }
                    _doLaunchAfterServerReady(doc);
                })
                .fail(function () {
                    _showWrongDocError();
                });
        });

        return _openDeferred.promise();
    }
function open ( restart ) { // If close() is still pending, wait for close to finish before opening if ( _isPromisePending ( _closeDeferred ) ) { return _closeDeferred . then ( function ( ) { return open ( restart ) ; } ) ; } if ( ! restart ) { // Return existing promise if it is still pending if ( _isPromisePending ( _openDeferred ) ) { return _openDeferred ; } else { _openDeferred = new $ . Deferred ( ) ; _openDeferred . always ( function ( ) { _openDeferred = null ; } ) ; } } // Send analytics data when Live Preview is opened HealthLogger . sendAnalyticsData ( "livePreviewOpen" , "usage" , "livePreview" , "open" ) ; // Register user defined server provider and keep handlers for further clean-up _regServers . push ( LiveDevServerManager . registerServer ( { create : _createUserServer } , 99 ) ) ; _regServers . push ( LiveDevServerManager . registerServer ( { create : _createFileServer } , 0 ) ) ; // TODO: need to run _onFileChanged() after load if doc != currentDocument here? Maybe not, since activeEditorChange // doesn't trigger it, while inline editors can still cause edits in doc other than currentDoc... _getInitialDocFromCurrent ( ) . done ( function ( doc ) { var prepareServerPromise = ( doc && _prepareServer ( doc ) ) || new $ . Deferred ( ) . reject ( ) , otherDocumentsInWorkingFiles ; if ( doc && ! doc . _masterEditor ) { otherDocumentsInWorkingFiles = MainViewManager . getWorkingSet ( MainViewManager . ALL_PANES ) . length ; MainViewManager . addToWorkingSet ( MainViewManager . ACTIVE_PANE , doc . file ) ; if ( ! otherDocumentsInWorkingFiles ) { MainViewManager . _edit ( MainViewManager . ACTIVE_PANE , doc ) ; } } // wait for server (StaticServer, Base URL or file:) prepareServerPromise . done ( function ( ) { var reverseInspectPref = PreferencesManager . get ( "livedev.enableReverseInspect" ) , wsPort = PreferencesManager . get ( "livedev.wsPort" ) ; if ( wsPort && reverseInspectPref ) { WebSocketTransport . createWebSocketServer ( wsPort ) ; } _doLaunchAfterServerReady ( doc ) ; } ) . fail ( function ( ) { _showWrongDocError ( ) ; } ) ; } ) ; return _openDeferred . promise ( ) ; }
Open the Connection and go live

@param {!boolean} restart  true if relaunching and _openDeferred already exists
@return {jQuery.Promise} Resolves once live preview is open
Open the Connection and go live