From 45f6ccd4dcbbf6519b3295e618794b85c5203600 Mon Sep 17 00:00:00 2001 From: joelchu Date: Sat, 26 Oct 2019 08:45:41 +0800 Subject: [PATCH 1/3] add onLogin handler --- packages/ws-client/package.json | 4 ++-- packages/ws-client/src/core/generator.js | 5 ++++- .../ws-client/src/core/resolver-methods.js | 18 ++++++++++++++++++ 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/packages/ws-client/package.json b/packages/ws-client/package.json index b96d6bb2..aa44d8fa 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.0", + "description": "This is the Web Socket client base library for Node and Browser. Not for direct use.", "main": "main.js", "module": "index.js", "files": [ diff --git a/packages/ws-client/src/core/generator.js b/packages/ws-client/src/core/generator.js index 2bd322be..e0d2b1b5 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 61afc6e7..fcb2de8c 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 -- Gitee From af830aab7b70371b07bf412b8e03f78ad762a5aa Mon Sep 17 00:00:00 2001 From: joelchu Date: Sat, 26 Oct 2019 11:38:02 +0800 Subject: [PATCH 2/3] update the jsonql-constants dep and republish again --- packages/@jsonql/ws/package.json | 4 ++-- packages/ws-client/package.json | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/@jsonql/ws/package.json b/packages/@jsonql/ws/package.json index afcb4dc9..e9094997 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.0", "ws": "^7.2.0" }, "devDependencies": { diff --git a/packages/ws-client/package.json b/packages/ws-client/package.json index aa44d8fa..73b49287 100755 --- a/packages/ws-client/package.json +++ b/packages/ws-client/package.json @@ -1,6 +1,6 @@ { "name": "jsonql-ws-client", - "version": "1.1.0", + "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", @@ -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" }, -- Gitee From c5fe95b746257ddc508f9bb956cc8287a90d9395 Mon Sep 17 00:00:00 2001 From: joelchu Date: Sat, 26 Oct 2019 11:40:38 +0800 Subject: [PATCH 3/3] jsonql-constants to 1.8.7 fix the LOGIN_PROP_NAME --- packages/@jsonql/ws/package.json | 2 +- packages/constants/README.md | 2 +- packages/constants/constants.json | 2 +- packages/constants/main.js | 2 +- packages/constants/module.js | 2 +- packages/constants/package.json | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/@jsonql/ws/package.json b/packages/@jsonql/ws/package.json index e9094997..06f32057 100644 --- a/packages/@jsonql/ws/package.json +++ b/packages/@jsonql/ws/package.json @@ -42,7 +42,7 @@ "jsonql-jwt": "^1.3.3", "jsonql-params-validator": "^1.4.11", "jsonql-utils": "^0.7.8", - "jsonql-ws-client": "^1.1.0", + "jsonql-ws-client": "^1.1.1", "ws": "^7.2.0" }, "devDependencies": { diff --git a/packages/constants/README.md b/packages/constants/README.md index 0b97a829..4ab31c60 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 69fdc218..f4cbdd9e 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 eab245df..1d7f6e9c 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 9d0a2665..01c4cf3f 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 3670bd1d..95fadf0e 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", -- Gitee