|
@@ -9,6 +9,7 @@ import { initSocket } from "./socket";
|
|
import { TaipyWsAdapter, WsAdapter } from "./wsAdapter";
|
|
import { TaipyWsAdapter, WsAdapter } from "./wsAdapter";
|
|
import { WsMessageType } from "../../src/context/wsUtils";
|
|
import { WsMessageType } from "../../src/context/wsUtils";
|
|
import { getBase } from "./utils";
|
|
import { getBase } from "./utils";
|
|
|
|
+import { CookieHandler } from "./cookieHandler";
|
|
|
|
|
|
export type OnInitHandler = (taipyApp: TaipyApp) => void;
|
|
export type OnInitHandler = (taipyApp: TaipyApp) => void;
|
|
export type OnChangeHandler = (taipyApp: TaipyApp, encodedName: string, value: unknown, dataEventKey?: string) => void;
|
|
export type OnChangeHandler = (taipyApp: TaipyApp, encodedName: string, value: unknown, dataEventKey?: string) => void;
|
|
@@ -36,6 +37,7 @@ export class TaipyApp {
|
|
_onWsStatusUpdate: OnWsStatusUpdate | undefined;
|
|
_onWsStatusUpdate: OnWsStatusUpdate | undefined;
|
|
_ackList: string[];
|
|
_ackList: string[];
|
|
_rdc: Record<string, Record<string, RequestDataCallback>>;
|
|
_rdc: Record<string, Record<string, RequestDataCallback>>;
|
|
|
|
+ _cookieHandler: CookieHandler | undefined;
|
|
variableData: DataManager | undefined;
|
|
variableData: DataManager | undefined;
|
|
functionData: DataManager | undefined;
|
|
functionData: DataManager | undefined;
|
|
appId: string;
|
|
appId: string;
|
|
@@ -51,6 +53,7 @@ export class TaipyApp {
|
|
onChange: OnChangeHandler | undefined = undefined,
|
|
onChange: OnChangeHandler | undefined = undefined,
|
|
path: string | undefined = undefined,
|
|
path: string | undefined = undefined,
|
|
socket: Socket | undefined = undefined,
|
|
socket: Socket | undefined = undefined,
|
|
|
|
+ handleCookie: boolean = true,
|
|
) {
|
|
) {
|
|
socket = socket || io("/", { autoConnect: false, path: `${this.getBaseUrl()}socket.io` });
|
|
socket = socket || io("/", { autoConnect: false, path: `${this.getBaseUrl()}socket.io` });
|
|
this.onInit = onInit;
|
|
this.onInit = onInit;
|
|
@@ -67,8 +70,10 @@ export class TaipyApp {
|
|
this.wsAdapters = [new TaipyWsAdapter()];
|
|
this.wsAdapters = [new TaipyWsAdapter()];
|
|
this._ackList = [];
|
|
this._ackList = [];
|
|
this._rdc = {};
|
|
this._rdc = {};
|
|
- // Init socket io connection
|
|
|
|
- initSocket(socket, this);
|
|
|
|
|
|
+ this._cookieHandler = handleCookie ? new CookieHandler() : undefined;
|
|
|
|
+ // Init socket io connection only when cookie is not handled
|
|
|
|
+ // Socket will be initialized by cookie handler when it is used
|
|
|
|
+ this._cookieHandler ? this._cookieHandler?.init(socket, this) : initSocket(socket, this);
|
|
}
|
|
}
|
|
|
|
|
|
// Getter and setter
|
|
// Getter and setter
|
|
@@ -169,7 +174,7 @@ export class TaipyApp {
|
|
this.sendWsMessage("ID", TAIPY_CLIENT_ID, id);
|
|
this.sendWsMessage("ID", TAIPY_CLIENT_ID, id);
|
|
if (id !== "") {
|
|
if (id !== "") {
|
|
this.clientId = id;
|
|
this.clientId = id;
|
|
- this.initApp()
|
|
|
|
|
|
+ this.initApp();
|
|
this.updateContext(this.path);
|
|
this.updateContext(this.path);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -292,6 +297,12 @@ export class TaipyApp {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-export const createApp = (onInit?: OnInitHandler, onChange?: OnChangeHandler, path?: string, socket?: Socket) => {
|
|
|
|
- return new TaipyApp(onInit, onChange, path, socket);
|
|
|
|
|
|
+export const createApp = (
|
|
|
|
+ onInit?: OnInitHandler,
|
|
|
|
+ onChange?: OnChangeHandler,
|
|
|
|
+ path?: string,
|
|
|
|
+ socket?: Socket,
|
|
|
|
+ handleCookie?: boolean,
|
|
|
|
+) => {
|
|
|
|
+ return new TaipyApp(onInit, onChange, path, socket, handleCookie);
|
|
};
|
|
};
|