all files / lib/providers/socket/ socketio.js

95.45% Statements 21/22
75% Branches 3/4
100% Functions 6/6
95.45% Lines 21/22
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52                                          34×     48×                
'use strict';
 
var socketio = require('socket.io');
var Proto = require('uberproto');
var debug = require('debug')('feathers:socket.io');
var commons = require('feathers-commons').socket;
 
module.exports = function (config) {
  return function () {
    var app = this;
 
    app.enable('feathers socketio');
 
    // Monkey patch app.setup(server)
    Proto.mixin({
      service: commons.service,
 
      setup: function (server) {
        Iif (this.disabled('feathers socketio')) {
          return this._super.apply(this, arguments);
        }
 
        var io = this.io = socketio.listen(server);
 
        if (typeof config === 'function') {
          debug('Calling SocketIO configuration function');
          config.call(this, io);
        }
 
        var result = this._super.apply(this, arguments);
 
        debug('Setting up SocketIO');
 
        commons.setup.call(this, {
          method: 'emit',
          connection: function() {
            return io.sockets;
          },
          clients: function() {
            return io.sockets.sockets;
          },
          params: function(socket) {
            return socket.feathers;
          }
        });
 
        return result;
      }
    }, app);
  };
};