Detect API version of Riot before rendering widget
This commit is contained in:
parent
11ed6342f6
commit
d29e8531d9
2 changed files with 33 additions and 6 deletions
|
@ -88,6 +88,10 @@ export class ScalarWidgetApi {
|
||||||
ScalarWidgetApi.callAction("get_openid", {});
|
ScalarWidgetApi.callAction("get_openid", {});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static requestSupportedVersions(): void {
|
||||||
|
ScalarWidgetApi.callAction("supported_api_versions", {});
|
||||||
|
}
|
||||||
|
|
||||||
private static callAction(action, payload) {
|
private static callAction(action, payload) {
|
||||||
if (!window.opener) {
|
if (!window.opener) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -14,12 +14,12 @@ import { FE_ScalarOpenIdRequestBody } from "../../shared/models/scalar-server-re
|
||||||
})
|
})
|
||||||
export class ReauthExampleWidgetWrapperComponent extends CapableWidget implements OnInit, OnDestroy {
|
export class ReauthExampleWidgetWrapperComponent extends CapableWidget implements OnInit, OnDestroy {
|
||||||
|
|
||||||
public busy = false;
|
public busy = true; // busy until we load supported versions
|
||||||
public hasOpenId = false;
|
public hasOpenId = false;
|
||||||
public userId: string;
|
public userId: string;
|
||||||
public blocked = false;
|
public blocked = false;
|
||||||
public error = false;
|
public error = false;
|
||||||
public stateMessage = "";
|
public stateMessage = "Checking client version...";
|
||||||
|
|
||||||
private widgetReplySubscription: Subscription;
|
private widgetReplySubscription: Subscription;
|
||||||
private widgetRequestSubscription: Subscription;
|
private widgetRequestSubscription: Subscription;
|
||||||
|
@ -38,14 +38,30 @@ export class ReauthExampleWidgetWrapperComponent extends CapableWidget implement
|
||||||
}
|
}
|
||||||
|
|
||||||
public ngOnInit(): void {
|
public ngOnInit(): void {
|
||||||
// TODO: Check that the client supports this (API version 0.0.2 at least)
|
|
||||||
|
|
||||||
super.ngOnInit();
|
super.ngOnInit();
|
||||||
this.widgetReplySubscription = ScalarWidgetApi.replyReceived.subscribe(async response => {
|
this.widgetReplySubscription = ScalarWidgetApi.replyReceived.subscribe(async response => {
|
||||||
if (response.action !== "get_openid") return;
|
|
||||||
|
|
||||||
const data = response.response;
|
const data = response.response;
|
||||||
|
|
||||||
|
if (response.action === "supported_api_versions") {
|
||||||
|
if (!data || !data.supported_versions) {
|
||||||
|
this.stateMessage = "Invalid API version response";
|
||||||
|
this.changeDetector.detectChanges();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.supported_versions.indexOf("0.0.2") === -1) {
|
||||||
|
this.stateMessage = "Your client is not supported by this widget.";
|
||||||
|
this.changeDetector.detectChanges();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.busy = false;
|
||||||
|
this.changeDetector.detectChanges();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (response.action !== "get_openid") return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (data.state === "request") {
|
if (data.state === "request") {
|
||||||
this.stateMessage = "Waiting for you to accept the prompt...";
|
this.stateMessage = "Waiting for you to accept the prompt...";
|
||||||
|
@ -96,6 +112,13 @@ export class ReauthExampleWidgetWrapperComponent extends CapableWidget implement
|
||||||
if (this.widgetRequestSubscription) this.widgetRequestSubscription.unsubscribe();
|
if (this.widgetRequestSubscription) this.widgetRequestSubscription.unsubscribe();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected onCapabilitiesSent(): void {
|
||||||
|
super.onCapabilitiesSent();
|
||||||
|
|
||||||
|
// Start a request for supported API versions
|
||||||
|
ScalarWidgetApi.requestSupportedVersions();
|
||||||
|
}
|
||||||
|
|
||||||
public onReauthStart(): void {
|
public onReauthStart(): void {
|
||||||
this.busy = true;
|
this.busy = true;
|
||||||
this.error = false;
|
this.error = false;
|
||||||
|
|
Loading…
Reference in a new issue