Skip to content

Commit

Permalink
fix cliend-id error for designer (Avaiga#1919)
Browse files Browse the repository at this point in the history
  • Loading branch information
dinhlongviolin1 authored Oct 4, 2024
1 parent 6fcadd9 commit 8cab9f4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
14 changes: 8 additions & 6 deletions frontend/taipy-gui/base/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { sendWsMessage, TAIPY_CLIENT_ID } from "../../src/context/wsUtils";
import { uploadFile } from "../../src/workers/fileupload";

import { Socket, io } from "socket.io-client";
import { nanoid } from 'nanoid';
import { nanoid } from "nanoid";
import { DataManager, ModuleData, RequestDataOptions } from "./dataManager";
import { initSocket } from "./socket";
import { TaipyWsAdapter, WsAdapter } from "./wsAdapter";
Expand All @@ -26,7 +26,6 @@ export type OnEvent =
type Route = [string, string];
type RequestDataCallback = (taipyApp: TaipyApp, encodedName: string, dataEventKey: string, value: unknown) => void;


export class TaipyApp {
socket: Socket;
_onInit: OnInitHandler | undefined;
Expand All @@ -51,7 +50,7 @@ export class TaipyApp {
onInit: OnInitHandler | undefined = undefined,
onChange: OnChangeHandler | undefined = undefined,
path: string | undefined = undefined,
socket: Socket | undefined = undefined
socket: Socket | undefined = undefined,
) {
socket = socket || io("/", { autoConnect: false, path: `${this.getBaseUrl()}socket.io` });
this.onInit = onInit;
Expand Down Expand Up @@ -168,14 +167,18 @@ export class TaipyApp {
this.routes = undefined;
const id = getLocalStorageValue(TAIPY_CLIENT_ID, "");
this.sendWsMessage("ID", TAIPY_CLIENT_ID, id);
this.sendWsMessage("AID", "connect", "");
this.sendWsMessage("GR", "", "");
if (id !== "") {
this.clientId = id;
this.initApp()
this.updateContext(this.path);
}
}

initApp() {
this.sendWsMessage("AID", "connect", "");
this.sendWsMessage("GR", "", "");
}

sendWsMessage(type: WsMessageType, id: string, payload: unknown, context: string | undefined = undefined) {
if (context === undefined) {
context = this.context;
Expand Down Expand Up @@ -235,7 +238,6 @@ export class TaipyApp {
this.sendWsMessage("U", encodedName, { value: value });
}


// Request Data from taipy backend
// This will trigger the backend to send the data to the frontend
requestData(encodedName: string, cb: RequestDataCallback, options?: RequestDataOptions) {
Expand Down
1 change: 1 addition & 0 deletions frontend/taipy-gui/base/src/packaging/taipy-gui-base.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ export declare class TaipyApp {
set onWsStatusUpdate(handler: OnWsStatusUpdate | undefined);
onWsStatusUpdateEvent(messageQueue: string[]): void;
init(): void;
initApp(): void;
sendWsMessage(type: WsMessageType | string, id: string, payload: unknown, context?: string | undefined): void;
registerWsAdapter(wsAdapter: WsAdapter): void;
getEncodedName(varName: string, module: string): string | undefined;
Expand Down
1 change: 1 addition & 0 deletions frontend/taipy-gui/base/src/wsAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export class TaipyWsAdapter extends WsAdapter {
const { id } = message as unknown as IdMessage;
storeClientId(id);
taipyApp.clientId = id;
taipyApp.initApp();
taipyApp.updateContext(taipyApp.path);
} else if (message.type === "GMC") {
const payload = message.payload as Record<string, unknown>;
Expand Down

0 comments on commit 8cab9f4

Please sign in to comment.