Compare commits
24 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 97eba85337 | |||
| 61936bbdd1 | |||
| 4ab1b917a9 | |||
| f299cff4c9 | |||
| a6e262bbae | |||
| 8a8200ca8a | |||
| e7785cc31b | |||
| 63610b66bc | |||
| d8d382b2fb | |||
| 7c8a2eeaeb | |||
| a34e8f571d | |||
| 2bf398cf97 | |||
| 315bbffac2 | |||
| 52e77d1c3e | |||
| 9ac1fdbb63 | |||
| ac43f63daf | |||
| c8ce7942d5 | |||
| 336351b98a | |||
| 20dcc9dc00 | |||
| f273094369 | |||
| 7fb3688cb9 | |||
| ddf28a8d0e | |||
| b26aa04388 | |||
| 3726e29768 |
@@ -36,6 +36,7 @@ auditProductionDependencies:
|
||||
- npmci command npm audit --audit-level=high --only=prod --production
|
||||
tags:
|
||||
- docker
|
||||
allow_failure: true
|
||||
|
||||
auditDevDependencies:
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
|
||||
23582
package-lock.json
generated
23582
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
19
package.json
19
package.json
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@designestate/dees-comms",
|
||||
"version": "1.0.4",
|
||||
"version": "1.0.16",
|
||||
"private": false,
|
||||
"description": "a comms module for communicating within the DOM",
|
||||
"main": "dist_ts/index.js",
|
||||
@@ -9,20 +9,21 @@
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"test": "(tstest test/ --web)",
|
||||
"build": "(tsbuild --web)"
|
||||
"build": "(tsbuild --web && tsbundle npm)"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@gitzone/tsbuild": "^2.1.25",
|
||||
"@gitzone/tsbundle": "^1.0.78",
|
||||
"@gitzone/tstest": "^1.0.52",
|
||||
"@pushrocks/tapbundle": "^3.2.9",
|
||||
"@types/node": "^14.11.5",
|
||||
"@gitzone/tsbuild": "^2.1.29",
|
||||
"@gitzone/tsbundle": "^1.0.89",
|
||||
"@gitzone/tstest": "^1.0.60",
|
||||
"@pushrocks/tapbundle": "^4.0.0",
|
||||
"@types/node": "^17.0.10",
|
||||
"tslint": "^6.1.3",
|
||||
"tslint-config-prettier": "^1.15.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@apiglobal/typedrequest": "^1.0.49",
|
||||
"@apiglobal/typedrequest-interfaces": "^1.0.15"
|
||||
"@apiglobal/typedrequest": "^1.0.65",
|
||||
"@apiglobal/typedrequest-interfaces": "^1.0.15",
|
||||
"broadcast-channel": "^3.7.0"
|
||||
},
|
||||
"files": [
|
||||
"ts/**/*",
|
||||
|
||||
@@ -3,9 +3,18 @@ import * as deesComms from '../ts/index';
|
||||
|
||||
let deesCommsTest: deesComms.DeesComms;
|
||||
|
||||
tap.test('first test', async () => {
|
||||
tap.test('first test', async (tools) => {
|
||||
deesCommsTest = new deesComms.DeesComms();
|
||||
deesCommsTest;
|
||||
deesCommsTest.createTypedHandler<any>('test', async (requestData) => {
|
||||
return { hitheretoo: `greetings to ${requestData.hithere}` };
|
||||
});
|
||||
|
||||
// lets fire a request
|
||||
const typedrequest = deesCommsTest.createTypedRequest<any>('test');
|
||||
const result = await typedrequest.fire({
|
||||
hithere: 'hello',
|
||||
});
|
||||
console.log(JSON.stringify(result));
|
||||
});
|
||||
|
||||
tap.start();
|
||||
|
||||
@@ -1,21 +1,35 @@
|
||||
import { TypedRequest } from '@apiglobal/typedrequest';
|
||||
import * as plugins from './dees-comms.plugins';
|
||||
|
||||
let BroadcastChannel = globalThis.BroadcastChannel;
|
||||
if (!BroadcastChannel) {
|
||||
BroadcastChannel = plugins.BroadCastChannelPolyfill as any;
|
||||
}
|
||||
|
||||
/**
|
||||
* a comm class for client side communication between workers and tabs.
|
||||
*/
|
||||
export class DeesComms {
|
||||
// sending messages
|
||||
private postChannel = new BroadcastChannel('dees-comms');
|
||||
private typedrouter = new plugins.typedrequest.TypedRouter();
|
||||
public typedrouter = new plugins.typedrequest.TypedRouter();
|
||||
public typedtarget = new plugins.typedrequest.TypedTarget({
|
||||
postMethodWithTypedRouter: async (messageArg) => {
|
||||
this.postMessage(messageArg);
|
||||
},
|
||||
typedRouterRef: this.typedrouter,
|
||||
});
|
||||
|
||||
private subscriptionChannel = new BroadcastChannel('dees-comms');
|
||||
|
||||
|
||||
constructor() {
|
||||
this.subscriptionChannel.onmessage = (eventArg) => {
|
||||
this.subscriptionChannel.onmessage = async (eventArg) => {
|
||||
const message = eventArg.data;
|
||||
this.typedrouter.routeAndAddResponse(message);
|
||||
console.log(JSON.stringify(message));
|
||||
const response = await this.typedrouter.routeAndAddResponse(message);
|
||||
if (response) {
|
||||
this.postMessage(response);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -25,7 +39,7 @@ export class DeesComms {
|
||||
public createTypedRequest<T extends plugins.typedrequestInterfaces.ITypedRequest>(
|
||||
methodName: T['method']
|
||||
): TypedRequest<T> {
|
||||
const typedrequest = new plugins.typedrequest.TypedRequest(this.postMessage, methodName, this.typedrouter);
|
||||
const typedrequest = new plugins.typedrequest.TypedRequest(this.typedtarget, methodName);
|
||||
return typedrequest;
|
||||
}
|
||||
|
||||
@@ -41,5 +55,12 @@ export class DeesComms {
|
||||
/**
|
||||
* subscribe to messages
|
||||
*/
|
||||
public async subscribe() {}
|
||||
public async createTypedHandler<T extends plugins.typedrequestInterfaces.ITypedRequest>(
|
||||
methodArg: T['method'],
|
||||
handlerFunction: plugins.typedrequest.THandlerFunction<T>
|
||||
) {
|
||||
this.typedrouter.addTypedHandler(
|
||||
new plugins.typedrequest.TypedHandler<T>(methodArg, handlerFunction)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,3 +3,10 @@ import * as typedrequestInterfaces from '@apiglobal/typedrequest-interfaces';
|
||||
import * as typedrequest from '@apiglobal/typedrequest';
|
||||
|
||||
export { typedrequestInterfaces, typedrequest };
|
||||
|
||||
// third party scope
|
||||
import { BroadcastChannel as BroadCastChannelPolyfill } from 'broadcast-channel';
|
||||
|
||||
export {
|
||||
BroadCastChannelPolyfill
|
||||
}
|
||||
Reference in New Issue
Block a user