fix(core): update

This commit is contained in:
Philipp Kunz 2021-01-28 12:58:42 +00:00
parent 969b2d6686
commit fef1ae338a
3 changed files with 40 additions and 13 deletions

20
package-lock.json generated
View File

@ -1950,9 +1950,9 @@
} }
}, },
"@pushrocks/smartsocket": { "@pushrocks/smartsocket": {
"version": "1.2.6", "version": "1.2.7",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartsocket/-/smartsocket-1.2.6.tgz", "resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartsocket/-/smartsocket-1.2.7.tgz",
"integrity": "sha512-rHOs/ANrgnrt+AHuUNAOzb+X5FrtP/yaC/6qp7lQSorb6x73T5343/9TB875kI1Q3trqlwJDvJy7+uJQ7zMMhg==", "integrity": "sha512-EBtWZRnoC9/0/KuBq2k6fTeFXx6r4LvXTS64VvC2lJkx5UgWhG0ZNhOTkMtVlf96fCk5Y9v9PS8UbG8fO7M1Gg==",
"requires": { "requires": {
"@apiglobal/typedrequest-interfaces": "^1.0.15", "@apiglobal/typedrequest-interfaces": "^1.0.15",
"@pushrocks/isohash": "^1.0.2", "@pushrocks/isohash": "^1.0.2",
@ -1961,7 +1961,7 @@
"@pushrocks/smartdelay": "^2.0.10", "@pushrocks/smartdelay": "^2.0.10",
"@pushrocks/smartenv": "^4.0.16", "@pushrocks/smartenv": "^4.0.16",
"@pushrocks/smartexpress": "^3.0.100", "@pushrocks/smartexpress": "^3.0.100",
"@pushrocks/smartjson": "^4.0.5", "@pushrocks/smartjson": "^4.0.6",
"@pushrocks/smartlog": "^2.0.39", "@pushrocks/smartlog": "^2.0.39",
"@pushrocks/smartpromise": "^3.1.3", "@pushrocks/smartpromise": "^3.1.3",
"@pushrocks/smartrx": "^2.0.19", "@pushrocks/smartrx": "^2.0.19",
@ -1972,6 +1972,18 @@
"socket.io-client": "^3.1.0" "socket.io-client": "^3.1.0"
}, },
"dependencies": { "dependencies": {
"@pushrocks/smartjson": {
"version": "4.0.6",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartjson/-/smartjson-4.0.6.tgz",
"integrity": "sha512-lykr068RSDHs0+EXCvIDVxjKnDtRQ2M7EXOo5jVrUU6/OEdfRl9ErM1K/oPafiEi47/PtTrwLlp1KdSgqkRjmg==",
"requires": {
"@types/buffer-json": "^2.0.0",
"@types/fast-json-stable-stringify": "^2.0.0",
"buffer-json": "^2.0.0",
"fast-json-stable-stringify": "^2.1.0",
"lodash.clonedeep": "^4.5.0"
}
},
"@pushrocks/smarttime": { "@pushrocks/smarttime": {
"version": "3.0.38", "version": "3.0.38",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmarttime/-/smarttime-3.0.38.tgz", "resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmarttime/-/smarttime-3.0.38.tgz",

View File

@ -25,7 +25,7 @@
"@apiglobal/typedrequest-interfaces": "^1.0.15", "@apiglobal/typedrequest-interfaces": "^1.0.15",
"@pushrocks/isohash": "^1.0.2", "@pushrocks/isohash": "^1.0.2",
"@pushrocks/smartexpress": "^3.0.100", "@pushrocks/smartexpress": "^3.0.100",
"@pushrocks/smartsocket": "^1.2.6", "@pushrocks/smartsocket": "^1.2.7",
"@pushrocks/smartstring": "^3.0.24" "@pushrocks/smartstring": "^3.0.24"
}, },
"browserslist": [ "browserslist": [

View File

@ -82,6 +82,7 @@ export class TypedSocket {
url: `${domain.nodeParsedUrl.protocol}//${domain.nodeParsedUrl.hostname}`, url: `${domain.nodeParsedUrl.protocol}//${domain.nodeParsedUrl.hostname}`,
autoReconnect: true, autoReconnect: true,
} }
console.log(`starting typedsocket with the following settings:`)
console.log(socketOptions); console.log(socketOptions);
const smartsocketClient = new plugins.smartsocket.SmartsocketClient(socketOptions); const smartsocketClient = new plugins.smartsocket.SmartsocketClient(socketOptions);
smartsocketClient.addSocketFunction( smartsocketClient.addSocketFunction(
@ -156,32 +157,46 @@ export class TypedSocket {
return typedrequest; return typedrequest;
} }
public async findTargetConnection( public async findAllTargetConnections(
findFuncArg: (connectionArg: plugins.smartsocket.SocketConnection) => boolean asyncFindFuncArg: (connectionArg: plugins.smartsocket.SocketConnection) => Promise<boolean>
) { ) {
if (this.socketServerOrClient instanceof plugins.smartsocket.Smartsocket) { if (this.socketServerOrClient instanceof plugins.smartsocket.Smartsocket) {
const matchingSockets: plugins.smartsocket.SocketConnection[] = [];
for (const socketConnection of this.socketServerOrClient.socketConnections.getArray()) { for (const socketConnection of this.socketServerOrClient.socketConnections.getArray()) {
if (findFuncArg(socketConnection)) { if (await asyncFindFuncArg(socketConnection)) {
return socketConnection; matchingSockets.push(socketConnection);
} }
} }
return matchingSockets;
} else { } else {
throw new Error('this method >>findTargetConnection<< is only available from the server'); throw new Error('this method >>findTargetConnection<< is only available from the server');
} }
} }
public async findTargetConnectionByTag(keyArg: string, payload?: any) { public async findTargetConnection(
this.findTargetConnection(socketConnectionArg => { asyncFindFuncArg: (connectionArg: plugins.smartsocket.SocketConnection) => Promise<boolean>
) {
const allMatching = this.findAllTargetConnections(asyncFindFuncArg);
return allMatching[0];
}
public async findAllTargetConnectionsByTag(keyArg: string, payloadArg?: any) {
return this.findAllTargetConnections(async socketConnectionArg => {
let result: boolean; let result: boolean;
if (!payload) { if (!payloadArg) {
result = !!socketConnectionArg.getTagById('keyArg') result = !!socketConnectionArg.getTagById('keyArg')
} else { } else {
result = !!socketConnectionArg.getTagById('keyArg') === payload; result = !!socketConnectionArg.getTagById('keyArg') === payloadArg;
} }
return result; return result;
}) })
} }
public async findTargetConnectionByTag(keyArg: string, payloadArg?: any) {
const allResults = this.findAllTargetConnectionsByTag(keyArg, payloadArg)
return allResults[0];
}
public async stop() { public async stop() {
await this.socketServerOrClient.stop() await this.socketServerOrClient.stop()
} }