Comparing version 0.5.0 to 0.5.1
@@ -7,3 +7,3 @@ "use strict"; | ||
class JJJRMISocket { | ||
constructor(socketName) { | ||
constructor(socketName) { | ||
this.jjjSocketName = socketName; | ||
@@ -16,4 +16,4 @@ this.translator = new Translator(); | ||
this.translator.addDecodeListener(obj=>obj.__jjjWebsocket = this); | ||
this.translator.addEncodeListener(obj=>obj.__jjjWebsocket = this); | ||
this.translator.addDecodeListener(obj => obj.__jjjWebsocket = this); | ||
this.translator.addEncodeListener(obj => obj.__jjjWebsocket = this); | ||
this.jjjEncode = null; | ||
@@ -53,3 +53,3 @@ } | ||
getAddress(){ | ||
getAddress() { | ||
let prequel = "ws://"; | ||
@@ -62,3 +62,3 @@ if (window.location.protocol === "https:") prequel = "wss://"; | ||
reset(){ | ||
reset() { | ||
this.translator.clear(); | ||
@@ -76,3 +76,3 @@ } | ||
methodRequest(src, methodName, args) { | ||
if (!this.translator.hasReferredObject(src)){ | ||
if (!this.translator.hasReferredObject(src)) { | ||
console.warn("see window.debug for source"); | ||
@@ -112,3 +112,3 @@ window.debug = src; | ||
onMessage(evt) { | ||
if (this.flags.RECEIVED && this.flags.VERBOSE){ | ||
if (this.flags.RECEIVED && this.flags.VERBOSE) { | ||
let json = JSON.parse(evt.data); | ||
@@ -121,3 +121,4 @@ console.log(JSON.stringify(json, null, 2)); | ||
switch (rmiMessage.type) { | ||
case JJJMessageType.FORGET:{ | ||
case JJJMessageType.FORGET: | ||
{ | ||
if (this.flags.ONMESSAGE) console.log(this.jjjSocketName + " FORGET"); | ||
@@ -127,3 +128,4 @@ this.translator.removeByKey(rmiMessage.key); | ||
} | ||
case JJJMessageType.READY:{ | ||
case JJJMessageType.READY: | ||
{ | ||
if (this.flags.CONNECT || this.flags.ONMESSAGE) console.log(this.jjjSocketName + " READY"); | ||
@@ -134,3 +136,4 @@ this.onready(rmiMessage.getRoot()); | ||
/* client originated request */ | ||
case JJJMessageType.LOCAL:{ | ||
case JJJMessageType.LOCAL: | ||
{ | ||
if (this.flags.ONMESSAGE) console.log(`Response to client side request: ${this.jjjSocketName} ${rmiMessage.methodName}`); | ||
@@ -143,4 +146,5 @@ let callback = this.callback[rmiMessage.uid]; | ||
/* server originated request */ | ||
case JJJMessageType.REMOTE:{ | ||
if (this.flags.ONMESSAGE) console.log(`Server side originated request: ${this.jjjSocketName} ${rmiMessage.methodName}`); | ||
case JJJMessageType.REMOTE: | ||
{ | ||
if (this.flags.ONMESSAGE) console.log(`Server side originated request: ${this.jjjSocketName} ${rmiMessage.methodName}`); | ||
let target = this.translator.getReferredObject(rmiMessage.ptr); | ||
@@ -157,3 +161,4 @@ this.remoteMethodCallback(target, rmiMessage.methodName, rmiMessage.args); | ||
} | ||
case JJJMessageType.EXCEPTION:{ | ||
case JJJMessageType.EXCEPTION: | ||
{ | ||
if (!this.flags.SILENT) console.log(this.jjjSocketName + " EXCEPTION " + rmiMessage.methodName); | ||
@@ -166,3 +171,4 @@ if (!this.flags.SILENT) console.warn(rmiMessage); | ||
} | ||
case JJJMessageType.REJECTED_CONNECTION:{ | ||
case JJJMessageType.REJECTED_CONNECTION: | ||
{ | ||
if (this.flags.CONNECT || this.flags.ONMESSAGE) console.log(this.jjjSocketName + " REJECTED_CONNECTION"); | ||
@@ -190,12 +196,47 @@ this.onreject(); | ||
} | ||
}; | ||
/** | ||
* Performs checks on class before registering it with translator. | ||
* @param {type} aClass | ||
* @returns {undefined} | ||
*/ | ||
registerClass(aClass) { | ||
if (typeof aClass !== "function") { | ||
console.log(aClass); | ||
throw new Error(`paramater 'class' of method 'registerClass' is '${typeof aClass}', expected 'function'`); | ||
} | ||
if (typeof aClass.__getClass !== "function") return; | ||
if (typeof aClass.__isEnum !== "function") return; | ||
if (typeof aClass.__isTransient !== "function") return; | ||
if (JJJRMISocket.flags.ONREGISTER) console.log(`Register ${aClass.__getClass()}`); | ||
this.translator.registerClass(aClass); | ||
for (let field in aClass) { | ||
if (JJJRMISocket.flags.ONREGISTER && JJJRMISocket.flags.VERBOSE) console.log(`considering ${aClass.__getClass()}.${field}`); | ||
if (typeof aClass[field] === "function" && typeof aClass[field].__getClass === "function") { | ||
this.registerClass(aClass[field]); | ||
} | ||
} | ||
} | ||
/* for registering all classes returned from generated JS */ | ||
registerPackage(packageFile) { | ||
for (let aClass in packageFile) { | ||
this.registerClass(packageFile[aClass]); | ||
} | ||
} | ||
} | ||
; | ||
JJJRMISocket.flags = { | ||
SILENT: false, /* do not print exceptions to console */ | ||
CONNECT: false, /* show the subset of ONMESSAGE that deals with the initial connection */ | ||
ONMESSAGE: false, /* describe the action taken when a message is received */ | ||
SENT: false, /* show the send object, versbose shows the json text as well */ | ||
RECEIVED: false, /* show the received server object, verbose shows the json text as well */ | ||
VERBOSE: false, /* print raw text for SENT / RECEIVED */ | ||
ONREGISTER: false /* report classes as they are registered */ | ||
SILENT: false, /* do not print exceptions to console */ | ||
CONNECT: false, /* show the subset of ONMESSAGE that deals with the initial connection */ | ||
ONMESSAGE: false, /* describe the action taken when a message is received */ | ||
SENT: false, /* show the send object, versbose shows the json text as well */ | ||
RECEIVED: false, /* show the received server object, verbose shows the json text as well */ | ||
VERBOSE: false, /* print raw text for SENT / RECEIVED */ | ||
ONREGISTER: false /* report classes as they are registered */ | ||
}; | ||
@@ -205,18 +246,25 @@ | ||
JJJRMISocket.registerClass = function(aClass){ | ||
if (typeof aClass !== "function"){ | ||
JJJRMISocket.registerClass = function (aClass) { | ||
if (typeof aClass !== "function") { | ||
console.log(aClass); | ||
throw new Error(`paramater 'class' of method 'registerClass' is '${typeof aClass}', expected 'function'`); | ||
} | ||
if (typeof aClass.__getClass !== "function"){ | ||
throw new Error(`in Class ${aClass.constructor.name} method __getClass of type ${typeof aClass.__getClass}`); | ||
if (JJJRMISocket.flags.ONREGISTER && JJJRMISocket.flags.VERBOSE) { | ||
if (typeof aClass.__getClass !== "function") console.log(`__getClass not of type function`); | ||
if (typeof aClass.__isEnum !== "function") console.log(`__isEnum not of type function`); | ||
if (typeof aClass.__isTransient !== "function") console.log(`__isTransient not of type function`); | ||
} | ||
if (typeof aClass.__getClass !== "function") return; | ||
if (typeof aClass.__isEnum !== "function") return; | ||
if (typeof aClass.__isTransient !== "function") return; | ||
if (JJJRMISocket.flags.ONREGISTER) console.log(`Register ${aClass.__getClass()}`); | ||
JJJRMISocket.classes.set(aClass.__getClass(), aClass); | ||
for (let field in aClass){ | ||
for (let field in aClass) { | ||
if (JJJRMISocket.flags.ONREGISTER && JJJRMISocket.flags.VERBOSE) console.log(`considering ${aClass.__getClass()}.${field}`); | ||
if (typeof aClass[field] === "function" && typeof aClass[field].__getClass === "function"){ | ||
if (typeof aClass[field] === "function" && typeof aClass[field].__getClass === "function") { | ||
JJJRMISocket.registerClass(aClass[field]); | ||
@@ -228,4 +276,4 @@ } | ||
/* for registering all classes returned from generated JS */ | ||
JJJRMISocket.registerPackage = function(packageFile){ | ||
for (let aClass in packageFile){ | ||
JJJRMISocket.registerPackage = function (packageFile) { | ||
for (let aClass in packageFile) { | ||
JJJRMISocket.registerClass(packageFile[aClass]); | ||
@@ -232,0 +280,0 @@ } |
{ | ||
"name": "jjjrmi", | ||
"version": "0.5.0", | ||
"version": "0.5.1", | ||
"keywords": [ | ||
@@ -5,0 +5,0 @@ "util", |
"use strict"; | ||
JJJRMI = { | ||
let JJJRMI = { | ||
javaEquivalent : { | ||
@@ -5,0 +5,0 @@ ArrayList : require("./java-equiv/ArrayList"), |
@@ -59,4 +59,3 @@ "use strict"; | ||
registerPackage(pkg) { | ||
for (let aClass in pkg) | ||
this.registerClass(pkg[aClass]); | ||
for (let aClass in pkg) this.registerClass(pkg[aClass]); | ||
} | ||
@@ -63,0 +62,0 @@ |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
46410
1314
0