Add entryPointBaseUrl support for web workers
Introduces the entryPointBaseUrl property to configuration in index.html and flutter_bootstrap.js, and updates python.js to use this base URL when creating Python web workers. This change allows for more flexible deployment scenarios where the entry point base URL may differ.
This commit is contained in:
parent
b89da8ac93
commit
4d71b7501d
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
var flutterConfig = {
|
var flutterConfig = {
|
||||||
multiViewEnabled: flet.multiView,
|
multiViewEnabled: flet.multiView,
|
||||||
|
entryPointBaseUrl: flet.entryPointBaseUrl,
|
||||||
assetBase: flet.assetBase
|
assetBase: flet.assetBase
|
||||||
};
|
};
|
||||||
if (flet.webRenderer != "auto") {
|
if (flet.webRenderer != "auto") {
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@
|
||||||
multiView: false,
|
multiView: false,
|
||||||
noCdn: "{{ cookiecutter.no_cdn }}".toLowerCase() == "true",
|
noCdn: "{{ cookiecutter.no_cdn }}".toLowerCase() == "true",
|
||||||
webSocketEndpoint: "/ws",
|
webSocketEndpoint: "/ws",
|
||||||
|
entryPointBaseUrl: "/",
|
||||||
assetBase: "/",
|
assetBase: "/",
|
||||||
routeUrlStrategy: "{{ cookiecutter.route_url_strategy }}",
|
routeUrlStrategy: "{{ cookiecutter.route_url_strategy }}",
|
||||||
canvasKitBaseUrl: "/canvaskit/",
|
canvasKitBaseUrl: "/canvaskit/",
|
||||||
|
|
|
||||||
|
|
@ -6,13 +6,14 @@ let _documentUrl = document.URL;
|
||||||
// This method is called from Dart on backend.connect()
|
// This method is called from Dart on backend.connect()
|
||||||
// dartOnMessage is called on backend.onMessage
|
// dartOnMessage is called on backend.onMessage
|
||||||
// it accepts "data" of type JSUint8Array
|
// it accepts "data" of type JSUint8Array
|
||||||
globalThis.jsConnect = async function(appId, args, dartOnMessage) {
|
globalThis.jsConnect = async function (appId, args, dartOnMessage) {
|
||||||
let app = {
|
let app = {
|
||||||
"dartOnMessage": dartOnMessage
|
"dartOnMessage": dartOnMessage
|
||||||
};
|
};
|
||||||
console.log(`Starting up Python worker: ${appId}, args: ${args}`);
|
console.log(`Starting up Python worker: ${appId}, args: ${args}`);
|
||||||
_apps[appId] = app;
|
_apps[appId] = app;
|
||||||
app.worker = new Worker("python-worker.js");
|
app.worker = new Worker((flet.entryPointBaseUrl.endsWith("/") ?
|
||||||
|
flet.entryPointBaseUrl.slice(0, -1) : flet.entryPointBaseUrl) + "python-worker.js");
|
||||||
|
|
||||||
var error;
|
var error;
|
||||||
app.worker.onmessage = (event) => {
|
app.worker.onmessage = (event) => {
|
||||||
|
|
@ -50,7 +51,7 @@ globalThis.jsConnect = async function(appId, args, dartOnMessage) {
|
||||||
|
|
||||||
// Called from Dart on backend.send
|
// Called from Dart on backend.send
|
||||||
// data is a message serialized to JSUint8Array
|
// data is a message serialized to JSUint8Array
|
||||||
globalThis.jsSend = async function(appId, data) {
|
globalThis.jsSend = async function (appId, data) {
|
||||||
if (appId in _apps) {
|
if (appId in _apps) {
|
||||||
const app = _apps[appId];
|
const app = _apps[appId];
|
||||||
app.worker.postMessage(data);
|
app.worker.postMessage(data);
|
||||||
|
|
@ -58,7 +59,7 @@ globalThis.jsSend = async function(appId, data) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Called from Dart on channel.disconnect
|
// Called from Dart on channel.disconnect
|
||||||
globalThis.jsDisconnect = async function(appId) {
|
globalThis.jsDisconnect = async function (appId) {
|
||||||
if (appId in _apps) {
|
if (appId in _apps) {
|
||||||
console.log(`Terminating Python worker: ${appId}`);
|
console.log(`Terminating Python worker: ${appId}`);
|
||||||
const app = _apps[appId];
|
const app = _apps[appId];
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue