arnaucube
arnaucube/socketioMEANseedPublic Self-hosted repository
socketioMEANseed/www/bower_components/angular-socket-io/mock/socket-io.js
www/bower_components/angular-socket-io/mock/socket-io.jsRaw
 1var io = {
 2  connect: createMockSocketObject
 3};
 4
 5function createMockSocketObject () {
 6
 7  var socket = {
 8    on: function (ev, fn) {
 9      (this._listeners[ev] = this._listeners[ev] || []).push(fn);
10    },
11    once: function (ev, fn) {
12      (this._listeners[ev] = this._listeners[ev] || []).push(fn);
13      fn._once = true;
14    },
15    emit: function (ev, data) {
16      if (this._listeners[ev]) {
17        var args = arguments;
18        this._listeners[ev].forEach(function (listener) {
19          if (listener._once) {
20            this.removeListener(ev, listener);
21          }
22          listener.apply(null, Array.prototype.slice.call(args, 1));
23        }.bind(this));
24      }
25    },
26    _listeners: {},
27    removeListener: function (ev, fn) {
28      if (fn) {
29        var index = this._listeners[ev].indexOf(fn);
30        if (index > -1) {
31          this._listeners[ev].splice(index, 1);
32        }
33      } else {
34        delete this._listeners[ev];
35      }
36    },
37    removeAllListeners: function (ev) {
38      if (ev) {
39        delete this._listeners[ev];
40      } else {
41        this._listeners = {};
42      }
43    },
44    disconnect: function () {},
45    connect: function () {}
46  };
47
48  return socket;
49}