Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| eab145e736 | |||
| 4060d64ed4 |
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "@designestate/dees-comms",
|
"name": "@designestate/dees-comms",
|
||||||
"version": "1.0.19",
|
"version": "1.0.20",
|
||||||
"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.20",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@apiglobal/typedrequest": "^2.0.2",
|
"@apiglobal/typedrequest": "^2.0.2",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@designestate/dees-comms",
|
"name": "@designestate/dees-comms",
|
||||||
"version": "1.0.19",
|
"version": "1.0.20",
|
||||||
"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",
|
||||||
|
|||||||
@@ -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}` };
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -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,10 +22,8 @@ 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);
|
||||||
@@ -50,7 +49,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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user