Skip to content

Commit

Permalink
Remove timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
mrruby committed Apr 25, 2024
1 parent 1382475 commit 92b12b8
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 15 deletions.
2 changes: 1 addition & 1 deletion holo-key-manager-js-client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@holo-host/holo-key-manager-js-client",
"version": "0.0.4",
"version": "0.0.5",
"description": "A JavaScript client API for managing Holo keys",
"main": "lib/index.js",
"types": "lib/holo-key-manager-js-client/src/index.d.ts",
Expand Down
15 changes: 1 addition & 14 deletions holo-key-manager-js-client/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import { parseMessageSchema } from '@shared/helpers';
import { createMessageWithId } from '@shared/services';
import { type Message, type MessageWithId, MessageWithIdSchema } from '@shared/types';

let timeoutId: number | null = null;

const isWindowDefined = () => typeof window !== 'undefined';

const isExpectedPayload = <T>(payload: unknown): payload is T => {
Expand Down Expand Up @@ -39,14 +37,8 @@ export const sendMessage = (message: Message): Promise<MessageWithId> =>
return;
}

if (timeoutId) {
clearTimeout(timeoutId);
timeoutId = null;
}

const messageWithId = createMessageWithId(message);

const removeListener = () => window.removeEventListener('message', responseHandler);
const responseHandler = (event: MessageEvent) => {
const parseResult = MessageWithIdSchema.safeParse(event.data);
if (!parseResult.success) {
Expand All @@ -57,16 +49,11 @@ export const sendMessage = (message: Message): Promise<MessageWithId> =>
return;
}
resolve(responseData);
removeListener();
window.removeEventListener('message', responseHandler);
};

window.postMessage(messageWithId, '*');
window.addEventListener('message', responseHandler);

timeoutId = setTimeout(() => {
removeListener();
reject(new Error('Response timeout'));
}, 300000);
});

export const checkContentScriptAndBrowser = () => {
Expand Down

0 comments on commit 92b12b8

Please sign in to comment.