From 4060d64ed47bb1696e9f75a5c5d3c69e6b299254 Mon Sep 17 00:00:00 2001 From: Philipp Kunz Date: Tue, 29 Mar 2022 13:14:10 +0200 Subject: [PATCH] fix(core): update --- test/test.browser.ts | 4 +++- ts/dees-comms.classes.deescomms.ts | 9 ++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/test/test.browser.ts b/test/test.browser.ts index 521cd95..0ce355b 100644 --- a/test/test.browser.ts +++ b/test/test.browser.ts @@ -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('test', async (requestData) => { + deesCommsTest2.createTypedHandler('test', async (requestData) => { console.log(`got the request ${counter++}`); return { hitheretoo: `greetings to ${requestData.hithere}` }; }); diff --git a/ts/dees-comms.classes.deescomms.ts b/ts/dees-comms.classes.deescomms.ts index 4fe585d..420d8f9 100644 --- a/ts/dees-comms.classes.deescomms.ts +++ b/ts/dees-comms.classes.deescomms.ts @@ -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,10 +22,8 @@ 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); @@ -50,7 +49,7 @@ export class DeesComms { public async postMessage( messageArg: T ): Promise { - this.postChannel.postMessage(messageArg); + this.broadcastChannel.postMessage(messageArg); } /**