Skip to content

Commit

Permalink
fix(iframe): fix iframe transport
Browse files Browse the repository at this point in the history
  • Loading branch information
unadlib committed Nov 9, 2023
1 parent daa0d2c commit d487ec2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "data-transport",
"version": "4.3.2",
"version": "4.3.3",
"description": "A simple and responsible transport",
"main": "lib/index.js",
"unpkg": "dist/index.umd.js",
Expand Down
24 changes: 15 additions & 9 deletions src/transports/iframeTransport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,19 @@ export abstract class IFrameMainTransport<
sender,
});
if (!skipConnectionCheck) {
this.emit({
// @ts-ignore
name: connectEventName,
silent: true,
}).then((connected) => {
if (connected) {
this[beforeEmitResolveKey]!();
}
});
const connect = () => {
this.emit({
// @ts-ignore
name: connectEventName,
silent: true,
skipBeforeEmit: true,
}).then((connected) => {
if (connected) {
this[beforeEmitResolveKey]!();
}
});
};
connect();
this[beforeEmitKey] = new Promise((resolve) => {
this[beforeEmitResolveKey] = resolve;
});
Expand All @@ -91,10 +95,12 @@ export abstract class IFrameMainTransport<
this[beforeEmitResolveKey]!();
return true;
});
// for iframe reload
iframe?.addEventListener('load', () => {
this[beforeEmitKey] = new Promise((resolve) => {
this[beforeEmitResolveKey] = resolve;
});
connect();
});
}
}
Expand Down

0 comments on commit d487ec2

Please sign in to comment.