client/shotgun.client.js
function (options) {

      var clientShell = this,
      context = {},
      // Default settings.
      defaultSettings = {
        namespace: 'shotgun',
        debug: false
      };

      // Override default settings with supplied options.
      var settings = clientShell.settings = extend(true, {}, defaultSettings, options);

      // Instruct socket.io to connect to the server.
      var socket = clientShell.socket = io.connect('/' + settings.namespace);

      // Proxy any listeners onto the socket itself.
      clientShell.on = function () {
        socket.on.apply(socket, arguments);
        return clientShell;
      };

      // Proxy any emit calls onto the socket itself.
      clientShell.emit = function () {
        socket.emit.apply(socket, arguments);
        return clientShell;
      };

      function getCookies() {
        var cookies = {};
        if (document.cookie.length > 0)
          document.cookie.split(';').forEach(function (cookie) {
            var components = cookie.split('='),
            name = components[0].trim(),
            value = components[1];
            if (name.indexOf(settings.namespace + '-') === 0) {
              name = name.replace(settings.namespace + '-', '');
              cookies[name] = decodeURIComponent(value);
            }
          });
          return cookies;
      }

      clientShell
      // Save context when it changes.
      .on('contextChanged', function (contextData) {
        context = contextData;
      })
      // Create a function for setting cookies in the browser.
      .on('setCookie', function (name, value, days) {
        var expiration = new Date();
        expiration.setDate(expiration.getDate() + days);
        value = encodeURIComponent(value) + ((days === null) ? "" : ";expires=" + expiration.toUTCString());
        document.cookie = settings.namespace + '-' + name + "=" + value;
      })
      .on('getCookie', function (name, callback) {
        // Create a cookies property on the context and fill it with all the cookies for this shell.
        var cookies = getCookies();
        callback(cookies[name]);
      })
      .on('getAllCookies', function (callback) {
        var cookies = getCookies();
        callback(cookies);
      });

      // Create an execute function that looks similar to the shotgun shell execute function for ease of use.
      clientShell.execute = function (cmdStr, contextOverride, options) {
        // If a context was passed in then override the stored context with it.
        if (contextOverride) context = contextOverride;
        socket.emit('execute', cmdStr, context, options);
        return clientShell;
      };

      return clientShell;
    }
function (options) {

      var clientShell = this,
      context = {},
      // Default settings.
      defaultSettings = {
        namespace: 'shotgun',
        debug: false
      };

      // Override default settings with supplied options.
      var settings = clientShell.settings = extend(true, {}, defaultSettings, options);

      // Instruct socket.io to connect to the server.
      var socket = clientShell.socket = io.connect('/' + settings.namespace);

      // Proxy any listeners onto the socket itself.
      clientShell.on = function () {
        socket.on.apply(socket, arguments);
        return clientShell;
      };

      // Proxy any emit calls onto the socket itself.
      clientShell.emit = function () {
        socket.emit.apply(socket, arguments);
        return clientShell;
      };

      function getCookies() {
        var cookies = {};
        if (document.cookie.length > 0)
          document.cookie.split(';').forEach(function (cookie) {
            var components = cookie.split('='),
            name = components[0].trim(),
            value = components[1];
            if (name.indexOf(settings.namespace + '-') === 0) {
              name = name.replace(settings.namespace + '-', '');
              cookies[name] = decodeURIComponent(value);
            }
          });
          return cookies;
      }

      clientShell
      // Save context when it changes.
      .on('contextChanged', function (contextData) {
        context = contextData;
      })
      // Create a function for setting cookies in the browser.
      .on('setCookie', function (name, value, days) {
        var expiration = new Date();
        expiration.setDate(expiration.getDate() + days);
        value = encodeURIComponent(value) + ((days === null) ? "" : ";expires=" + expiration.toUTCString());
        document.cookie = settings.namespace + '-' + name + "=" + value;
      })
      .on('getCookie', function (name, callback) {
        // Create a cookies property on the context and fill it with all the cookies for this shell.
        var cookies = getCookies();
        callback(cookies[name]);
      })
      .on('getAllCookies', function (callback) {
        var cookies = getCookies();
        callback(cookies);
      });

      // Create an execute function that looks similar to the shotgun shell execute function for ease of use.
      clientShell.execute = function (cmdStr, contextOverride, options) {
        // If a context was passed in then override the stored context with it.
        if (contextOverride) context = contextOverride;
        socket.emit('execute', cmdStr, context, options);
        return clientShell;
      };

      return clientShell;
    }
function ( options ) { var clientShell = this , context = { } , // Default settings. defaultSettings = { namespace : 'shotgun' , debug : false } ; // Override default settings with supplied options. var settings = clientShell . settings = extend ( true , { } , defaultSettings , options ) ; // Instruct socket.io to connect to the server. var socket = clientShell . socket = io . connect ( '/' + settings . namespace ) ; // Proxy any listeners onto the socket itself. clientShell . on = function ( ) { socket . on . apply ( socket , arguments ) ; return clientShell ; } ; // Proxy any emit calls onto the socket itself. clientShell . emit = function ( ) { socket . emit . apply ( socket , arguments ) ; return clientShell ; } ; function getCookies ( ) { var cookies = { } ; if ( document . cookie . length > 0 ) document . cookie . split ( ';' ) . forEach ( function ( cookie ) { var components = cookie . split ( '=' ) , name = components [ 0 ] . trim ( ) , value = components [ 1 ] ; if ( name . indexOf ( settings . namespace + '-' ) === 0 ) { name = name . replace ( settings . namespace + '-' , '' ) ; cookies [ name ] = decodeURIComponent ( value ) ; } } ) ; return cookies ; } clientShell // Save context when it changes. . on ( 'contextChanged' , function ( contextData ) { context = contextData ; } ) // Create a function for setting cookies in the browser. . on ( 'setCookie' , function ( name , value , days ) { var expiration = new Date ( ) ; expiration . setDate ( expiration . getDate ( ) + days ) ; value = encodeURIComponent ( value ) + ( ( days === null ) ? "" : ";expires=" + expiration . toUTCString ( ) ) ; document . cookie = settings . namespace + '-' + name + "=" + value ; } ) . on ( 'getCookie' , function ( name , callback ) { // Create a cookies property on the context and fill it with all the cookies for this shell. var cookies = getCookies ( ) ; callback ( cookies [ name ] ) ; } ) . on ( 'getAllCookies' , function ( callback ) { var cookies = getCookies ( ) ; callback ( cookies ) ; } ) ; // Create an execute function that looks similar to the shotgun shell execute function for ease of use. clientShell . execute = function ( cmdStr , contextOverride , options ) { // If a context was passed in then override the stored context with it. if ( contextOverride ) context = contextOverride ; socket . emit ( 'execute' , cmdStr , context , options ) ; return clientShell ; } ; return clientShell ; }
Shotgun client shell.
Shotgun client shell .