Compare commits
20 Commits
Author | SHA1 | Date | |
---|---|---|---|
9c1504ef02 | |||
e8f2e04d1c | |||
e12aa7e961 | |||
857b7cd010 | |||
e100dea160 | |||
e8e87fcdba | |||
0d18b11721 | |||
eaaefddbe3 | |||
8c6946ddb6 | |||
3a7ebcdd80 | |||
ec2afbfd55 | |||
89feeca735 | |||
c4261765ec | |||
33fe6bcd41 | |||
1baf1c318c | |||
051aba3299 | |||
7998d79b13 | |||
6838a8729a | |||
67f4e33ca0 | |||
8a8277ae9f |
155
package-lock.json
generated
155
package-lock.json
generated
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@pushrocks/smartuniverse",
|
||||
"version": "1.0.54",
|
||||
"version": "1.0.64",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
@ -104,24 +104,17 @@
|
||||
}
|
||||
},
|
||||
"@pushrocks/lik": {
|
||||
"version": "3.0.5",
|
||||
"resolved": "https://verdaccio.lossless.one/@pushrocks%2flik/-/lik-3.0.5.tgz",
|
||||
"integrity": "sha512-pc5Nq0WUysS34qPpyiZXiX254kL3vyRVbt3D36Q5QU+eHhxAThHofSzgOdyVHUZU2WFoaMlKowIVsyUFzIkfdw==",
|
||||
"version": "3.0.10",
|
||||
"resolved": "https://verdaccio.lossless.one/@pushrocks%2flik/-/lik-3.0.10.tgz",
|
||||
"integrity": "sha512-iWG06QsrL6AAnjPRWMVz4bRaRE0jJt/HgEK0YeLqaSBLY8ju4ps1j4lEN8VrUlXGZyPB6UGQfcreesO24buYhQ==",
|
||||
"requires": {
|
||||
"@pushrocks/smartdelay": "^2.0.2",
|
||||
"@pushrocks/smartpromise": "^2.0.5",
|
||||
"@pushrocks/smartdelay": "^2.0.3",
|
||||
"@pushrocks/smartpromise": "^3.0.2",
|
||||
"@pushrocks/smartrx": "^2.0.3",
|
||||
"@pushrocks/smarttime": "^3.0.5",
|
||||
"@pushrocks/smarttime": "^3.0.12",
|
||||
"@types/minimatch": "^3.0.3",
|
||||
"minimatch": "^3.0.4",
|
||||
"symbol-tree": "^3.2.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"@pushrocks/smartpromise": {
|
||||
"version": "2.0.5",
|
||||
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartpromise/-/smartpromise-2.0.5.tgz",
|
||||
"integrity": "sha512-9j/chLtIiNkR0MDw7Mpxg9slxAVvAQwUZuiaPYX5KpHdKxQaHLI1VZ8IN0vPhwlfgNO4i4vGXV0wB8BvSDj03g=="
|
||||
}
|
||||
"symbol-tree": "^3.2.4"
|
||||
}
|
||||
},
|
||||
"@pushrocks/smartcli": {
|
||||
@ -182,12 +175,12 @@
|
||||
}
|
||||
},
|
||||
"@pushrocks/smartexpress": {
|
||||
"version": "3.0.35",
|
||||
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartexpress/-/smartexpress-3.0.35.tgz",
|
||||
"integrity": "sha512-8DYFURxE+CXuh59O7SMRTLKaiWda/I1srcLE5Hka6YCLCahCKsT1HDVHcEVnY4E7kd9OaHEzuPa7ZddaISi5xQ==",
|
||||
"version": "3.0.38",
|
||||
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartexpress/-/smartexpress-3.0.38.tgz",
|
||||
"integrity": "sha512-di26orVJwgBRGKVpYcPrauc14CVo0piAzXTBWFZZNUCuIsndnXepd9oDzMO+KHVZpNz3W4DxbtRkppZjrh9ejw==",
|
||||
"requires": {
|
||||
"@pushrocks/lik": "^3.0.5",
|
||||
"@pushrocks/smartfile": "^7.0.2",
|
||||
"@pushrocks/lik": "^3.0.10",
|
||||
"@pushrocks/smartfile": "^7.0.4",
|
||||
"@pushrocks/smartmanifest": "^1.0.6",
|
||||
"@pushrocks/smartpromise": "^3.0.2",
|
||||
"@pushrocks/smartrequest": "^1.1.16",
|
||||
@ -199,9 +192,9 @@
|
||||
"cors": "^2.8.5",
|
||||
"express": "^4.17.1",
|
||||
"express-force-ssl": "^0.3.2",
|
||||
"helmet": "^3.18.0",
|
||||
"helmet": "^3.20.0",
|
||||
"rendertron-middleware": "^0.1.5",
|
||||
"sitemap": "^2.2.0"
|
||||
"sitemap": "^3.2.2"
|
||||
}
|
||||
},
|
||||
"@pushrocks/smartfile": {
|
||||
@ -340,14 +333,14 @@
|
||||
}
|
||||
},
|
||||
"@pushrocks/smartsocket": {
|
||||
"version": "1.1.38",
|
||||
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartsocket/-/smartsocket-1.1.38.tgz",
|
||||
"integrity": "sha512-mGWEuA53GqTFOCebwo4Ayu2l7xjui7I0tdUNgZShGhIr4yv+q3sP/66q6cT388xVawIN+swviJPlPoogaoZXdA==",
|
||||
"version": "1.1.44",
|
||||
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartsocket/-/smartsocket-1.1.44.tgz",
|
||||
"integrity": "sha512-AxDEDQw96szewxiA7Vk+ak6l7tsf2MLIThAuoV53ycDkDNXMyJizqE8fnzks9+/OEukwwas9kYNT9MyqPIS1mw==",
|
||||
"requires": {
|
||||
"@pushrocks/lik": "^3.0.5",
|
||||
"@pushrocks/lik": "^3.0.10",
|
||||
"@pushrocks/smartdelay": "^2.0.3",
|
||||
"@pushrocks/smartexpress": "^3.0.21",
|
||||
"@pushrocks/smarthash": "^2.0.4",
|
||||
"@pushrocks/smartexpress": "^3.0.38",
|
||||
"@pushrocks/smarthash": "^2.0.6",
|
||||
"@pushrocks/smartlog": "^2.0.19",
|
||||
"@pushrocks/smartpromise": "^3.0.2",
|
||||
"@types/shortid": "0.0.29",
|
||||
@ -525,9 +518,9 @@
|
||||
"integrity": "sha512-tHq6qdbT9U1IRSGf14CL0pUlULksvY9OZ+5eEgl1N7t+OA3tGvNpxJCzuKQlsNgCVwbAs670L1vcVQi8j9HjnA=="
|
||||
},
|
||||
"@types/node": {
|
||||
"version": "12.6.8",
|
||||
"resolved": "https://verdaccio.lossless.one/@types%2fnode/-/node-12.6.8.tgz",
|
||||
"integrity": "sha512-aX+gFgA5GHcDi89KG5keey2zf0WfZk/HAQotEamsK2kbey+8yGKcson0hbK8E+v0NArlCJQCqMP161YhV6ZXLg=="
|
||||
"version": "12.7.1",
|
||||
"resolved": "https://verdaccio.lossless.one/@types%2fnode/-/node-12.7.1.tgz",
|
||||
"integrity": "sha512-aK9jxMypeSrhiYofWWBf/T7O+KwaiAHzM4sveCdWPn71lzUSMimRnKzhXDKfKwV1kWoBo2P1aGgaIYGLf9/ljw=="
|
||||
},
|
||||
"@types/range-parser": {
|
||||
"version": "1.2.3",
|
||||
@ -604,21 +597,6 @@
|
||||
"requires": {
|
||||
"mime-types": "~2.1.24",
|
||||
"negotiator": "0.6.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"mime-db": {
|
||||
"version": "1.40.0",
|
||||
"resolved": "https://verdaccio.lossless.one/mime-db/-/mime-db-1.40.0.tgz",
|
||||
"integrity": "sha512-jYdeOMPy9vnxEqFRRo6ZvTZ8d9oPb+k18PKoYNYUe2stVEBPPwsln/qWzdbmaIvnhZ9v2P+CuecK+fpUfsV2mA=="
|
||||
},
|
||||
"mime-types": {
|
||||
"version": "2.1.24",
|
||||
"resolved": "https://verdaccio.lossless.one/mime-types/-/mime-types-2.1.24.tgz",
|
||||
"integrity": "sha512-WaFHS3MCl5fapm3oLxU4eYDw77IQM2ACcxQ9RIxfaC3ooc6PFuBMGZZsYpvoXS5D5QTWPieo1jjLdAm3TBP3cQ==",
|
||||
"requires": {
|
||||
"mime-db": "1.40.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"after": {
|
||||
@ -702,9 +680,9 @@
|
||||
"dev": true
|
||||
},
|
||||
"async-limiter": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://verdaccio.lossless.one/async-limiter/-/async-limiter-1.0.0.tgz",
|
||||
"integrity": "sha512-jp/uFnooOiO+L211eZOoSyzpOITMXx1rBITauYykG3BRYPu8h0UcxsPNB04RR5vo4Tyz3+ay17tR6JVf9qzYWg=="
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://verdaccio.lossless.one/async-limiter/-/async-limiter-1.0.1.tgz",
|
||||
"integrity": "sha512-csOlWGAcRFJaI6m+F2WKdnMKr4HhdhFVBk0H/QbJFMCr+uO2kwohwXQPxw/9OCxp05r5ghVBFSyioixx3gfkNQ=="
|
||||
},
|
||||
"asynckit": {
|
||||
"version": "0.4.0",
|
||||
@ -1802,11 +1780,6 @@
|
||||
"path-exists": "^3.0.0"
|
||||
}
|
||||
},
|
||||
"lodash": {
|
||||
"version": "4.17.15",
|
||||
"resolved": "https://verdaccio.lossless.one/lodash/-/lodash-4.17.15.tgz",
|
||||
"integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A=="
|
||||
},
|
||||
"lodash._baseassign": {
|
||||
"version": "3.2.0",
|
||||
"resolved": "https://verdaccio.lossless.one/lodash._baseassign/-/lodash._baseassign-3.2.0.tgz",
|
||||
@ -1856,6 +1829,11 @@
|
||||
"lodash.keys": "^3.0.0"
|
||||
}
|
||||
},
|
||||
"lodash.chunk": {
|
||||
"version": "4.2.0",
|
||||
"resolved": "https://verdaccio.lossless.one/lodash.chunk/-/lodash.chunk-4.2.0.tgz",
|
||||
"integrity": "sha1-ZuXOH3btJ7QwPYxlEujRIW6BBrw="
|
||||
},
|
||||
"lodash.clonedeep": {
|
||||
"version": "4.5.0",
|
||||
"resolved": "https://verdaccio.lossless.one/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz",
|
||||
@ -1881,11 +1859,21 @@
|
||||
"lodash.isarray": "^3.0.0"
|
||||
}
|
||||
},
|
||||
"lodash.padstart": {
|
||||
"version": "4.6.1",
|
||||
"resolved": "https://verdaccio.lossless.one/lodash.padstart/-/lodash.padstart-4.6.1.tgz",
|
||||
"integrity": "sha1-0uPuv/DZ05rVD1y9G1KnvOa7YRs="
|
||||
},
|
||||
"lodash.restparam": {
|
||||
"version": "3.6.1",
|
||||
"resolved": "https://verdaccio.lossless.one/lodash.restparam/-/lodash.restparam-3.6.1.tgz",
|
||||
"integrity": "sha1-k2pOMJ7zMKdkXtQUWYbIWuWyCAU="
|
||||
},
|
||||
"lodash.sortby": {
|
||||
"version": "4.7.0",
|
||||
"resolved": "https://verdaccio.lossless.one/lodash.sortby/-/lodash.sortby-4.7.0.tgz",
|
||||
"integrity": "sha1-7dFMgk4sycHgsKG0K7UhBRakJDg="
|
||||
},
|
||||
"log-symbols": {
|
||||
"version": "2.2.0",
|
||||
"resolved": "https://verdaccio.lossless.one/log-symbols/-/log-symbols-2.2.0.tgz",
|
||||
@ -2279,9 +2267,9 @@
|
||||
}
|
||||
},
|
||||
"psl": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://verdaccio.lossless.one/psl/-/psl-1.2.0.tgz",
|
||||
"integrity": "sha512-GEn74ZffufCmkDDLNcl3uuyF/aSD6exEyh1v/ZSdAomB82t6G9hzJVRx0jBmLDW+VfZqks3aScmMw9DszwUalA=="
|
||||
"version": "1.3.0",
|
||||
"resolved": "https://verdaccio.lossless.one/psl/-/psl-1.3.0.tgz",
|
||||
"integrity": "sha512-avHdspHO+9rQTLbv1RO+MPYeP/SzsCoxofjVnHanETfQhTJrmB0HlDoW+EiN/R+C0BZ+gERab9NY0lPN2TxNag=="
|
||||
},
|
||||
"pump": {
|
||||
"version": "3.0.0",
|
||||
@ -2535,13 +2523,14 @@
|
||||
"dev": true
|
||||
},
|
||||
"sitemap": {
|
||||
"version": "2.2.0",
|
||||
"resolved": "https://verdaccio.lossless.one/sitemap/-/sitemap-2.2.0.tgz",
|
||||
"integrity": "sha512-9Zoi3UBhSIt5jWENDRUbzsqLMJ+Fha3P2aQ2PRghmh0FOivtHsC4FAJdkAEKHvATajd74BWp/57Yh7kz/UA53Q==",
|
||||
"version": "3.2.2",
|
||||
"resolved": "https://verdaccio.lossless.one/sitemap/-/sitemap-3.2.2.tgz",
|
||||
"integrity": "sha512-TModL/WU4m2q/mQcrDgNANn0P4LwprM9MMvG4hu5zP4c6IIKs2YLTu6nXXnNr8ODW/WFtxKggiJ1EGn2W0GNmg==",
|
||||
"requires": {
|
||||
"lodash": "^4.17.10",
|
||||
"url-join": "^4.0.0",
|
||||
"xmlbuilder": "^10.0.0"
|
||||
"lodash.chunk": "^4.2.0",
|
||||
"lodash.padstart": "^4.6.1",
|
||||
"whatwg-url": "^7.0.0",
|
||||
"xmlbuilder": "^13.0.0"
|
||||
}
|
||||
},
|
||||
"smartchai": {
|
||||
@ -2757,9 +2746,9 @@
|
||||
}
|
||||
},
|
||||
"symbol-tree": {
|
||||
"version": "3.2.2",
|
||||
"resolved": "https://verdaccio.lossless.one/symbol-tree/-/symbol-tree-3.2.2.tgz",
|
||||
"integrity": "sha1-rifbOPZgp64uHDt9G8KQgZuFGeY="
|
||||
"version": "3.2.4",
|
||||
"resolved": "https://verdaccio.lossless.one/symbol-tree/-/symbol-tree-3.2.4.tgz",
|
||||
"integrity": "sha512-9QNk5KwDF+Bvz+PyObkmSYjI5ksVUYtjW7AU22r2NKcfLJcXp96hkDWU3+XndOsUb+AQ9QhfzfCT2O+CNWT5Tw=="
|
||||
},
|
||||
"through2": {
|
||||
"version": "3.0.1",
|
||||
@ -2795,6 +2784,14 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"tr46": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://verdaccio.lossless.one/tr46/-/tr46-1.0.1.tgz",
|
||||
"integrity": "sha1-qLE/1r/SSJUZZ0zN5VujaTtwbQk=",
|
||||
"requires": {
|
||||
"punycode": "^2.1.0"
|
||||
}
|
||||
},
|
||||
"ts-node": {
|
||||
"version": "8.2.0",
|
||||
"resolved": "https://verdaccio.lossless.one/ts-node/-/ts-node-8.2.0.tgz",
|
||||
@ -2909,11 +2906,6 @@
|
||||
"punycode": "^2.1.0"
|
||||
}
|
||||
},
|
||||
"url-join": {
|
||||
"version": "4.0.1",
|
||||
"resolved": "https://verdaccio.lossless.one/url-join/-/url-join-4.0.1.tgz",
|
||||
"integrity": "sha512-jk1+QP6ZJqyOiuEI9AEWQfju/nB2Pw466kbA0LEZljHwKeMgd9WrAEgEGxjPDD2+TNbbb37rTyhEfrCXfuKXnA=="
|
||||
},
|
||||
"util-deprecate": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://verdaccio.lossless.one/util-deprecate/-/util-deprecate-1.0.2.tgz",
|
||||
@ -2978,6 +2970,21 @@
|
||||
"defaults": "^1.0.3"
|
||||
}
|
||||
},
|
||||
"webidl-conversions": {
|
||||
"version": "4.0.2",
|
||||
"resolved": "https://verdaccio.lossless.one/webidl-conversions/-/webidl-conversions-4.0.2.tgz",
|
||||
"integrity": "sha512-YQ+BmxuTgd6UXZW3+ICGfyqRyHXVlD5GtQr5+qjiNW7bF0cqrzX500HVXPBOvgXb5YnzDd+h0zqyv61KUD7+Sg=="
|
||||
},
|
||||
"whatwg-url": {
|
||||
"version": "7.0.0",
|
||||
"resolved": "https://verdaccio.lossless.one/whatwg-url/-/whatwg-url-7.0.0.tgz",
|
||||
"integrity": "sha512-37GeVSIJ3kn1JgKyjiYNmSLP1yzbpb29jdmwBSgkD9h40/hyrR/OifpVUndji3tmwGgD8qpw7iQu3RSbCrBpsQ==",
|
||||
"requires": {
|
||||
"lodash.sortby": "^4.7.0",
|
||||
"tr46": "^1.0.1",
|
||||
"webidl-conversions": "^4.0.2"
|
||||
}
|
||||
},
|
||||
"which": {
|
||||
"version": "1.3.1",
|
||||
"resolved": "https://verdaccio.lossless.one/which/-/which-1.3.1.tgz",
|
||||
@ -3059,9 +3066,9 @@
|
||||
"integrity": "sha512-xN0kV+8XfOQM2OPPBdEbGtbvJNNP1pvZR7sE6d44cjJFQG4OiGDdienPg5iOUGswBTiGbBvtYDURd30BMJwwqg=="
|
||||
},
|
||||
"xmlbuilder": {
|
||||
"version": "10.1.1",
|
||||
"resolved": "https://verdaccio.lossless.one/xmlbuilder/-/xmlbuilder-10.1.1.tgz",
|
||||
"integrity": "sha512-OyzrcFLL/nb6fMGHbiRDuPup9ljBycsdCypwuyg5AAHvyWzGfChJpCXMG88AGTIMFhGZ9RccFN1e6lhg3hkwKg=="
|
||||
"version": "13.0.2",
|
||||
"resolved": "https://verdaccio.lossless.one/xmlbuilder/-/xmlbuilder-13.0.2.tgz",
|
||||
"integrity": "sha512-Eux0i2QdDYKbdbA6AM6xE4m6ZTZr4G4xF9kahI2ukSEMCzwce2eX9WlTI5J3s+NU7hpasFsr8hWIONae7LluAQ=="
|
||||
},
|
||||
"xmlhttprequest-ssl": {
|
||||
"version": "1.5.5",
|
||||
|
11
package.json
11
package.json
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@pushrocks/smartuniverse",
|
||||
"version": "1.0.54",
|
||||
"version": "1.0.64",
|
||||
"private": false,
|
||||
"description": "messaging service for your micro services",
|
||||
"main": "dist/index.js",
|
||||
@ -17,7 +17,7 @@
|
||||
"@gitzone/tsbuild": "^2.1.11",
|
||||
"@gitzone/tstest": "^1.0.24",
|
||||
"@pushrocks/tapbundle": "^3.0.11",
|
||||
"@types/node": "^12.6.8",
|
||||
"@types/node": "^12.7.1",
|
||||
"tslint": "^5.18.0",
|
||||
"tslint-config-prettier": "^1.18.0"
|
||||
},
|
||||
@ -25,15 +25,16 @@
|
||||
"rxjs": "*"
|
||||
},
|
||||
"dependencies": {
|
||||
"@pushrocks/lik": "^3.0.5",
|
||||
"@pushrocks/lik": "^3.0.10",
|
||||
"@pushrocks/smartdelay": "^2.0.3",
|
||||
"@pushrocks/smartexpress": "^3.0.35",
|
||||
"@pushrocks/smartexpress": "^3.0.38",
|
||||
"@pushrocks/smartfile": "^7.0.4",
|
||||
"@pushrocks/smarthash": "^2.0.6",
|
||||
"@pushrocks/smartlog": "^2.0.19",
|
||||
"@pushrocks/smartpromise": "^3.0.2",
|
||||
"@pushrocks/smartrequest": "^1.1.16",
|
||||
"@pushrocks/smartrx": "^2.0.3",
|
||||
"@pushrocks/smartsocket": "^1.1.38",
|
||||
"@pushrocks/smartsocket": "^1.1.44",
|
||||
"@pushrocks/smarttime": "^3.0.12",
|
||||
"@pushrocks/smartunique": "^3.0.1"
|
||||
},
|
||||
|
19
test/test.ts
19
test/test.ts
@ -15,7 +15,7 @@ const testServerData = {
|
||||
|
||||
const testChannelData = {
|
||||
channelName: 'awesomeTestChannel',
|
||||
channelPass: 'awesomeChannelPAss'
|
||||
channelPass: 'awesomeChannelPass'
|
||||
};
|
||||
|
||||
tap.test('first test', async () => {
|
||||
@ -37,22 +37,25 @@ tap.test('create smartuniverse client', async () => {
|
||||
});
|
||||
|
||||
tap.test('should add a channel to the universe', async () => {
|
||||
await testUniverse.addChannel(testChannelData.channelName, testChannelData.channelPass);
|
||||
testUniverse.addChannel(testChannelData.channelName, testChannelData.channelPass);
|
||||
});
|
||||
|
||||
tap.test('should add the same channel to the client universe in the same way', async () => {
|
||||
await testClientUniverse.addChannel(testChannelData.channelName, testChannelData.channelPass);
|
||||
testClientUniverse.addChannel(testChannelData.channelName, testChannelData.channelPass);
|
||||
});
|
||||
|
||||
tap.test('should start the ClientUniverse', async () => {
|
||||
await testClientUniverse.start();
|
||||
})
|
||||
|
||||
tap.test('should get a observable correctly', async () => {
|
||||
testClientChannel = await testClientUniverse.getChannel(testChannelData.channelName);
|
||||
testClientChannel = testClientUniverse.getChannel(testChannelData.channelName);
|
||||
expect(testClientChannel).to.be.instanceof(smartuniverse.ClientUniverseChannel);
|
||||
});
|
||||
|
||||
tap.test('should send a message correctly', async () => {
|
||||
await testClientUniverse.sendMessage({
|
||||
messageText: 'hello',
|
||||
targetChannelName: testChannelData.channelName
|
||||
await (testClientUniverse.getChannel(testChannelData.channelName)).sendMessage({
|
||||
messageText: 'hello'
|
||||
});
|
||||
});
|
||||
|
||||
@ -71,7 +74,7 @@ tap.test('a second client should be able to subscibe', async () => {
|
||||
tap.test('should receive a message correctly', async () => {});
|
||||
|
||||
tap.test('should disconnect the client correctly', async () => {
|
||||
testClientUniverse.close();
|
||||
testClientUniverse.stop();
|
||||
});
|
||||
|
||||
tap.test('should end the server correctly', async tools => {
|
||||
|
@ -1,6 +1,7 @@
|
||||
// Client classes
|
||||
export * from './smartuniverse.classes.clientuniverse';
|
||||
export * from './smartuniverse.classes.clientuniversechannel';
|
||||
export * from './smartuniverse.classes.clientuniversemessage';
|
||||
|
||||
// Server classes
|
||||
export * from './smartuniverse.classes.universe';
|
||||
|
@ -1,4 +0,0 @@
|
||||
export interface IAuthenticationRequest {
|
||||
channelName: string;
|
||||
password: string;
|
||||
}
|
@ -2,9 +2,11 @@ export interface IMessageCreator {
|
||||
messageText: string;
|
||||
payload?: string | number | any;
|
||||
payloadStringType?: 'Buffer' | 'string' | 'object';
|
||||
targetChannelName: string;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
export interface IUniverseMessage extends IMessageCreator {
|
||||
id: string;
|
||||
/**
|
||||
@ -12,4 +14,5 @@ export interface IUniverseMessage extends IMessageCreator {
|
||||
*/
|
||||
timestamp: number;
|
||||
passphrase: string;
|
||||
targetChannelName: string;
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ import * as url from 'url';
|
||||
|
||||
import * as interfaces from './interfaces';
|
||||
|
||||
import { ClientUniverseChannel, UniverseMessage } from './';
|
||||
import { ClientUniverseChannel, ClientUniverseMessage } from './';
|
||||
import { ClientUniverseCache } from './smartuniverse.classes.clientuniversecache';
|
||||
|
||||
export interface IClientOptions {
|
||||
@ -21,9 +21,7 @@ export interface IClientOptions {
|
||||
export class ClientUniverse {
|
||||
public options;
|
||||
public smartsocketClient: plugins.smartsocket.SmartsocketClient;
|
||||
public observableIntake: plugins.smartrx.ObservableIntake<UniverseMessage>;
|
||||
|
||||
public channelStore = new Objectmap<ClientUniverseChannel>();
|
||||
public observableIntake: plugins.smartrx.ObservableIntake<ClientUniverseMessage>;
|
||||
public clientUniverseCache = new ClientUniverseCache();
|
||||
|
||||
constructor(optionsArg: IClientOptions) {
|
||||
@ -34,15 +32,16 @@ export class ClientUniverse {
|
||||
* adds a channel to the channelcache
|
||||
* TODO: verify channel before adding it to the channel cache
|
||||
*/
|
||||
public async addChannel(channelNameArg: string, passphraseArg: string) {
|
||||
const existingChannel = await this.getChannel(channelNameArg);
|
||||
public addChannel(channelNameArg: string, passphraseArg: string) {
|
||||
const existingChannel = this.getChannel(channelNameArg);
|
||||
|
||||
if (existingChannel) {
|
||||
throw new Error('channel exists');
|
||||
}
|
||||
|
||||
// lets create the channel
|
||||
ClientUniverseChannel.createClientUniverseChannel(this, channelNameArg, passphraseArg);
|
||||
const clientUniverseChannel = ClientUniverseChannel.createClientUniverseChannel(this, channelNameArg, passphraseArg);
|
||||
return clientUniverseChannel;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -50,9 +49,8 @@ export class ClientUniverse {
|
||||
* @param channelName
|
||||
* @param passphraseArg
|
||||
*/
|
||||
public async getChannel(channelName: string): Promise<ClientUniverseChannel> {
|
||||
await this.checkConnection();
|
||||
const clientUniverseChannel = this.channelStore.find(channel => {
|
||||
public getChannel(channelName: string): ClientUniverseChannel {
|
||||
const clientUniverseChannel = this.clientUniverseCache.channelMap.find(channel => {
|
||||
return channel.name === channelName;
|
||||
});
|
||||
return clientUniverseChannel;
|
||||
@ -63,27 +61,16 @@ export class ClientUniverse {
|
||||
* @param messageArg
|
||||
*/
|
||||
public removeChannel(channelNameArg, notifyServer = true) {
|
||||
const clientUniverseChannel = this.channelStore.findOneAndRemove(channelItemArg => {
|
||||
const clientUniverseChannel = this.clientUniverseCache.channelMap.findOneAndRemove(channelItemArg => {
|
||||
return channelItemArg.name === channelNameArg;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* sends a message towards the server
|
||||
* @param messageArg
|
||||
*/
|
||||
public async sendMessage(messageArg: interfaces.IMessageCreator) {
|
||||
public async start() {
|
||||
await this.checkConnection();
|
||||
const universeMessageToSend: interfaces.IUniverseMessage = {
|
||||
id: plugins.smartunique.shortId(),
|
||||
timestamp: Date.now(),
|
||||
passphrase: (await this.getChannel(messageArg.targetChannelName)).passphrase,
|
||||
...messageArg
|
||||
};
|
||||
await this.smartsocketClient.serverCall('processMessage', universeMessageToSend);
|
||||
}
|
||||
|
||||
public close() {
|
||||
public stop() {
|
||||
this.smartsocketClient.disconnect();
|
||||
}
|
||||
|
||||
@ -91,7 +78,7 @@ export class ClientUniverse {
|
||||
* checks the connection towards a universe server
|
||||
* since password validation is done through other means, a connection should always be possible
|
||||
*/
|
||||
private async checkConnection(): Promise<void> {
|
||||
public async checkConnection(): Promise<void> {
|
||||
if (!this.smartsocketClient && !this.observableIntake) {
|
||||
const parsedURL = url.parse(this.options.serverAddress);
|
||||
const socketConfig: plugins.smartsocket.ISmartsocketClientOptions = {
|
||||
@ -101,7 +88,6 @@ export class ClientUniverse {
|
||||
role: 'UniverseClient',
|
||||
url: parsedURL.protocol + '//' + parsedURL.hostname
|
||||
};
|
||||
console.log(socketConfig);
|
||||
this.smartsocketClient = new SmartsocketClient(socketConfig);
|
||||
this.observableIntake = new plugins.smartrx.ObservableIntake();
|
||||
|
||||
@ -110,7 +96,7 @@ export class ClientUniverse {
|
||||
/**
|
||||
* should handle a forced unsubscription by the server
|
||||
*/
|
||||
const unsubscribe = new plugins.smartsocket.SocketFunction({
|
||||
const socketFunctionUnsubscribe = new plugins.smartsocket.SocketFunction({
|
||||
funcName: 'unsubscribe',
|
||||
allowedRoles: [],
|
||||
funcDef: async (data: interfaces.IServerUnsubscribeActionPayload) => {
|
||||
@ -119,17 +105,26 @@ export class ClientUniverse {
|
||||
});
|
||||
|
||||
/**
|
||||
* should handle a message reception
|
||||
* handles message reception
|
||||
*/
|
||||
const processMessageSocketFunction = new plugins.smartsocket.SocketFunction({
|
||||
const socketFunctionProcessMessage = new plugins.smartsocket.SocketFunction({
|
||||
funcName: 'processMessage',
|
||||
allowedRoles: [],
|
||||
funcDef: async (data: interfaces.IServerUnsubscribeActionPayload) => {
|
||||
throw new Error('TODO');
|
||||
funcDef: async (messageDescriptorArg: interfaces.IUniverseMessage) => {
|
||||
plugins.smartlog.defaultLogger.log('info', 'Got message from server');
|
||||
this.observableIntake.push(ClientUniverseMessage.createMessageFromMessageDescriptor(messageDescriptorArg));
|
||||
}
|
||||
});
|
||||
|
||||
// add functions
|
||||
this.smartsocketClient.addSocketFunction(socketFunctionUnsubscribe);
|
||||
this.smartsocketClient.addSocketFunction(socketFunctionProcessMessage);
|
||||
|
||||
await this.smartsocketClient.connect();
|
||||
plugins.smartlog.defaultLogger.log('info', 'universe client connected successfully');
|
||||
await this.clientUniverseCache.channelMap.forEach(async clientUniverseChannelArg => {
|
||||
await clientUniverseChannelArg.subscribe();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,11 @@
|
||||
import * as plugins from './smartuniverse.plugins';
|
||||
import { ClientUniverseChannel } from './smartuniverse.classes.clientuniversechannel';
|
||||
|
||||
/**
|
||||
* a cache for clients
|
||||
* keeps track of which messages have already been received
|
||||
* good for deduplication in mesh environments
|
||||
*/
|
||||
export class ClientUniverseCache {}
|
||||
export class ClientUniverseCache {
|
||||
public channelMap = new plugins.lik.Objectmap<ClientUniverseChannel>();
|
||||
}
|
||||
|
@ -13,18 +13,17 @@ export class ClientUniverseChannel implements interfaces.IUniverseChannel {
|
||||
* @param channelNameArg
|
||||
* @param passphraseArg
|
||||
*/
|
||||
public static async createClientUniverseChannel(
|
||||
public static createClientUniverseChannel(
|
||||
clientUniverseArg: ClientUniverse,
|
||||
channelNameArg: string,
|
||||
passphraseArg: string
|
||||
): Promise<ClientUniverseChannel> {
|
||||
): ClientUniverseChannel {
|
||||
const clientChannel = new ClientUniverseChannel(
|
||||
clientUniverseArg,
|
||||
channelNameArg,
|
||||
passphraseArg
|
||||
);
|
||||
clientUniverseArg.channelStore.add(clientChannel);
|
||||
await clientChannel.subscribe();
|
||||
clientUniverseArg.clientUniverseCache.channelMap.add(clientChannel);
|
||||
return clientChannel;
|
||||
}
|
||||
|
||||
@ -37,10 +36,10 @@ export class ClientUniverseChannel implements interfaces.IUniverseChannel {
|
||||
public passphrase: string;
|
||||
|
||||
// refs
|
||||
public clientUniverse: ClientUniverse;
|
||||
public clientUniverseRef: ClientUniverse;
|
||||
|
||||
constructor(clientUniverseArg: ClientUniverse, nameArg: string, passphraseArg: string) {
|
||||
this.clientUniverse = clientUniverseArg;
|
||||
this.clientUniverseRef = clientUniverseArg;
|
||||
this.name = nameArg;
|
||||
this.passphrase = passphraseArg;
|
||||
}
|
||||
@ -55,6 +54,24 @@ export class ClientUniverseChannel implements interfaces.IUniverseChannel {
|
||||
name: this.name,
|
||||
passphrase: this.passphrase
|
||||
};
|
||||
this.clientUniverse.smartsocketClient.serverCall(serverCallActionName, serverCallActionPayload);
|
||||
await this.clientUniverseRef.smartsocketClient.serverCall(serverCallActionName, serverCallActionPayload);
|
||||
}
|
||||
|
||||
/**
|
||||
* sends a message towards the server
|
||||
* @param messageArg
|
||||
*/
|
||||
public async sendMessage(messageArg: interfaces.IMessageCreator) {
|
||||
await this.clientUniverseRef.checkConnection();
|
||||
const universeMessageToSend: interfaces.IUniverseMessage = {
|
||||
id: plugins.smartunique.shortId(),
|
||||
timestamp: Date.now(),
|
||||
passphrase: this.passphrase,
|
||||
targetChannelName: this.name,
|
||||
messageText: messageArg.messageText,
|
||||
payload: messageArg.payload,
|
||||
payloadStringType: messageArg.payloadStringType
|
||||
};
|
||||
await this.clientUniverseRef.smartsocketClient.serverCall('processMessage', universeMessageToSend);
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,10 @@ export class ClientUniverseMessage implements interfaces.IUniverseMessage {
|
||||
// ======
|
||||
// STATIC
|
||||
// ======
|
||||
public static createMessageFromPayload(messageDescriptor: interfaces.IUniverseMessage) {}
|
||||
public static createMessageFromMessageDescriptor(messageDescriptor: interfaces.IUniverseMessage) {
|
||||
const clientuniverseMessage = new ClientUniverseMessage(messageDescriptor);
|
||||
return clientuniverseMessage;
|
||||
}
|
||||
|
||||
// ========
|
||||
// INSTANCE
|
||||
@ -23,11 +26,14 @@ export class ClientUniverseMessage implements interfaces.IUniverseMessage {
|
||||
public payloadStringType;
|
||||
public targetChannelName: string;
|
||||
|
||||
constructor(messageArg: interfaces.IUniverseMessage, payloadArg) {
|
||||
constructor(messageArg: interfaces.IUniverseMessage) {
|
||||
for (const key of Object.keys(messageArg)) {
|
||||
this[key] = messageArg[key];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* gets json for payload
|
||||
*/
|
||||
getAsJsonForPayload() {}
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ export class Universe {
|
||||
|
||||
constructor(optionsArg: ISmartUniverseConstructorOptions) {
|
||||
this.options = optionsArg;
|
||||
this.universeCache = new UniverseCache(this.options.messageExpiryInMilliseconds);
|
||||
this.universeCache = new UniverseCache(this, this.options.messageExpiryInMilliseconds);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -59,8 +59,8 @@ export class Universe {
|
||||
/**
|
||||
* adds a channel to the Universe
|
||||
*/
|
||||
public async addChannel(nameArg: string, passphraseArg: string) {
|
||||
const newChannel = UniverseChannel.createChannel(this.universeCache, nameArg, passphraseArg);
|
||||
public addChannel(nameArg: string, passphraseArg: string) {
|
||||
const newChannel = UniverseChannel.createChannel(this, nameArg, passphraseArg);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -89,7 +89,7 @@ export class Universe {
|
||||
// add the role to smartsocket
|
||||
this.smartsocket.addSocketRoles([ClientRole]);
|
||||
|
||||
const SubscriptionSocketFunction = new plugins.smartsocket.SocketFunction({
|
||||
const socketFunctionSubscription = new plugins.smartsocket.SocketFunction({
|
||||
allowedRoles: [ClientRole], // there is only one client role, Authentication happens on another level
|
||||
funcName: 'channelSubscription',
|
||||
funcDef: async (
|
||||
@ -98,12 +98,11 @@ export class Universe {
|
||||
) => {
|
||||
// run in "this context" of this class
|
||||
await (async () => {
|
||||
// TODO: properly add the connection
|
||||
const universeConnection = new UniverseConnection({
|
||||
socketConnection: socketConnectionArg,
|
||||
authenticationRequests: []
|
||||
authenticationRequests: [dataArg]
|
||||
});
|
||||
await UniverseConnection.addConnectionToCache(this.universeCache, universeConnection);
|
||||
await UniverseConnection.addConnectionToCache(this, universeConnection);
|
||||
return {
|
||||
'subscription status': 'success'
|
||||
};
|
||||
@ -111,7 +110,7 @@ export class Universe {
|
||||
}
|
||||
});
|
||||
|
||||
const ProcessMessageSocketFunction = new plugins.smartsocket.SocketFunction({
|
||||
const socketFunctionProcessMessage = new plugins.smartsocket.SocketFunction({
|
||||
allowedRoles: [ClientRole], // there is only one client role, Authentication happens on another level
|
||||
funcName: 'processMessage',
|
||||
funcDef: async (dataArg: interfaces.IUniverseMessage, socketConnectionArg) => {
|
||||
@ -122,33 +121,36 @@ export class Universe {
|
||||
socketConnectionArg
|
||||
);
|
||||
if (universeConnection) {
|
||||
console.log('found UniverseConnection for socket');
|
||||
plugins.smartlog.defaultLogger.log('ok', 'found UniverseConnection for socket for incoming message');
|
||||
} else {
|
||||
console.log('universe client not yet present');
|
||||
console.log('creating one now as send only');
|
||||
const universeConnectionInstance = new UniverseConnection({
|
||||
socketConnection: socketConnectionArg,
|
||||
authenticationRequests: []
|
||||
});
|
||||
await UniverseConnection.addConnectionToCache(
|
||||
this.universeCache,
|
||||
universeConnectionInstance
|
||||
);
|
||||
plugins.smartlog.defaultLogger.log('warn', 'found no Authorized channel for incoming message');
|
||||
return {
|
||||
error: 'You need to authenticate for a channel'
|
||||
};
|
||||
}
|
||||
await UniverseChannel.authorizeAMessageForAChannel(
|
||||
const unauthenticatedMessage = UniverseMessage.createMessageFromPayload(socketConnectionArg, dataArg);
|
||||
const foundChannel = await UniverseChannel.authorizeAMessageForAChannel(
|
||||
this.universeCache,
|
||||
UniverseMessage.createMessageFromPayload(dataArg)
|
||||
unauthenticatedMessage
|
||||
);
|
||||
if (foundChannel && unauthenticatedMessage.authenticated) {
|
||||
const authenticatedMessage = unauthenticatedMessage;
|
||||
await this.universeCache.addMessage(authenticatedMessage);
|
||||
}
|
||||
})();
|
||||
}
|
||||
});
|
||||
|
||||
// add socket functions
|
||||
this.smartsocket.addSocketFunction(socketFunctionSubscription);
|
||||
this.smartsocket.addSocketFunction(socketFunctionProcessMessage);
|
||||
|
||||
// add smartsocket to the running smartexpress app
|
||||
this.smartsocket.setExternalServer('smartexpress', this.smartexpressServer as any);
|
||||
// start everything
|
||||
await this.smartexpressServer.start();
|
||||
await this.smartsocket.start();
|
||||
console.log('started universe');
|
||||
plugins.smartlog.defaultLogger.log('success', 'started universe');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -9,6 +9,7 @@ import { Observable, from } from 'rxjs';
|
||||
import { filter } from 'rxjs/operators';
|
||||
import { rxjs } from '@pushrocks/smartrx';
|
||||
import { UniverseConnection } from './smartuniverse.classes.universeconnection';
|
||||
import { Universe } from './smartuniverse.classes.universe';
|
||||
|
||||
/**
|
||||
* universe store handles the creation, storage and retrieval of messages.
|
||||
@ -30,15 +31,22 @@ export class UniverseCache {
|
||||
*/
|
||||
public channelMap = new Objectmap<UniverseChannel>();
|
||||
|
||||
/**
|
||||
* stores all connections
|
||||
*/
|
||||
public connectionMap = new plugins.lik.Objectmap<UniverseConnection>();
|
||||
|
||||
/**
|
||||
* allows messages to be processed in a blacklist mode for further analysis
|
||||
*/
|
||||
public blackListChannel = new UniverseChannel(this, 'blacklist', 'nada');
|
||||
public blackListChannel: UniverseChannel;
|
||||
|
||||
constructor(standardMessageExpiryArg: number) {
|
||||
public universeRef: Universe;
|
||||
|
||||
constructor(universeArg: Universe, standardMessageExpiryArg: number) {
|
||||
this.universeRef = universeArg;
|
||||
this.standardMessageExpiry = standardMessageExpiryArg;
|
||||
this.blackListChannel = new UniverseChannel(this.universeRef, 'blacklist', 'nada');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -50,6 +58,9 @@ export class UniverseCache {
|
||||
messageArg.setUniverseCache(this);
|
||||
UniverseChannel.authorizeAMessageForAChannel(this, messageArg);
|
||||
this.messageMap.add(messageArg);
|
||||
messageArg.universeChannelList.forEach(universeChannel => {
|
||||
universeChannel.pushToClients(messageArg);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,7 +1,10 @@
|
||||
import * as plugins from './smartuniverse.plugins';
|
||||
import * as interfaces from './interfaces';
|
||||
|
||||
import { UniverseCache } from './smartuniverse.classes.universecache';
|
||||
import { UniverseMessage } from './smartuniverse.classes.universemessage';
|
||||
import { UniverseConnection } from './smartuniverse.classes.universeconnection';
|
||||
import { Universe } from './smartuniverse.classes.universe';
|
||||
|
||||
/**
|
||||
* enables messages to stay within a certain scope.
|
||||
@ -17,12 +20,12 @@ export class UniverseChannel {
|
||||
* @param passphraseArg the secret thats used for a certain topic.
|
||||
*/
|
||||
public static createChannel(
|
||||
universeCacheArg: UniverseCache,
|
||||
universeArg: Universe,
|
||||
channelNameArg: string,
|
||||
passphraseArg: string
|
||||
) {
|
||||
const newChannel = new UniverseChannel(universeCacheArg, channelNameArg, passphraseArg);
|
||||
universeCacheArg.channelMap.add(newChannel);
|
||||
const newChannel = new UniverseChannel(universeArg, channelNameArg, passphraseArg);
|
||||
universeArg.universeCache.channelMap.add(newChannel);
|
||||
return newChannel;
|
||||
}
|
||||
|
||||
@ -50,7 +53,7 @@ export class UniverseChannel {
|
||||
public static authorizeAMessageForAChannel(
|
||||
universeCacheArg: UniverseCache,
|
||||
universeMessageArg: UniverseMessage
|
||||
) {
|
||||
): UniverseChannel {
|
||||
const foundChannel = universeCacheArg.channelMap.find(universeChannel => {
|
||||
const result = universeChannel.authenticate(universeMessageArg);
|
||||
return result;
|
||||
@ -58,14 +61,22 @@ export class UniverseChannel {
|
||||
if (foundChannel) {
|
||||
universeMessageArg.authenticated = true;
|
||||
universeMessageArg.universeChannelList.add(foundChannel);
|
||||
plugins.smartlog.defaultLogger.log('ok', 'message authorized');
|
||||
return foundChannel;
|
||||
} else {
|
||||
universeMessageArg.authenticated = false;
|
||||
universeMessageArg.universeChannelList.add(universeCacheArg.blackListChannel);
|
||||
console.log('message not valid');
|
||||
plugins.smartlog.defaultLogger.log('warn', 'message not valid');
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static getUniverseChannelByName(universeRef: Universe, universeChannelName: string) {
|
||||
return universeRef.universeCache.channelMap.find(channelArg => {
|
||||
return channelArg.name === universeChannelName;
|
||||
});
|
||||
}
|
||||
|
||||
// ========
|
||||
// INSTANCE
|
||||
// ========
|
||||
@ -73,14 +84,15 @@ export class UniverseChannel {
|
||||
* the name of the channel
|
||||
*/
|
||||
public name: string;
|
||||
public universeCacheInstance: UniverseCache;
|
||||
public universeRef: Universe;
|
||||
|
||||
/**
|
||||
* the passphrase for the channel
|
||||
*/
|
||||
public passphrase: string;
|
||||
|
||||
constructor(universeCacheArg: UniverseCache, channelNameArg: string, passphraseArg: string) {
|
||||
constructor(universeArg: Universe, channelNameArg: string, passphraseArg: string) {
|
||||
this.universeRef = universeArg;
|
||||
this.name = channelNameArg;
|
||||
this.passphrase = passphraseArg;
|
||||
}
|
||||
@ -97,5 +109,29 @@ export class UniverseChannel {
|
||||
);
|
||||
}
|
||||
|
||||
public pushToClients(messageArg: UniverseMessage) {}
|
||||
/**
|
||||
* pushes a message to clients
|
||||
* @param messageArg
|
||||
*/
|
||||
public async pushToClients(messageArg: UniverseMessage) {
|
||||
const universeConnectionsWithChannelAccess: UniverseConnection[] = [];
|
||||
this.universeRef.universeCache.connectionMap.forEach(async socketConnection => {
|
||||
if (socketConnection.authenticatedChannels.includes(this)) {
|
||||
universeConnectionsWithChannelAccess.push(socketConnection);
|
||||
}
|
||||
});
|
||||
for (const universeConnection of universeConnectionsWithChannelAccess) {
|
||||
const smartsocket = universeConnection.socketConnection.smartsocketRef as plugins.smartsocket.Smartsocket;
|
||||
const universeMessageToSend: interfaces.IUniverseMessage = {
|
||||
id: messageArg.id,
|
||||
timestamp: messageArg.timestamp,
|
||||
passphrase: messageArg.passphrase,
|
||||
targetChannelName: this.name,
|
||||
messageText: messageArg.messageText,
|
||||
payload: messageArg.payload,
|
||||
payloadStringType: messageArg.payloadStringType
|
||||
};
|
||||
smartsocket.clientCall('processMessage', universeMessageToSend, universeConnection.socketConnection);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ import * as plugins from './smartuniverse.plugins';
|
||||
import * as interfaces from './interfaces';
|
||||
import { UniverseChannel } from './smartuniverse.classes.universechannel';
|
||||
import { UniverseCache } from './smartuniverse.classes.universecache';
|
||||
import { Universe } from './smartuniverse.classes.universe';
|
||||
|
||||
/**
|
||||
* represents a connection to the universe
|
||||
@ -12,17 +13,19 @@ export class UniverseConnection {
|
||||
* @param universeConnectionArg
|
||||
*/
|
||||
public static async addConnectionToCache(
|
||||
universeCache: UniverseCache,
|
||||
universeRef: Universe,
|
||||
universeConnectionArg: UniverseConnection
|
||||
) {
|
||||
let universeConnection = universeConnectionArg;
|
||||
universeConnection = await UniverseConnection.deduplicateUniverseConnection(
|
||||
universeCache,
|
||||
universeRef.universeCache,
|
||||
universeConnection
|
||||
);
|
||||
universeConnection = await UniverseConnection.authenticateAuthenticationRequests(
|
||||
universeRef,
|
||||
universeConnection
|
||||
);
|
||||
universeRef.universeCache.connectionMap.add(universeConnection);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -50,10 +53,16 @@ export class UniverseConnection {
|
||||
/**
|
||||
* authenticate AuthenticationRequests
|
||||
*/
|
||||
public static authenticateAuthenticationRequests(
|
||||
universeConnectionArg
|
||||
public static async authenticateAuthenticationRequests(
|
||||
universeRef: Universe,
|
||||
universeConnectionArg: UniverseConnection
|
||||
): Promise<UniverseConnection> {
|
||||
// TODO: authenticate connections
|
||||
for (const authenticationRequest of universeConnectionArg.authenticationRequests) {
|
||||
const universeChannelToAuthenticateAgainst = UniverseChannel.getUniverseChannelByName(universeRef, authenticationRequest.name);
|
||||
if (universeChannelToAuthenticateAgainst.passphrase === authenticationRequest.passphrase) {
|
||||
universeConnectionArg.authenticatedChannels.push(universeChannelToAuthenticateAgainst);
|
||||
}
|
||||
}
|
||||
return universeConnectionArg;
|
||||
}
|
||||
|
||||
@ -64,7 +73,6 @@ export class UniverseConnection {
|
||||
connectionArg1: UniverseConnection,
|
||||
connectionArg2: UniverseConnection
|
||||
) {
|
||||
// TODO: merge connections
|
||||
return connectionArg1;
|
||||
}
|
||||
|
||||
@ -87,7 +95,7 @@ export class UniverseConnection {
|
||||
* the socketClient to ping
|
||||
*/
|
||||
public socketConnection: plugins.smartsocket.SocketConnection;
|
||||
public authenticationRequests = [];
|
||||
public authenticationRequests: interfaces.IServerCallSubscribeActionPayload[] = [];
|
||||
public subscribedChannels: UniverseChannel[] = [];
|
||||
public authenticatedChannels: UniverseChannel[] = [];
|
||||
public failedToJoinChannels: UniverseChannel[] = [];
|
||||
@ -104,7 +112,7 @@ export class UniverseConnection {
|
||||
socketConnection: plugins.smartsocket.SocketConnection;
|
||||
authenticationRequests: interfaces.IServerCallSubscribeActionPayload[];
|
||||
}) {
|
||||
// TODO: check if this is correct
|
||||
this.authenticationRequests = optionsArg.authenticationRequests;
|
||||
this.socketConnection = optionsArg.socketConnection;
|
||||
}
|
||||
}
|
||||
|
@ -7,27 +7,28 @@ import { Timer, TimeStamp } from '@pushrocks/smarttime';
|
||||
import { Universe } from './smartuniverse.classes.universe';
|
||||
import { UniverseChannel } from './smartuniverse.classes.universechannel';
|
||||
import { UniverseCache } from './smartuniverse.classes.universecache';
|
||||
import { IUniverseMessage } from './interfaces';
|
||||
import { SocketConnection } from '@pushrocks/smartsocket';
|
||||
|
||||
/**
|
||||
* represents a message within a universe
|
||||
* acts as a container to save message states like authentication status
|
||||
*/
|
||||
export class UniverseMessage implements interfaces.IUniverseMessage {
|
||||
public static createMessageFromPayload(dataArg: interfaces.IUniverseMessage) {
|
||||
return new UniverseMessage(dataArg);
|
||||
public static createMessageFromPayload(socketConnectionArg: SocketConnection, dataArg: interfaces.IUniverseMessage) {
|
||||
const universeMessageInstance = new UniverseMessage(dataArg);
|
||||
universeMessageInstance.socketConnection = socketConnectionArg;
|
||||
return universeMessageInstance;
|
||||
}
|
||||
|
||||
public id: string;
|
||||
|
||||
public timestamp: number;
|
||||
public smartTimestamp: TimeStamp;
|
||||
|
||||
public messageText: string;
|
||||
public passphrase: string;
|
||||
public payload: any;
|
||||
public payloadStringType;
|
||||
public targetChannelName: string;
|
||||
public socketConnection: SocketConnection;
|
||||
|
||||
/**
|
||||
* the UniverseCache the message is attached to
|
||||
@ -42,7 +43,7 @@ export class UniverseMessage implements interfaces.IUniverseMessage {
|
||||
/**
|
||||
* wether the message is authenticated
|
||||
*/
|
||||
public authenticated: boolean = null;
|
||||
public authenticated: boolean = false;
|
||||
|
||||
/**
|
||||
* a destruction timer for this message
|
||||
@ -54,7 +55,7 @@ export class UniverseMessage implements interfaces.IUniverseMessage {
|
||||
* @param messageArg
|
||||
* @param attachedPayloadArg
|
||||
*/
|
||||
constructor(messageDescriptor: IUniverseMessage) {
|
||||
constructor(messageDescriptor: interfaces.IUniverseMessage) {
|
||||
this.smartTimestamp = new TimeStamp(this.timestamp);
|
||||
this.messageText = messageDescriptor.messageText;
|
||||
this.targetChannelName = messageDescriptor.targetChannelName;
|
||||
@ -68,6 +69,10 @@ export class UniverseMessage implements interfaces.IUniverseMessage {
|
||||
this.universeCache = universeCacheArg;
|
||||
}
|
||||
|
||||
public setTargetChannel() {
|
||||
|
||||
}
|
||||
|
||||
public setDestructionTimer(selfdestructAfterArg: number) {
|
||||
if (selfdestructAfterArg) {
|
||||
this.destructionTimer = new Timer(selfdestructAfterArg);
|
||||
@ -86,7 +91,7 @@ export class UniverseMessage implements interfaces.IUniverseMessage {
|
||||
* handles bad messages for further analysis
|
||||
*/
|
||||
public handleAsBadMessage() {
|
||||
console.log('received a bad message');
|
||||
plugins.smartlog.defaultLogger.log('warn', 'received a bad message');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -9,6 +9,7 @@ import * as smarthash from '@pushrocks/smarthash';
|
||||
import * as smartdelay from '@pushrocks/smartdelay';
|
||||
import * as smartexpress from '@pushrocks/smartexpress';
|
||||
import * as smartfile from '@pushrocks/smartfile';
|
||||
import * as smartlog from '@pushrocks/smartlog';
|
||||
import * as smartpromise from '@pushrocks/smartpromise';
|
||||
import * as smartrequest from '@pushrocks/smartrequest';
|
||||
import * as smartrx from '@pushrocks/smartrx';
|
||||
@ -22,6 +23,7 @@ export {
|
||||
smartdelay,
|
||||
smartexpress,
|
||||
smartfile,
|
||||
smartlog,
|
||||
smartpromise,
|
||||
smartrx,
|
||||
smartrequest,
|
||||
|
Reference in New Issue
Block a user