Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9d895913eb | |||
| b5cc8e7952 | |||
| 1a36912461 | |||
| 1dcbdcc06d | |||
| c7d0c8723f | |||
| ae377b185e | |||
| eab145e736 | |||
| 4060d64ed4 | |||
| b7dfd8b1d5 | |||
| 82f2675910 |
8785
package-lock.json
generated
8785
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
12
package.json
12
package.json
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@designestate/dees-comms",
|
||||
"version": "1.0.18",
|
||||
"version": "1.0.23",
|
||||
"private": false,
|
||||
"description": "a comms module for communicating within the DOM",
|
||||
"main": "dist_ts/index.js",
|
||||
@@ -13,14 +13,14 @@
|
||||
"build": "(tsbuild --web --allowimplicitany && tsbundle npm)"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@gitzone/tsbuild": "^2.1.61",
|
||||
"@gitzone/tsbundle": "^1.0.102",
|
||||
"@gitzone/tstest": "^1.0.70",
|
||||
"@gitzone/tsbuild": "^2.1.63",
|
||||
"@gitzone/tsbundle": "^2.0.4",
|
||||
"@gitzone/tstest": "^1.0.71",
|
||||
"@pushrocks/tapbundle": "^5.0.3",
|
||||
"@types/node": "^17.0.23"
|
||||
"@types/node": "^17.0.35"
|
||||
},
|
||||
"dependencies": {
|
||||
"@apiglobal/typedrequest": "^2.0.1",
|
||||
"@apiglobal/typedrequest": "^2.0.3",
|
||||
"@apiglobal/typedrequest-interfaces": "^1.0.15",
|
||||
"@pushrocks/smartdelay": "^2.0.13",
|
||||
"broadcast-channel": "^3.7.0"
|
||||
|
||||
@@ -2,11 +2,13 @@ import { expect, tap } from '@pushrocks/tapbundle';
|
||||
import * as deesComms from '../ts/index.js';
|
||||
|
||||
let deesCommsTest: deesComms.DeesComms;
|
||||
let deesCommsTest2: deesComms.DeesComms;
|
||||
|
||||
tap.test('first test', async (tools) => {
|
||||
deesCommsTest = new deesComms.DeesComms();
|
||||
deesCommsTest2 = new deesComms.DeesComms();
|
||||
let counter = 1;
|
||||
deesCommsTest.createTypedHandler<any>('test', async (requestData) => {
|
||||
deesCommsTest2.createTypedHandler<any>('test', async (requestData) => {
|
||||
console.log(`got the request ${counter++}`);
|
||||
return { hitheretoo: `greetings to ${requestData.hithere}` };
|
||||
});
|
||||
@@ -25,7 +27,12 @@ tap.test('first test', async (tools) => {
|
||||
hithere: 'hello',
|
||||
});
|
||||
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();
|
||||
8
ts/00_commitinfo_data.ts
Normal file
8
ts/00_commitinfo_data.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* autocreated commitinfo by @pushrocks/commitinfo
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@designestate/dees-comms',
|
||||
version: '1.0.23',
|
||||
description: 'a comms module for communicating within the DOM'
|
||||
}
|
||||
@@ -10,8 +10,9 @@ if (!BroadcastChannel) {
|
||||
* a comm class for client side communication between workers and tabs.
|
||||
*/
|
||||
export class DeesComms {
|
||||
private broadcastChannel = new BroadcastChannel('dees-comms');
|
||||
|
||||
// sending messages
|
||||
private postChannel = new BroadcastChannel('dees-comms');
|
||||
public typedrouter = new plugins.typedrequest.TypedRouter();
|
||||
public typedtarget = new plugins.typedrequest.TypedTarget({
|
||||
postMethodWithTypedRouter: async (messageArg) => {
|
||||
@@ -21,15 +22,15 @@ export class DeesComms {
|
||||
});
|
||||
|
||||
// receiving messages
|
||||
private subscriptionChannel = new BroadcastChannel('dees-comms');
|
||||
|
||||
constructor() {
|
||||
this.subscriptionChannel.onmessage = async (eventArg) => {
|
||||
this.broadcastChannel.onmessage = async (eventArg) => {
|
||||
const message = (eventArg as any).method ? eventArg : eventArg.data;
|
||||
console.log(JSON.stringify(message));
|
||||
const response = await this.typedrouter.routeAndAddResponse(message);
|
||||
if (response) {
|
||||
if (response && !response.error) {
|
||||
this.postMessage(response);
|
||||
} else {
|
||||
// console.log(response);
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -50,7 +51,7 @@ export class DeesComms {
|
||||
public async postMessage<T = plugins.typedrequestInterfaces.ITypedRequest>(
|
||||
messageArg: T
|
||||
): Promise<void> {
|
||||
this.postChannel.postMessage(messageArg);
|
||||
this.broadcastChannel.postMessage(messageArg);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user