Comparing version 0.1.0 to 0.1.1
@@ -13,3 +13,3 @@ "use strict"; | ||
var _events = require("events"); | ||
var _eventemitter = require("eventemitter2"); | ||
@@ -120,3 +120,3 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
return Client; | ||
}(_events.EventEmitter); | ||
}(_eventemitter.EventEmitter2); | ||
@@ -123,0 +123,0 @@ function client(url) { |
{ | ||
"name": "lastws", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "A solid WebSocket wrapper", | ||
@@ -29,2 +29,3 @@ "main": "server.js", | ||
"dependencies": { | ||
"eventemitter2": "^2.1.0", | ||
"websocket": "^1.0.23" | ||
@@ -40,9 +41,3 @@ }, | ||
"source-map-support": "^0.4.2" | ||
}, | ||
"babel": { | ||
"presets": [ | ||
"es2015", | ||
"stage-1" | ||
] | ||
} | ||
} |
124
server.js
@@ -15,3 +15,3 @@ "use strict"; | ||
var _events = require("events"); | ||
var _eventemitter = require("eventemitter2"); | ||
@@ -24,9 +24,61 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
var Server = function (_EventEmitter) { | ||
_inherits(Server, _EventEmitter); | ||
var Connection = function (_EventEmitter) { | ||
_inherits(Connection, _EventEmitter); | ||
function Connection(socket) { | ||
_classCallCheck(this, Connection); | ||
var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(Connection).call(this)); | ||
_this.socket = socket; | ||
socket.on("message", function (msg) { | ||
var json = JSON.parse(msg.utf8Data); | ||
_get(Object.getPrototypeOf(Connection.prototype), "emit", _this).call(_this, json.type, json.body); | ||
}); | ||
socket.on("close", function (reasonCode, description) { | ||
_get(Object.getPrototypeOf(Connection.prototype), "emit", _this).call(_this, "close", reasonCode, description); | ||
}); | ||
socket.on("error", function (err) { | ||
_get(Object.getPrototypeOf(Connection.prototype), "emit", _this).call(_this, "error", err); | ||
}); | ||
return _this; | ||
} | ||
_createClass(Connection, [{ | ||
key: "send", | ||
value: function send(type, body) { | ||
this.socket.sendUTF(JSON.stringify({ | ||
type: type, | ||
body: body | ||
})); | ||
} | ||
}, { | ||
key: "close", | ||
value: function close() { | ||
var _socket; | ||
(_socket = this.socket).close.apply(_socket, arguments); | ||
} | ||
}, { | ||
key: "drop", | ||
value: function drop() { | ||
var _socket2; | ||
(_socket2 = this.socket).drop.apply(_socket2, arguments); | ||
} | ||
}]); | ||
return Connection; | ||
}(_eventemitter.EventEmitter2); | ||
var Server = function (_EventEmitter2) { | ||
_inherits(Server, _EventEmitter2); | ||
function Server(httpServer) { | ||
_classCallCheck(this, Server); | ||
var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(Server).call(this)); | ||
var _this2 = _possibleConstructorReturn(this, Object.getPrototypeOf(Server).call(this)); | ||
@@ -37,5 +89,5 @@ var server = new _websocket.server({ | ||
}); | ||
_this.server = server; | ||
_this2.server = server; | ||
var sockets = new Map(); | ||
_this.sockets = sockets; | ||
_this2.sockets = sockets; | ||
@@ -45,3 +97,3 @@ server.on("connect", function (socket) { | ||
sockets.set(socket, connection); | ||
_get(Object.getPrototypeOf(Server.prototype), "emit", _this).call(_this, "connect", connection); | ||
_get(Object.getPrototypeOf(Server.prototype), "emit", _this2).call(_this2, "connect", connection); | ||
}); | ||
@@ -52,5 +104,5 @@ | ||
sockets.delete(socket); | ||
_get(Object.getPrototypeOf(Server.prototype), "emit", _this).call(_this, "close", connection, reasonCode, description); | ||
_get(Object.getPrototypeOf(Server.prototype), "emit", _this2).call(_this2, "close", connection, reasonCode, description); | ||
}); | ||
return _this; | ||
return _this2; | ||
} | ||
@@ -78,58 +130,6 @@ | ||
return Server; | ||
}(_events.EventEmitter); | ||
}(_eventemitter.EventEmitter2); | ||
var Connection = function (_EventEmitter2) { | ||
_inherits(Connection, _EventEmitter2); | ||
function Connection(socket) { | ||
_classCallCheck(this, Connection); | ||
var _this2 = _possibleConstructorReturn(this, Object.getPrototypeOf(Connection).call(this)); | ||
_this2.socket = socket; | ||
socket.on("message", function (msg) { | ||
var json = JSON.parse(msg.utf8Data); | ||
_get(Object.getPrototypeOf(Connection.prototype), "emit", _this2).call(_this2, json.type, json.body); | ||
}); | ||
socket.on("close", function (reasonCode, description) { | ||
_get(Object.getPrototypeOf(Connection.prototype), "emit", _this2).call(_this2, "close", reasonCode, description); | ||
}); | ||
socket.on("error", function (err) { | ||
_get(Object.getPrototypeOf(Connection.prototype), "emit", _this2).call(_this2, "error", err); | ||
}); | ||
return _this2; | ||
} | ||
_createClass(Connection, [{ | ||
key: "send", | ||
value: function send(type, body) { | ||
this.socket.sendUTF(JSON.stringify({ | ||
type: type, | ||
body: body | ||
})); | ||
} | ||
}, { | ||
key: "close", | ||
value: function close() { | ||
var _socket; | ||
(_socket = this.socket).close.apply(_socket, arguments); | ||
} | ||
}, { | ||
key: "drop", | ||
value: function drop() { | ||
var _socket2; | ||
(_socket2 = this.socket).drop.apply(_socket2, arguments); | ||
} | ||
}]); | ||
return Connection; | ||
}(_events.EventEmitter); | ||
function server(httpServer) { | ||
return new Server(httpServer); | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
13791
8
2
+ Addedeventemitter2@^2.1.0
+ Addedeventemitter2@2.2.2(transitive)