packages/browser-sync/lib/async.js
function(bs, done) {
        /**
         * An extra port is not needed in snippet/server mode
         */
        if (bs.options.get("mode") !== "proxy") {
            return done();
        }

        /**
         * Web socket support is disabled by default
         */
        if (!bs.options.getIn(["proxy", "ws"])) {
            return done();
        }

        /**
         * Use 1 higher than server port by default...
         */
        var socketPort = bs.options.get("port") + 1;

        /**
         * Or use the user-defined socket.port option instead
         */
        if (bs.options.hasIn(["socket", "port"])) {
            socketPort = bs.options.getIn(["socket", "port"]);
        }

        utils.getPort(bs.options.get("listen", "localhost"), socketPort, null, function(err, port) {
            if (err) {
                return utils.fail(true, err, bs.cb);
            }
            done(null, {
                optionsIn: [
                    {
                        path: ["socket", "port"],
                        value: port
                    }
                ]
            });
        });
    }
function(bs, done) {
        /**
         * An extra port is not needed in snippet/server mode
         */
        if (bs.options.get("mode") !== "proxy") {
            return done();
        }

        /**
         * Web socket support is disabled by default
         */
        if (!bs.options.getIn(["proxy", "ws"])) {
            return done();
        }

        /**
         * Use 1 higher than server port by default...
         */
        var socketPort = bs.options.get("port") + 1;

        /**
         * Or use the user-defined socket.port option instead
         */
        if (bs.options.hasIn(["socket", "port"])) {
            socketPort = bs.options.getIn(["socket", "port"]);
        }

        utils.getPort(bs.options.get("listen", "localhost"), socketPort, null, function(err, port) {
            if (err) {
                return utils.fail(true, err, bs.cb);
            }
            done(null, {
                optionsIn: [
                    {
                        path: ["socket", "port"],
                        value: port
                    }
                ]
            });
        });
    }
function ( bs , done ) { /**
         * An extra port is not needed in snippet/server mode
         */ if ( bs . options . get ( "mode" ) !== "proxy" ) { return done ( ) ; } /**
         * Web socket support is disabled by default
         */ if ( ! bs . options . getIn ( [ "proxy" , "ws" ] ) ) { return done ( ) ; } /**
         * Use 1 higher than server port by default...
         */ var socketPort = bs . options . get ( "port" ) + 1 ; /**
         * Or use the user-defined socket.port option instead
         */ if ( bs . options . hasIn ( [ "socket" , "port" ] ) ) { socketPort = bs . options . getIn ( [ "socket" , "port" ] ) ; } utils . getPort ( bs . options . get ( "listen" , "localhost" ) , socketPort , null , function ( err , port ) { if ( err ) { return utils . fail ( true , err , bs . cb ) ; } done ( null , { optionsIn : [ { path : [ "socket" , "port" ] , value : port } ] } ) ; } ) ; }
If the running mode is proxy, we'll use a separate port
for the Browsersync web-socket server. This is to eliminate any issues
with trying to proxy web sockets through to the users server.
@param bs
@param done
If the running mode is proxy we ll use a separate port for the Browsersync web - socket server . This is to eliminate any issues with trying to proxy web sockets through to the users server .