6 Commits

Author SHA1 Message Date
1a36912461 1.0.22 2022-03-29 14:56:22 +02:00
1dcbdcc06d fix(core): update 2022-03-29 14:56:21 +02:00
c7d0c8723f 1.0.21 2022-03-29 13:18:10 +02:00
ae377b185e fix(core): update 2022-03-29 13:18:09 +02:00
eab145e736 1.0.20 2022-03-29 13:14:10 +02:00
4060d64ed4 fix(core): update 2022-03-29 13:14:10 +02:00
4 changed files with 27 additions and 19 deletions

18
package-lock.json generated
View File

@@ -1,15 +1,15 @@
{ {
"name": "@designestate/dees-comms", "name": "@designestate/dees-comms",
"version": "1.0.19", "version": "1.0.22",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "@designestate/dees-comms", "name": "@designestate/dees-comms",
"version": "1.0.19", "version": "1.0.22",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@apiglobal/typedrequest": "^2.0.2", "@apiglobal/typedrequest": "^2.0.3",
"@apiglobal/typedrequest-interfaces": "^1.0.15", "@apiglobal/typedrequest-interfaces": "^1.0.15",
"@pushrocks/smartdelay": "^2.0.13", "@pushrocks/smartdelay": "^2.0.13",
"broadcast-channel": "^3.7.0" "broadcast-channel": "^3.7.0"
@@ -36,9 +36,9 @@
} }
}, },
"node_modules/@apiglobal/typedrequest": { "node_modules/@apiglobal/typedrequest": {
"version": "2.0.2", "version": "2.0.3",
"resolved": "https://verdaccio.lossless.one/@apiglobal%2ftypedrequest/-/typedrequest-2.0.2.tgz", "resolved": "https://verdaccio.lossless.one/@apiglobal%2ftypedrequest/-/typedrequest-2.0.3.tgz",
"integrity": "sha512-bd5N4sbHMLf28mHvC0oweLhsbhFUMvS+7qbzYdKDWC1Ge7b3U1jRi/RT4jWWPew6TiYsxcLLLcEHZh3uoULWeA==", "integrity": "sha512-bRXiv3OwPh4uA4ete9maHXyF3CMNz8rc81r41DBeYzscaadKlQSK0ewOBLQjjZ2MBWDAGR0NbGBEaJJrXqYS0w==",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@apiglobal/typedrequest-interfaces": "^1.0.15", "@apiglobal/typedrequest-interfaces": "^1.0.15",
@@ -10768,9 +10768,9 @@
} }
}, },
"@apiglobal/typedrequest": { "@apiglobal/typedrequest": {
"version": "2.0.2", "version": "2.0.3",
"resolved": "https://verdaccio.lossless.one/@apiglobal%2ftypedrequest/-/typedrequest-2.0.2.tgz", "resolved": "https://verdaccio.lossless.one/@apiglobal%2ftypedrequest/-/typedrequest-2.0.3.tgz",
"integrity": "sha512-bd5N4sbHMLf28mHvC0oweLhsbhFUMvS+7qbzYdKDWC1Ge7b3U1jRi/RT4jWWPew6TiYsxcLLLcEHZh3uoULWeA==", "integrity": "sha512-bRXiv3OwPh4uA4ete9maHXyF3CMNz8rc81r41DBeYzscaadKlQSK0ewOBLQjjZ2MBWDAGR0NbGBEaJJrXqYS0w==",
"requires": { "requires": {
"@apiglobal/typedrequest-interfaces": "^1.0.15", "@apiglobal/typedrequest-interfaces": "^1.0.15",
"@pushrocks/isounique": "^1.0.5", "@pushrocks/isounique": "^1.0.5",

View File

@@ -1,6 +1,6 @@
{ {
"name": "@designestate/dees-comms", "name": "@designestate/dees-comms",
"version": "1.0.19", "version": "1.0.22",
"private": false, "private": false,
"description": "a comms module for communicating within the DOM", "description": "a comms module for communicating within the DOM",
"main": "dist_ts/index.js", "main": "dist_ts/index.js",
@@ -20,7 +20,7 @@
"@types/node": "^17.0.23" "@types/node": "^17.0.23"
}, },
"dependencies": { "dependencies": {
"@apiglobal/typedrequest": "^2.0.2", "@apiglobal/typedrequest": "^2.0.3",
"@apiglobal/typedrequest-interfaces": "^1.0.15", "@apiglobal/typedrequest-interfaces": "^1.0.15",
"@pushrocks/smartdelay": "^2.0.13", "@pushrocks/smartdelay": "^2.0.13",
"broadcast-channel": "^3.7.0" "broadcast-channel": "^3.7.0"

View File

@@ -2,11 +2,13 @@ import { expect, tap } from '@pushrocks/tapbundle';
import * as deesComms from '../ts/index.js'; import * as deesComms from '../ts/index.js';
let deesCommsTest: deesComms.DeesComms; let deesCommsTest: deesComms.DeesComms;
let deesCommsTest2: deesComms.DeesComms;
tap.test('first test', async (tools) => { tap.test('first test', async (tools) => {
deesCommsTest = new deesComms.DeesComms(); deesCommsTest = new deesComms.DeesComms();
deesCommsTest2 = new deesComms.DeesComms();
let counter = 1; let counter = 1;
deesCommsTest.createTypedHandler<any>('test', async (requestData) => { deesCommsTest2.createTypedHandler<any>('test', async (requestData) => {
console.log(`got the request ${counter++}`); console.log(`got the request ${counter++}`);
return { hitheretoo: `greetings to ${requestData.hithere}` }; return { hitheretoo: `greetings to ${requestData.hithere}` };
}); });
@@ -25,7 +27,12 @@ tap.test('first test', async (tools) => {
hithere: 'hello', hithere: 'hello',
}); });
console.log(JSON.stringify(result2)); */ console.log(JSON.stringify(result2)); */
}); });
tap.test('should end on nodejs', async (toolsArg) => {
if (globalThis.process) {
toolsArg.delayFor(2000).then(() => globalThis.process.exit(0));
}
})
tap.start(); tap.start();

View File

@@ -10,8 +10,9 @@ if (!BroadcastChannel) {
* a comm class for client side communication between workers and tabs. * a comm class for client side communication between workers and tabs.
*/ */
export class DeesComms { export class DeesComms {
private broadcastChannel = new BroadcastChannel('dees-comms');
// sending messages // sending messages
private postChannel = new BroadcastChannel('dees-comms');
public typedrouter = new plugins.typedrequest.TypedRouter(); public typedrouter = new plugins.typedrequest.TypedRouter();
public typedtarget = new plugins.typedrequest.TypedTarget({ public typedtarget = new plugins.typedrequest.TypedTarget({
postMethodWithTypedRouter: async (messageArg) => { postMethodWithTypedRouter: async (messageArg) => {
@@ -21,15 +22,15 @@ export class DeesComms {
}); });
// receiving messages // receiving messages
private subscriptionChannel = new BroadcastChannel('dees-comms');
constructor() { constructor() {
this.subscriptionChannel.onmessage = async (eventArg) => { this.broadcastChannel.onmessage = async (eventArg) => {
const message = (eventArg as any).method ? eventArg : eventArg.data; const message = (eventArg as any).method ? eventArg : eventArg.data;
console.log(JSON.stringify(message)); console.log(JSON.stringify(message));
const response = await this.typedrouter.routeAndAddResponse(message); const response = await this.typedrouter.routeAndAddResponse(message);
if (response) { if (response && !response.error) {
this.postMessage(response); this.postMessage(response);
} else {
// console.log(response);
} }
}; };
} }
@@ -50,7 +51,7 @@ export class DeesComms {
public async postMessage<T = plugins.typedrequestInterfaces.ITypedRequest>( public async postMessage<T = plugins.typedrequestInterfaces.ITypedRequest>(
messageArg: T messageArg: T
): Promise<void> { ): Promise<void> {
this.postChannel.postMessage(messageArg); this.broadcastChannel.postMessage(messageArg);
} }
/** /**