Compare commits

..

6 Commits

Author SHA1 Message Date
2a9e58cc35 1.2.7 2021-01-28 12:39:32 +00:00
7d6a9921b5 fix(core): update 2021-01-28 12:39:31 +00:00
3ee46a31f7 1.2.6 2021-01-28 01:39:24 +00:00
d72310ce10 fix(core): update 2021-01-28 01:39:23 +00:00
1e14166ddb 1.2.5 2021-01-28 01:31:43 +00:00
be38e91548 fix(core): update 2021-01-28 01:31:42 +00:00
6 changed files with 41 additions and 28 deletions

8
package-lock.json generated
View File

@ -1,6 +1,6 @@
{ {
"name": "@pushrocks/smartsocket", "name": "@pushrocks/smartsocket",
"version": "1.2.4", "version": "1.2.7",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {
@ -1567,9 +1567,9 @@
} }
}, },
"@pushrocks/smartjson": { "@pushrocks/smartjson": {
"version": "4.0.5", "version": "4.0.6",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartjson/-/smartjson-4.0.5.tgz", "resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartjson/-/smartjson-4.0.6.tgz",
"integrity": "sha512-i4kBjZSbs1t8swcAPEdPkDJHci2higzvMIkNUKTgXWrcxUFMuOis/B5huUnnIqg/Td8R+mAdf/B/CMfgjABTlg==", "integrity": "sha512-lykr068RSDHs0+EXCvIDVxjKnDtRQ2M7EXOo5jVrUU6/OEdfRl9ErM1K/oPafiEi47/PtTrwLlp1KdSgqkRjmg==",
"requires": { "requires": {
"@types/buffer-json": "^2.0.0", "@types/buffer-json": "^2.0.0",
"@types/fast-json-stable-stringify": "^2.0.0", "@types/fast-json-stable-stringify": "^2.0.0",

View File

@ -1,6 +1,6 @@
{ {
"name": "@pushrocks/smartsocket", "name": "@pushrocks/smartsocket",
"version": "1.2.4", "version": "1.2.7",
"description": "easy and secure websocket communication", "description": "easy and secure websocket communication",
"main": "dist_ts/index.js", "main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts", "typings": "dist_ts/index.d.ts",
@ -26,7 +26,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",

View File

@ -90,16 +90,30 @@ tap.test('should react to a new websocket connection from client', async () => {
await testSmartsocketClient.connect(); await testSmartsocketClient.connect();
}); });
tap.test('should be able to tag a connection', async (tools) => { tap.test('should be able to tag a connection from client', async (tools) => {
await testSmartsocketClient.addTag({ await testSmartsocketClient.addTag({
id: 'awesome', id: 'awesome',
payload: 'yes' payload: 'yes',
}); });
const tagOnServerSide = await testSmartsocket.socketConnections.find((socketConnection) => { const tagOnServerSide = await testSmartsocket.socketConnections
return true; .find((socketConnection) => {
}).getTagById('awesome'); return true;
})
.getTagById('awesome');
expect(tagOnServerSide.payload).to.equal('yes'); expect(tagOnServerSide.payload).to.equal('yes');
}) });
tap.test('should be able to tag a connection from server', async (tools) => {
await testSmartsocket.socketConnections
.find((socketConnection) => {
return true;
}).addTag({
id: 'awesome2',
payload: 'absolutely',
});
const tagOnClientSide = await testSmartsocketClient.socketConnection.getTagById('awesome2');
expect(tagOnClientSide.payload).to.equal('absolutely');
});
tap.test('2 clients should connect in parallel', async () => { tap.test('2 clients should connect in parallel', async () => {
// TODO: implement parallel test // TODO: implement parallel test

View File

@ -1,6 +1,6 @@
export interface ITag <T = any> { export interface ITag<T = any> {
id: string; id: string;
payload: T; payload: T;
} }
export type TTagStore = {[key: string]: ITag}; export type TTagStore = { [key: string]: ITag };

View File

@ -46,7 +46,7 @@ export class SmartsocketClient {
public socketRoles = new plugins.lik.ObjectMap<SocketRole>(); public socketRoles = new plugins.lik.ObjectMap<SocketRole>();
// tagStore // tagStore
private tagStore: {[key: string]: interfaces.ITag} = {}; private tagStore: { [key: string]: interfaces.ITag } = {};
private tagStoreSubscription: plugins.smartrx.rxjs.Subscription; private tagStoreSubscription: plugins.smartrx.rxjs.Subscription;
/** /**
@ -66,7 +66,7 @@ export class SmartsocketClient {
*/ */
public async getTagById(tagIdArg: interfaces.ITag['id']) { public async getTagById(tagIdArg: interfaces.ITag['id']) {
return this.tagStore[tagIdArg]; return this.tagStore[tagIdArg];
}; }
/** /**
* removes a tag from a connection * removes a tag from a connection
@ -164,12 +164,15 @@ export class SmartsocketClient {
// handle connection // handle connection
this.socketConnection.socket.on('connect', async () => { this.socketConnection.socket.on('connect', async () => {
this.tagStoreSubscription?.unsubscribe(); this.tagStoreSubscription?.unsubscribe();
this.tagStoreSubscription = this.socketConnection.tagStoreObservable.subscribe(tagStoreArg => {
this.tagStore = tagStoreArg
});
for (const keyArg of Object.keys(this.tagStore)) { for (const keyArg of Object.keys(this.tagStore)) {
this.socketConnection.addTag(this.tagStore[keyArg]); this.socketConnection.addTag(this.tagStore[keyArg]);
} }
this.tagStoreSubscription = this.socketConnection.tagStoreObservable.subscribe(
(tagStoreArg) => {
this.tagStore = tagStoreArg;
}
);
this.updateStatus('connected'); this.updateStatus('connected');
}); });

View File

@ -95,12 +95,12 @@ export class SocketConnection {
this.tagStoreObservable.next(this.tagStore); this.tagStoreObservable.next(this.tagStore);
const remoteSubscription = this.remoteTagStoreObservable.subscribe((remoteTagStore) => { const remoteSubscription = this.remoteTagStoreObservable.subscribe((remoteTagStore) => {
const localTagString = plugins.smartjson.stringify(tagArg); const localTagString = plugins.smartjson.stringify(tagArg);
const remoteTagString = plugins.smartjson.stringify(remoteTagStore[tagArg.id]) const remoteTagString = plugins.smartjson.stringify(remoteTagStore[tagArg.id]);
if (localTagString === remoteTagString) { if (localTagString === remoteTagString) {
remoteSubscription.unsubscribe(); remoteSubscription.unsubscribe();
done.resolve(); done.resolve();
} }
}) });
this.socket.emit('updateTagStore', this.tagStore); this.socket.emit('updateTagStore', this.tagStore);
await done.promise; await done.promise;
} }
@ -111,7 +111,7 @@ export class SocketConnection {
*/ */
public async getTagById(tagIdArg: interfaces.ITag['id']) { public async getTagById(tagIdArg: interfaces.ITag['id']) {
return this.tagStore[tagIdArg]; return this.tagStore[tagIdArg];
}; }
/** /**
* removes a tag from a connection * removes a tag from a connection
@ -192,17 +192,13 @@ export class SocketConnection {
}); });
this.socket.on('updateTagStore', async (tagStoreArg: interfaces.TTagStore) => { this.socket.on('updateTagStore', async (tagStoreArg: interfaces.TTagStore) => {
const exitingStoreString = plugins.smartjson.stringify(this.tagStore); if (!plugins.smartjson.deepEqualObjects(this.tagStore, tagStoreArg)) {
const newStoreString = plugins.smartjson.stringify(tagStoreArg);
console.log(exitingStoreString);
console.log(newStoreString);
if (exitingStoreString !== newStoreString) {
this.tagStore = tagStoreArg; this.tagStore = tagStoreArg;
this.socket.emit('updateTagStore', this.tagStore); this.socket.emit('updateTagStore', this.tagStore);
this.tagStoreObservable.next(this.tagStore); this.tagStoreObservable.next(this.tagStore);
} }
this.remoteTagStoreObservable.next(tagStoreArg); this.remoteTagStoreObservable.next(tagStoreArg);
}) });
logger.log('info', `now listening to function requests for ${this.alias}`); logger.log('info', `now listening to function requests for ${this.alias}`);
done.resolve(this); done.resolve(this);