diff --git a/packages/@jsonql/ws/package.json b/packages/@jsonql/ws/package.json index afcb4dc9bfce778d2ca338ba1563b6debd3fdcb1..06f32057eb402b0e36d07e0510927f6096379c29 100644 --- a/packages/@jsonql/ws/package.json +++ b/packages/@jsonql/ws/package.json @@ -37,12 +37,12 @@ "license": "ISC", "homepage": "jsonql.org", "dependencies": { - "jsonql-constants": "^1.8.5", + "jsonql-constants": "^1.8.6", "jsonql-errors": "^1.1.3", "jsonql-jwt": "^1.3.3", "jsonql-params-validator": "^1.4.11", "jsonql-utils": "^0.7.8", - "jsonql-ws-client": "^1.0.13", + "jsonql-ws-client": "^1.1.1", "ws": "^7.2.0" }, "devDependencies": { diff --git a/packages/constants/README.md b/packages/constants/README.md index 0b97a829779bd22fef518f6be1cafcc921484536..4ab31c60c5b2c606a7bc4269d527387c0b142df3 100755 --- a/packages/constants/README.md +++ b/packages/constants/README.md @@ -107,7 +107,7 @@ non-javascript to develop your tool. You can also use the included `constants.js - RESULT_PROP_NAME - ERROR_PROP_NAME - READY_PROP_NAME -- LOGGIN_PROP_NAME +- LOGIN_PROP_NAME - SEND_MSG_PROP_NAME - CLIENT_PROP_NAME - USERDATA_PROP_NAME diff --git a/packages/constants/constants.json b/packages/constants/constants.json index 69fdc21804e8ce1fdcfe7a62c4ea73aa1bd17dc4..f4cbdd9e6724124323209429bd1aca6ea2eeb194 100644 --- a/packages/constants/constants.json +++ b/packages/constants/constants.json @@ -139,7 +139,7 @@ "RESULT_PROP_NAME": "onResult", "ERROR_PROP_NAME": "onError", "READY_PROP_NAME": "onReady", - "LOGGIN_PROP_NAME": "onLogin", + "LOGIN_PROP_NAME": "onLogin", "SEND_MSG_PROP_NAME": "send", "CLIENT_PROP_NAME": "client", "USERDATA_PROP_NAME": "userdata", diff --git a/packages/constants/main.js b/packages/constants/main.js index eab245df056ae3eede843c1c354a30f4bf88d6ca..1d7f6e9c72043adfea14c24788836f01ead6a61a 100644 --- a/packages/constants/main.js +++ b/packages/constants/main.js @@ -139,7 +139,7 @@ module.exports = { "RESULT_PROP_NAME": "onResult", "ERROR_PROP_NAME": "onError", "READY_PROP_NAME": "onReady", - "LOGGIN_PROP_NAME": "onLogin", + "LOGIN_PROP_NAME": "onLogin", "SEND_MSG_PROP_NAME": "send", "CLIENT_PROP_NAME": "client", "USERDATA_PROP_NAME": "userdata", diff --git a/packages/constants/module.js b/packages/constants/module.js index 9d0a26658da4d0ef0bc4e42fd0825801e08d7c61..01c4cf3f28b6680d0d66a51a1a4f3f4941e3ce7c 100644 --- a/packages/constants/module.js +++ b/packages/constants/module.js @@ -144,7 +144,7 @@ export const MESSAGE_PROP_NAME = 'onMessage'; export const RESULT_PROP_NAME = 'onResult'; export const ERROR_PROP_NAME = 'onError'; export const READY_PROP_NAME = 'onReady'; -export const LOGGIN_PROP_NAME = 'onLogin'; // new @1.8.6 +export const LOGIN_PROP_NAME = 'onLogin'; // new @1.8.6 export const SEND_MSG_PROP_NAME = 'send'; // this one is for nodeClient inject into the resolver export const CLIENT_PROP_NAME = 'client'; diff --git a/packages/constants/package.json b/packages/constants/package.json index 3670bd1d92db37ee2c1a02982ea8e573e236e2fe..95fadf0e3405f0aeadcf83788f6a111357c4fdca 100755 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -1,6 +1,6 @@ { "name": "jsonql-constants", - "version": "1.8.6", + "version": "1.8.7", "description": "All the share constants for json:ql tools", "main": "main.js", "module": "module.js", diff --git a/packages/ws-client/package.json b/packages/ws-client/package.json index b96d6bb22ea19c5b552ee201157128cff74687d2..73b4928707da6d55a2fbe26ff97341b10a8faa46 100755 --- a/packages/ws-client/package.json +++ b/packages/ws-client/package.json @@ -1,7 +1,7 @@ { "name": "jsonql-ws-client", - "version": "1.0.13", - "description": "This is the Web Socket client for Node and Browser", + "version": "1.1.1", + "description": "This is the Web Socket client base library for Node and Browser. Not for direct use.", "main": "main.js", "module": "index.js", "files": [ @@ -49,7 +49,7 @@ "node": ">=8" }, "dependencies": { - "jsonql-constants": "^1.8.5", + "jsonql-constants": "^1.8.6", "jsonql-errors": "^1.1.3", "jsonql-jwt": "^1.3.3", "jsonql-params-validator": "^1.4.11", @@ -61,7 +61,7 @@ "esm": "^3.2.25", "fs-extra": "^8.1.0", "jsonql-contract": "^1.7.21", - "jsonql-ws-server": "^1.3.2", + "jsonql-ws-server": "^1.3.4", "kefir": "^3.8.6", "ws": "^7.2.0" }, diff --git a/packages/ws-client/src/core/generator.js b/packages/ws-client/src/core/generator.js index 2bd322beb66f3be68839b381accd62ec4e3677d6..e0d2b1b51497142f82e514470cbcbe43448931bb 100644 --- a/packages/ws-client/src/core/generator.js +++ b/packages/ws-client/src/core/generator.js @@ -6,6 +6,7 @@ import { createResolver, createNamespaceErrorHandler, createOnReadyhandler, + createOnLoginhandler, createAuthMethods } from './resolver-methods' import { getDebug } from '../utils' @@ -55,6 +56,8 @@ export function generator(opts, nspMap, ee) { .then(obj1 => createNamespaceErrorHandler(obj1, ee, nspSet)) // add onReady handler .then(obj2 => createOnReadyhandler(obj2, ee, nspSet)) + // add onLogin handler + .then(obj3 => createOnLoginhandler(obj3, ee, nspSet)) // Auth related methods - .then(obj3 => createAuthMethods(obj3, ee, opts)) + .then(obj4 => createAuthMethods(obj4, ee, opts)) } diff --git a/packages/ws-client/src/core/resolver-methods.js b/packages/ws-client/src/core/resolver-methods.js index 61afc6e733400621abee20df4d336e4c2d4eafb6..fcb2de8c0292abaed8305ae65eb76c4cb8f31dba 100644 --- a/packages/ws-client/src/core/resolver-methods.js +++ b/packages/ws-client/src/core/resolver-methods.js @@ -25,6 +25,7 @@ import { ERROR_PROP_NAME, MESSAGE_PROP_NAME, RESULT_PROP_NAME, + LOGIN_PROP_NAME, SEND_MSG_PROP_NAME, LOGIN_EVENT_NAME, READY_PROP_NAME, @@ -105,6 +106,23 @@ export function createOnReadyhandler(obj, ee, nspSet) { }) } +/** + * This event will fire when the socket.io.on('connection') and ws.onopen + * Plus this will check if it's the private namespace that fired the event + * @param {object} obj the client itself + * @param {object} ee Event Emitter + * @param {object} nspSet namespace keys + * @return {object} obj with onLogin prop + */ +export function createOnLoginhandler(obj, ee, nspSet) { + return objDefineProps(obj, LOGIN_PROP_NAME, function(onLoginCallback) { + if (isFunc(onLoginCallback)) { + // only one callback can registered with it, TBC + ee.$only(LOGIN_PROP_NAME, onLoginCallback) + } + }) +} + /** * Create auth related methods * @param {object} obj the client itself