websocket-framed
Advanced tools
Comparing version 1.0.24 to 1.1.0
@@ -47,5 +47,10 @@ /* | ||
[ "babelify", { | ||
presets: [ "es2015", "es2016", "es2017", "stage-3", "stage-2" ], | ||
plugins: [ [ "transform-runtime", { | ||
"polyfill": false, | ||
presets: [ | ||
[ "@babel/preset-env", { | ||
"targets": { | ||
"browsers": "last 2 versions, not dead" | ||
} | ||
} ] | ||
], | ||
plugins: [ [ "@babel/transform-runtime", { | ||
"regenerator": false | ||
@@ -75,18 +80,12 @@ } ] ] | ||
presets: [ | ||
[ "env", { | ||
[ "@babel/preset-env", { | ||
"targets": { | ||
"node": 6.0 | ||
"node": "6.0" | ||
} | ||
} ], | ||
"es2016", | ||
"es2017", | ||
"stage-3", | ||
"stage-2" | ||
} ] | ||
], | ||
plugins: [ | ||
[ "transform-runtime", { | ||
[ "@babel/transform-runtime", { | ||
"helpers": true, | ||
"polyfill": true, | ||
"regenerator": false, | ||
"moduleName": "babel-runtime" | ||
"regenerator": false | ||
} ] | ||
@@ -102,4 +101,8 @@ ] | ||
}) | ||
grunt.registerTask("default", [ "eslint", "browserify:websocket-framed-browser", "babel:websocket-framed-node" ]) | ||
grunt.registerTask("default", [ | ||
"eslint", | ||
"browserify:websocket-framed-browser", | ||
"babel:websocket-framed-node" | ||
]) | ||
} | ||
"use strict"; | ||
var _defineProperty = require("babel-runtime/core-js/object/define-property"); | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
var _defineProperty2 = _interopRequireDefault(_defineProperty); | ||
var _eventemitter = _interopRequireDefault(require("eventemitter3")); | ||
var _eventemitter = require("eventemitter3"); | ||
var _encodr = _interopRequireDefault(require("encodr")); | ||
var _eventemitter2 = _interopRequireDefault(_eventemitter); | ||
var _encodr = require("encodr"); | ||
var _encodr2 = _interopRequireDefault(_encodr); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
/* helper function: define a non-enumerable property */ | ||
/* | ||
@@ -43,84 +34,101 @@ ** WebSocket-Framed -- Framed WebSocket Communication | ||
/* external dependencies */ | ||
/* helper function: define a non-enumerable property */ | ||
const mkProp = (obj, name, value, writeable = true) => { | ||
(0, _defineProperty2.default)(obj, name, { | ||
configurable: false, | ||
enumerable: false, | ||
writable: writeable, | ||
value: value | ||
}); | ||
Object.defineProperty(obj, name, { | ||
configurable: false, | ||
enumerable: false, | ||
writable: writeable, | ||
value: value | ||
}); | ||
}; | ||
/* internal class: a single data frame */ | ||
/* internal class: a single data frame */ | ||
class Frame { | ||
constructor(channel) { | ||
mkProp(this, "channel", channel); | ||
this.reset(); | ||
} | ||
reset() { | ||
this.fid = 0; | ||
this.rid = 0; | ||
this.type = "MESSAGE"; | ||
this.data = null; | ||
} | ||
set(frame, replyTo = undefined) { | ||
this.fid = frame.fid ? frame.fid : this.channel.fid(); | ||
this.rid = frame.rid ? frame.rid : replyTo ? replyTo.fid : 0; | ||
this.type = frame.type ? frame.type : "MESSAGE"; | ||
this.data = frame.data ? frame.data : null; | ||
return this; | ||
} | ||
import(data) { | ||
let frame = this.channel.codec.decode(data); | ||
this.fid = frame[0]; | ||
this.rid = frame[1]; | ||
this.type = frame[2]; | ||
this.data = frame[3]; | ||
return this; | ||
} | ||
export() { | ||
let frame = [this.fid, this.rid, this.type, this.data]; | ||
let data = this.channel.codec.encode(frame); | ||
return data; | ||
} | ||
constructor(channel) { | ||
mkProp(this, "channel", channel); | ||
this.reset(); | ||
} | ||
reset() { | ||
this.fid = 0; | ||
this.rid = 0; | ||
this.type = "MESSAGE"; | ||
this.data = null; | ||
} | ||
set(frame, replyTo = undefined) { | ||
this.fid = frame.fid ? frame.fid : this.channel.fid(); | ||
this.rid = frame.rid ? frame.rid : replyTo ? replyTo.fid : 0; | ||
this.type = frame.type ? frame.type : "MESSAGE"; | ||
this.data = frame.data ? frame.data : null; | ||
return this; | ||
} | ||
import(data) { | ||
let frame = this.channel.codec.decode(data); | ||
this.fid = frame[0]; | ||
this.rid = frame[1]; | ||
this.type = frame[2]; | ||
this.data = frame[3]; | ||
return this; | ||
} | ||
export() { | ||
let frame = [this.fid, this.rid, this.type, this.data]; | ||
let data = this.channel.codec.encode(frame); | ||
return data; | ||
} | ||
} | ||
/* API class: framed WebSocket communication */ | ||
/* API class: framed WebSocket communication */ | ||
class WebSocketFramed extends _eventemitter2.default { | ||
constructor(ws, codec = "json") { | ||
super(); | ||
mkProp(this, "ws", ws); | ||
mkProp(this, "codec", new _encodr2.default(codec)); | ||
mkProp(this, "fid", (() => { | ||
let fid = 0; | ||
return () => { | ||
fid++; | ||
if (fid >= 0xffffffff - 1) fid = 1; | ||
return fid; | ||
}; | ||
})()); | ||
this.ws.addEventListener("message", ev => { | ||
let frame = new Frame(this); | ||
try { | ||
let data = ev.data; | ||
if (typeof data !== "string" && !ArrayBuffer.isView(data) && process.browser) data = new Uint8Array(data); | ||
frame.import(data); | ||
} catch (ex) { | ||
this.emit("error", ex); | ||
return; | ||
} | ||
ev.frame = frame; | ||
this.emit("message", ev); | ||
}); | ||
} | ||
send(frameData, replyTo) { | ||
let frame = new Frame(this); | ||
frame.set(frameData, replyTo); | ||
let data = frame.export(); | ||
if (typeof data !== "string" && ArrayBuffer.isView(data) && process.browser) data = data.buffer; | ||
this.ws.send(data); | ||
return { frame, data }; | ||
} | ||
class WebSocketFramed extends _eventemitter.default { | ||
constructor(ws, codec = "json") { | ||
super(); | ||
mkProp(this, "ws", ws); | ||
mkProp(this, "codec", new _encodr.default(codec)); | ||
mkProp(this, "fid", (() => { | ||
let fid = 0; | ||
return () => { | ||
fid++; | ||
if (fid >= 0xffffffff - 1) fid = 1; | ||
return fid; | ||
}; | ||
})()); | ||
this.ws.addEventListener("message", ev => { | ||
let frame = new Frame(this); | ||
try { | ||
let data = ev.data; | ||
if (typeof data !== "string" && !ArrayBuffer.isView(data) && process.browser) data = new Uint8Array(data); | ||
frame.import(data); | ||
} catch (ex) { | ||
this.emit("error", ex); | ||
return; | ||
} | ||
ev.frame = frame; | ||
this.emit("message", ev); | ||
}); | ||
} | ||
send(frameData, replyTo) { | ||
let frame = new Frame(this); | ||
frame.set(frameData, replyTo); | ||
let data = frame.export(); | ||
if (typeof data !== "string" && ArrayBuffer.isView(data) && process.browser) data = data.buffer; | ||
this.ws.send(data); | ||
return { | ||
frame, | ||
data | ||
}; | ||
} | ||
} | ||
/* export the API class the traditional way */ | ||
/* export the API class the traditional way */ | ||
module.exports = WebSocketFramed; |
{ | ||
"name": "websocket-framed", | ||
"version": "1.0.24", | ||
"version": "1.1.0", | ||
"description": "Framed WebSocket Communication", | ||
@@ -21,3 +21,3 @@ "keywords": [ "websocket", "frame", "message" ], | ||
"dependencies": { | ||
"encodr": "1.0.17", | ||
"encodr": "1.1.0", | ||
"eventemitter3": "3.1.0" | ||
@@ -27,16 +27,12 @@ }, | ||
"grunt": "1.0.3", | ||
"grunt-cli": "1.2.0", | ||
"grunt-cli": "1.3.1", | ||
"grunt-contrib-clean": "1.1.0", | ||
"grunt-eslint": "21.0.0", | ||
"grunt-babel": "7.0.0", | ||
"grunt-babel": "8.0.0-beta.0", | ||
"grunt-browserify": "5.3.0", | ||
"browserify": "16.2.2", | ||
"babelify": "8.0.0", | ||
"babel-core": "6.26.3", | ||
"babel-preset-es2015": "6.24.1", | ||
"babel-preset-es2016": "6.24.1", | ||
"babel-preset-es2017": "6.24.1", | ||
"babel-preset-stage-3": "6.24.1", | ||
"babel-preset-stage-2": "6.24.1", | ||
"babel-plugin-transform-runtime": "6.23.0", | ||
"babelify": "9.0.0", | ||
"@babel/core": "7.0.0", | ||
"@babel/preset-env": "7.0.0", | ||
"@babel/plugin-transform-runtime": "7.0.0", | ||
"uglifyify": "5.0.1", | ||
@@ -46,9 +42,8 @@ "browserify-header": "0.9.4", | ||
"browserify-shim": "3.8.14", | ||
"babel-eslint": "8.2.6", | ||
"babel-preset-env": "1.7.0", | ||
"eslint": "5.2.0", | ||
"eslint-config-standard": "11.0.0", | ||
"eslint-plugin-standard": "3.1.0", | ||
"eslint-plugin-promise": "3.8.0", | ||
"eslint-plugin-import": "2.13.0", | ||
"babel-eslint": "9.0.0", | ||
"eslint": "5.5.0", | ||
"eslint-config-standard": "12.0.0", | ||
"eslint-plugin-standard": "4.0.0", | ||
"eslint-plugin-promise": "4.0.0", | ||
"eslint-plugin-import": "2.14.0", | ||
"eslint-plugin-node": "7.0.1" | ||
@@ -55,0 +50,0 @@ }, |
Sorry, the diff of this file is too big to display
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
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
22
0
94086
641
+ Added@babel/runtime@7.0.0(transitive)
+ Addedencodr@1.1.0(transitive)
+ Addedregenerator-runtime@0.12.1(transitive)
- Removedbabel-runtime@6.26.0(transitive)
- Removedcore-js@2.6.12(transitive)
- Removedencodr@1.0.17(transitive)
- Removedregenerator-runtime@0.11.1(transitive)
Updatedencodr@1.1.0