From 10c4f4a146b3065b22e0670d7c752b25b8489025 Mon Sep 17 00:00:00 2001 From: David Kebler Date: Sun, 8 Sep 2019 20:09:36 -0700 Subject: [PATCH] 0.1.27 add bubble up 'status' event on every socket add in latest websocket client example --- examples/four-in-one.js | 1 - examples/ws-fio-client/package.json | 27 ++- examples/ws-fio-client/quasar.conf.js | 4 +- examples/ws-fio-client/src/boot/socket.js | 1 - .../ws-fio-client/src/layouts/default.vue | 7 +- examples/ws-fio-client/src/pages/Index.vue | 209 +++++++++++++----- nodemon.json | 2 +- package.json | 10 +- src/base.js | 28 +-- 9 files changed, 185 insertions(+), 104 deletions(-) diff --git a/examples/four-in-one.js b/examples/four-in-one.js index 91666ac..1feb27a 100644 --- a/examples/four-in-one.js +++ b/examples/four-in-one.js @@ -50,7 +50,6 @@ const socketfuncs = { } } - // client processing function function status(transport) { return (packet) => { diff --git a/examples/ws-fio-client/package.json b/examples/ws-fio-client/package.json index a1310c7..1bcd108 100644 --- a/examples/ws-fio-client/package.json +++ b/examples/ws-fio-client/package.json @@ -1,28 +1,31 @@ { - "name": "fio-client", + "name": "example-client", "version": "0.0.1", - "description": "a websocket client for use with the fiod example", + "description": "a websocket client example for use with @uci/websocket-client", "productName": "Websocket Client", "cordovaId": "org.cordova.quasar.app", "author": "David Kebler ", "private": true, "scripts": { "lint": "eslint --ext .js,.vue src", - "client": "WSS=ws://localhost:8090 ./node_modules/.bin/quasar dev" + "client": "./node_modules/.bin/quasar dev" }, "dependencies": { - "@quasar/extras": "^1.2.0", - "@uci/websocket-client": "^0.1.7", - "quasar": "^1.0.0", - "rfs": "^8.0.4" + "@quasar/extras": "^1.3.1", + "@uci/websocket-client": "^0.1.8", + "auto-bind": "^2.1.0", + "better-try-catch": "^0.6.2", + "delay": "^4.3.0", + "quasar": "^1.1.0", + "rfs": "^9.0.0" }, "devDependencies": { - "@quasar/app": "^1.0.0", + "@quasar/app": "^1.0.6", "@vue/eslint-config-standard": "^4.0.0", - "babel-eslint": "^10.0.1", - "eslint": "^5.10.0", - "eslint-loader": "^2.1.1", - "eslint-plugin-vue": "^5.0.0" + "babel-eslint": "^10.0.3", + "eslint": "^6.3.0", + "eslint-loader": "^3.0.0", + "eslint-plugin-vue": "^5.2.3" }, "engines": { "node": ">= 8.9.0", diff --git a/examples/ws-fio-client/quasar.conf.js b/examples/ws-fio-client/quasar.conf.js index be3bca9..486da1c 100644 --- a/examples/ws-fio-client/quasar.conf.js +++ b/examples/ws-fio-client/quasar.conf.js @@ -46,7 +46,9 @@ module.exports = function (ctx) { 'QSelect', 'QField', 'QFooter', - 'QTooltip' + 'QTooltip', + 'QBadge', + 'QScrollArea' ], directives: [ diff --git a/examples/ws-fio-client/src/boot/socket.js b/examples/ws-fio-client/src/boot/socket.js index 0c1f8bd..3b26564 100644 --- a/examples/ws-fio-client/src/boot/socket.js +++ b/examples/ws-fio-client/src/boot/socket.js @@ -1,4 +1,3 @@ -// import WebSocket from '@uci/websocket-client' import WebSocket from '@uci/websocket-client' const ws = new WebSocket(process.env.WSS || 'ws://0.0.0.0:8090') diff --git a/examples/ws-fio-client/src/layouts/default.vue b/examples/ws-fio-client/src/layouts/default.vue index f0176f9..ad316fb 100644 --- a/examples/ws-fio-client/src/layouts/default.vue +++ b/examples/ws-fio-client/src/layouts/default.vue @@ -14,11 +14,7 @@ - - - A UCommandIt Library Example - - + @@ -28,6 +24,7 @@ export default { data () { return { + status: [] } } } diff --git a/examples/ws-fio-client/src/pages/Index.vue b/examples/ws-fio-client/src/pages/Index.vue index 8e9c96f..07dae4e 100644 --- a/examples/ws-fio-client/src/pages/Index.vue +++ b/examples/ws-fio-client/src/pages/Index.vue @@ -1,9 +1,10 @@ diff --git a/nodemon.json b/nodemon.json index ab901e4..2e2a7df 100644 --- a/nodemon.json +++ b/nodemon.json @@ -1,4 +1,4 @@ { "ignoreRoot": [".git","examples/ws-fio-client"], - "watch": ["node_modules/@uci/","node_modules/@uci-utils/","src/","index.js","examples/","test/"] + "watch": ["node_modules/@uci/","node_modules/@uci-utils/","src/","index.js","examples/four-in-on.js","examples/four-in-on.js","test/"] } diff --git a/package.json b/package.json index 3ebfed8..f666063 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@uci/base", - "version": "0.1.26", + "version": "0.1.27", "description": "Multi type and transport JSON packet communication base class. Used in UCI extended classes", "main": "src/base", "scripts": { @@ -30,14 +30,14 @@ "chai": "^4.2.0", "esm": "^3.2.25", "mocha": "^6.2.0", - "nodemon": "^1.19.1" + "nodemon": "^1.19.2" }, "dependencies": { "@uci-utils/bind-funcs": "^0.2.4", "@uci-utils/logger": "^0.0.15", - "@uci/mqtt": "^0.1.12", - "@uci/socket": "^0.2.19", - "@uci/websocket": "^0.3.8", + "@uci/mqtt": "^0.1.13", + "@uci/socket": "^0.2.20", + "@uci/websocket": "^0.3.9", "await-to-js": "^2.1.1", "p-reflect": "^2.1.0", "p-settle": "^3.1.0" diff --git a/src/base.js b/src/base.js index 680a6a0..3b3b8d9 100644 --- a/src/base.js +++ b/src/base.js @@ -128,17 +128,6 @@ class Base extends EventEmitter { } } - // console.log('in init', this._socket) - // for (let name in this._socket) { - // let socket = this._initSocket(name) - // console.log(socket) - // let [err,res] = await to(socket.init()) - // if (err) errors[name] = err - // results[name] = res - // } - // this._started = true - // return {results:results, errors:errors} - let sockets = [] for (let name of Object.keys(this._socket)) { sockets.push(this._initSocket(name)) @@ -188,17 +177,11 @@ class Base extends EventEmitter { this._socket[name].transport = transport this._socket[name]._packetProcess = this._packetProcess.bind(this, name) - let bubble = (msg) => { - console.log(msg,name,this._socket[name].name) - this._socket[name].on(msg, ev => { - ev.socketName=name - this.emit(msg, ev) - }) - } - - const msgs = ['error','warn','fatal'] - msgs.map(bubble) // bubble up any emitted errors - + // bubble up any socket 'status' events to the base instance + this._socket[name].on('status', ev => { + ev.socketName=name + this.emit('status', ev) + }) // do this as .then promise then addSocket doesn't need to be async before init if (this._started) return await this._initSocket(name) @@ -559,7 +542,6 @@ class Base extends EventEmitter { return 'failed' } - } // end Base Class export default Base