Skip to content

Commit

Permalink
Add a warning if contentLoaded event isn't received (#85)
Browse files Browse the repository at this point in the history
* Add a warning if contentLoaded event isn't received

So the widget fails less silently if waitForIFrameLoad=false is specified
but the widget doesn't send the contentLoaded event, to help prevent
people like me being daft and wasting ages because they reverted one
bit of code and not the other.

* Revert dev package.json changes
  • Loading branch information
dbkr authored Jul 13, 2023
1 parent 233f7d8 commit 682b001
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/ClientWidgetApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ export class ClientWidgetApi extends EventEmitter {
private allowedEvents: WidgetEventCapability[] = [];
private isStopped = false;
private turnServers: AsyncGenerator<ITurnServer> | null = null;
private contentLoadedWaitTimer?: ReturnType<typeof setTimeout>;

/**
* Creates a new client widget API. This will instantiate the transport
Expand Down Expand Up @@ -238,20 +239,30 @@ export class ClientWidgetApi extends EventEmitter {
} else {
// Reaching this means, that the Iframe got reloaded/loaded and
// the clientApi is awaiting the FIRST ContentLoaded action.
console.log("waitForIframeLoad is false: waiting for widget to send contentLoaded");
this.contentLoadedWaitTimer = setTimeout(() => {
console.error(
"Widget specified waitForIframeLoad=false but timed out waiting for contentLoaded event!",
);
}, 10000);
this.contentLoadedActionSent = false;
}
}

private handleContentLoadedAction(action: IContentLoadedActionRequest) {
if (this.contentLoadedWaitTimer !== undefined) {
clearTimeout(this.contentLoadedWaitTimer);
this.contentLoadedWaitTimer = undefined;
}
if (this.contentLoadedActionSent) {
throw new Error("Improper sequence: ContentLoaded Action can only be send once after the widget loaded "
throw new Error("Improper sequence: ContentLoaded Action can only be sent once after the widget loaded "
+"and should only be used if waitForIframeLoad is false (default=true)");
}
if (this.widget.waitForIframeLoad) {
this.transport.reply(action, <IWidgetApiErrorResponseData>{
error: {
message: "Improper sequence: not expecting ContentLoaded event if "
+"waitForIframLoad is true (default=true)",
+"waitForIframeLoad is true (default=true)",
},
});
} else {
Expand Down

0 comments on commit 682b001

Please sign in to comment.