NAM Performance profiling (sync)
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
<meta charset="UTF-8">
|
||||
<title>T3K Response</title>
|
||||
<script>
|
||||
debugger;
|
||||
window.opener.postMessage(
|
||||
{
|
||||
type: "t3k_response",
|
||||
|
||||
@@ -7,6 +7,6 @@
|
||||
"ui_plugins": [],
|
||||
"enable_auto_update": true,
|
||||
"has_wifi_device": false,
|
||||
"tone3000_A2_models": true,
|
||||
"tone3000_A2_models": false,
|
||||
"end": true
|
||||
}
|
||||
@@ -587,6 +587,7 @@ export
|
||||
}
|
||||
|
||||
private beforeUnloadListener(e: Event) {
|
||||
alert("BeforeUnload");
|
||||
this.model_.close();
|
||||
return undefined;
|
||||
}
|
||||
@@ -601,7 +602,6 @@ export
|
||||
|
||||
super.componentDidMount();
|
||||
window.addEventListener("beforeunload", this.beforeUnloadListener);
|
||||
window.addEventListener("unload", this.unloadListener);
|
||||
|
||||
this.model_.errorMessage.addOnChangedHandler(this.errorChangeHandler_);
|
||||
this.model_.state.addOnChangedHandler(this.stateChangeHandler_);
|
||||
|
||||
@@ -46,13 +46,21 @@ export default class JackStatusView extends React.Component<JackStatusViewProps,
|
||||
this.tick = this.tick.bind(this);
|
||||
}
|
||||
|
||||
private waitingForTick: boolean = false;
|
||||
tick() {
|
||||
if (this.model.state.get() === State.Ready) {
|
||||
if (this.waitingForTick) return;
|
||||
this.waitingForTick = true;
|
||||
this.model.getJackStatus()
|
||||
.then(jackStatus => {
|
||||
this.waitingForTick = false;
|
||||
this.setState({jackStatus: jackStatus});
|
||||
})
|
||||
.catch(error => { /* ignore*/ });
|
||||
.catch(error => {
|
||||
this.waitingForTick = false;
|
||||
});
|
||||
} else {
|
||||
this.waitingForTick = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -707,6 +707,25 @@ export class PiPedalModel //implements PiPedalModel
|
||||
|
||||
}
|
||||
|
||||
async makeTone3000Pkce(redirectUrl: string) : Promise<Tone3000PkceParams>
|
||||
{
|
||||
if (this.webSocket === undefined)
|
||||
{
|
||||
throw new Error("Server disconnected.");
|
||||
}
|
||||
return await this.webSocket.request<Tone3000PkceParams>(
|
||||
"makeTone3000Pkce", redirectUrl);
|
||||
}
|
||||
|
||||
async sha256Base64url(intput: string) : Promise<string> {
|
||||
if (this.webSocket === undefined)
|
||||
{
|
||||
throw new Error("Server disconnected.");
|
||||
}
|
||||
return this.webSocket.request<string>(
|
||||
"sha256Base64url", intput);
|
||||
|
||||
}
|
||||
async pingTone3000Server(): Promise<boolean> {
|
||||
if (this.webSocket === undefined) {
|
||||
return false;
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { PiPedalModel, getErrorMessage, Tone3000PkceParams } from "./PiPedalModel";
|
||||
import Tone3000DownloadType from "./Tone3000DownloadType";
|
||||
import { PkceParams, buildPkceParams, handleOAuthCallback } from "./t3k/tone3000-client.ts";
|
||||
import { T3K_DEBUG, PkceParams, setServerPkceParams, handleOAuthCallback } from "./t3k/tone3000-client.ts";
|
||||
|
||||
import { Model, PaginatedResponse, Platform, Tone } from "./t3k/types.ts";
|
||||
import { PUBLISHABLE_KEY } from './t3k/config.ts';
|
||||
|
||||
|
||||
import { startSelectFlowPopup, T3KClient } from "./t3k/tone3000-client.ts";
|
||||
import { startSelectFlowPopup, buildPkceParams,T3KClient } from "./t3k/tone3000-client.ts";
|
||||
import Tone3000DownloadProgress from './Tone3000DownloadProgress';
|
||||
import { safeFilenameEncode } from "./SafeFilename";
|
||||
|
||||
@@ -20,6 +20,8 @@ async function asyncSleep(ms: number): Promise<void> {
|
||||
return new Promise(resolve => setTimeout(resolve, ms));
|
||||
}
|
||||
|
||||
const USE_SERVER_PCKE=true;
|
||||
|
||||
|
||||
const RUN_THROTTLER_TEST = true;
|
||||
const ALLOWED_DOWNLOADS_PER_MINUTE = 25;
|
||||
@@ -119,6 +121,7 @@ export class Tone3000DownloadHandler {
|
||||
let uri = event.data.uri;
|
||||
this.handleTone3000DownloadComplete();
|
||||
if (uri) {
|
||||
|
||||
this_.handleT3kSelectResponse(uri, event.data.storedState, event.data.codeVerifier)
|
||||
.then(() => { })
|
||||
.catch((error) => {
|
||||
@@ -171,17 +174,18 @@ export class Tone3000DownloadHandler {
|
||||
|
||||
private progress: Tone3000DownloadProgress = new Tone3000DownloadProgress();
|
||||
|
||||
private async throttleRequests(): Promise<void> {
|
||||
private async throttleRequests(): Promise<boolean> {
|
||||
let now = Date.now();
|
||||
let delay = this.throttler.getThrottleDelay(now);
|
||||
while (delay > 0) {
|
||||
await asyncSleep(250);
|
||||
if (this.checkForCancel())
|
||||
{
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
delay -= 250;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private onTone3000DownloadStarted() {
|
||||
@@ -214,6 +218,10 @@ export class Tone3000DownloadHandler {
|
||||
downloadType: Tone3000DownloadType
|
||||
): Promise<void> {
|
||||
try {
|
||||
|
||||
if (T3K_DEBUG) {
|
||||
console.debug("PiPedal responseUri: " + responseUri);
|
||||
}
|
||||
this.onTone3000DownloadStarted();
|
||||
this.progress.title = "Authenticating..."
|
||||
this.onTone3000DownloadProgress(this.progress);
|
||||
@@ -221,13 +229,13 @@ export class Tone3000DownloadHandler {
|
||||
return;
|
||||
}
|
||||
|
||||
await this.throttleRequests();
|
||||
if (!await this.throttleRequests()) return;
|
||||
let tokenResponse = await handleOAuthCallback(
|
||||
PUBLISHABLE_KEY,
|
||||
this.redirectUrl(),
|
||||
responseUri);
|
||||
|
||||
if (!tokenResponse.ok) {
|
||||
;
|
||||
throw new Error(tokenResponse.error);
|
||||
}
|
||||
if (this.checkForCancel()) {
|
||||
@@ -245,7 +253,7 @@ export class Tone3000DownloadHandler {
|
||||
this.onTone3000DownloadProgress(this.progress);
|
||||
|
||||
|
||||
await this.throttleRequests();
|
||||
if (!await this.throttleRequests()) return;
|
||||
let tone: Tone = await this.t3kClient.getTone(tokenResponse.toneId);
|
||||
|
||||
if (this.checkForCancel()) {
|
||||
@@ -264,7 +272,7 @@ export class Tone3000DownloadHandler {
|
||||
}
|
||||
|
||||
while (true) {
|
||||
await this.throttleRequests();
|
||||
if (!await this.throttleRequests()) return;
|
||||
if (this.checkForCancel()) {
|
||||
return;
|
||||
}
|
||||
@@ -308,7 +316,7 @@ export class Tone3000DownloadHandler {
|
||||
lastUpdateTime = Date.now();
|
||||
}
|
||||
|
||||
await this.throttleRequests();
|
||||
if (!await this.throttleRequests()) return;
|
||||
|
||||
if (!model.model_url) {
|
||||
throw new Error("Model " + model.name + " does not have a model URL.");
|
||||
@@ -463,18 +471,45 @@ export class Tone3000DownloadHandler {
|
||||
|
||||
try {
|
||||
|
||||
let pkceParams = await buildPkceParams();
|
||||
let t3kPceParams: Tone3000PkceParams;
|
||||
let pkceParams: PkceParams;
|
||||
if (USE_SERVER_PCKE) {
|
||||
t3kPceParams = await this.model.makeTone3000Pkce(this.redirectUrl());
|
||||
pkceParams = {
|
||||
codeChallenge: t3kPceParams.codeChallenge,
|
||||
codeVerifier: t3kPceParams.codeVerifier,
|
||||
state: t3kPceParams.state
|
||||
}
|
||||
setServerPkceParams(pkceParams)
|
||||
|
||||
} else {
|
||||
pkceParams = await buildPkceParams();
|
||||
t3kPceParams = {
|
||||
codeChallenge: pkceParams.codeChallenge,
|
||||
codeVerifier: pkceParams.codeVerifier,
|
||||
state: pkceParams.state,
|
||||
publishableKey: PUBLISHABLE_KEY,
|
||||
redirectUrl: this.redirectUrl()
|
||||
};
|
||||
// verify that the server matches.
|
||||
let testcodeChallenge = await this.model.sha256Base64url(pkceParams.codeVerifier);
|
||||
if (testcodeChallenge !== pkceParams.codeChallenge) {
|
||||
throw new Error("model.sha256Base64url produces incorrect results. ");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
this.pkceParams = pkceParams;
|
||||
this.popupWindow = await startSelectFlowPopup(
|
||||
pkceParams,
|
||||
PUBLISHABLE_KEY,
|
||||
this.redirectUrl(),
|
||||
{
|
||||
architecture: downloadType === Tone3000DownloadType.CabIr ? undefined : 2,
|
||||
architecture: (downloadType === Tone3000DownloadType.Nam && this.model.tone3000_A2_models) ? 2: undefined,
|
||||
platform: downloadType === Tone3000DownloadType.CabIr ? Platform.Ir : Platform.Nam,
|
||||
menubar: true,
|
||||
width: popupWidth,
|
||||
height: popupHeight
|
||||
height: popupHeight,
|
||||
},
|
||||
|
||||
);
|
||||
|
||||
@@ -3,18 +3,13 @@
|
||||
// Trailing slashes are stripped so `${T3K_API}/api/...` never produces a double slash —
|
||||
// Vercel 308-redirects double-slash paths, and redirects drop CORS headers.
|
||||
export const T3K_API = (
|
||||
(import.meta.env.VITE_T3K_API_DOMAIN as string | undefined) ?? 'https://www.tone3000.com'
|
||||
'https://www.tone3000.com'
|
||||
).replace(/\/+$/, '');
|
||||
|
||||
export const PUBLISHABLE_KEY = import.meta.env.VITE_PUBLISHABLE_KEY as string;
|
||||
export const PUBLISHABLE_KEY = "t3k_pub_bHrH8btdwXXTtxz5ryEU8sNLF-2TGRT9";
|
||||
|
||||
// Per-demo keys — fall back to the shared PUBLISHABLE_KEY for local dev
|
||||
export const PUBLISHABLE_KEY_SELECT =
|
||||
(import.meta.env.VITE_PUBLISHABLE_KEY_SELECT as string | undefined) ?? PUBLISHABLE_KEY;
|
||||
export const PUBLISHABLE_KEY_LOAD =
|
||||
(import.meta.env.VITE_PUBLISHABLE_KEY_LOAD as string | undefined) ?? PUBLISHABLE_KEY;
|
||||
export const PUBLISHABLE_KEY_FULL =
|
||||
(import.meta.env.VITE_PUBLISHABLE_KEY_FULL as string | undefined) ?? PUBLISHABLE_KEY;
|
||||
export const PUBLISHABLE_KEY_SELECT = PUBLISHABLE_KEY;
|
||||
export const PUBLISHABLE_KEY_LOAD = PUBLISHABLE_KEY;
|
||||
export const PUBLISHABLE_KEY_FULL = PUBLISHABLE_KEY;
|
||||
|
||||
export const REDIRECT_URI =
|
||||
(import.meta.env.VITE_REDIRECT_URI as string | undefined) ?? 'http://localhost:3001';
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user