@webqit/webflo 1.0.17 → 1.0.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -100,6 +100,50 @@ export class HttpEvent {
|
|
|
100
100
|
return [301, 302, 303, 307, 308].includes(this.#response?.status);
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
+
async stream(callback, { interval = 3000, maxClock = 30, crossNavigation = false } = {}) {
|
|
104
|
+
return new Promise((res) => {
|
|
105
|
+
const state = { connected: false, navigatedAway: false };
|
|
106
|
+
const start = () => {
|
|
107
|
+
const poll = async (maxClock) => {
|
|
108
|
+
await new Promise(($res) => setTimeout($res, interval));
|
|
109
|
+
if (maxClock === 0 || !state.connected || state.navigatedAway) {
|
|
110
|
+
res(callback());
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
await callback(async (response, endOfStream = false) => {
|
|
114
|
+
if (endOfStream) {
|
|
115
|
+
res(response);
|
|
116
|
+
} else {
|
|
117
|
+
await this.client.postMessage(response, { messageType: 'response' });
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
poll(typeof maxClock === 'number' && maxClock > 0 ? --maxClock : maxClock);
|
|
121
|
+
};
|
|
122
|
+
poll(maxClock);
|
|
123
|
+
};
|
|
124
|
+
// Life cycle management
|
|
125
|
+
this.client.on('connected', () => {
|
|
126
|
+
state.connected = true;
|
|
127
|
+
start();
|
|
128
|
+
});
|
|
129
|
+
this.client.on('empty', () => {
|
|
130
|
+
state.connected = false;
|
|
131
|
+
});
|
|
132
|
+
this.client.handleMessages('navigation', (e) => {
|
|
133
|
+
if (!crossNavigation
|
|
134
|
+
|| (crossNavigation === -1 && e.data.pathname === this.url.pathname)
|
|
135
|
+
|| (typeof crossNavigation === 'function' && !crossNavigation(e.data))) {
|
|
136
|
+
state.navigatedAway = true;
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
setTimeout(() => {
|
|
140
|
+
if (!state.connected) {
|
|
141
|
+
res();
|
|
142
|
+
}
|
|
143
|
+
}, 30000/*30sec*/);
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
|
|
103
147
|
async with(url, init = {}) {
|
|
104
148
|
if (!this.request) {
|
|
105
149
|
return new HttpEvent(this, { ...this.#init, url });
|
|
@@ -371,9 +371,9 @@ export class WebfloClient extends WebfloRuntime {
|
|
|
371
371
|
const { BINDINGS_API: { api: bindingsConfig } = {}, } = window.webqit.oohtml.configs;
|
|
372
372
|
scope.context = this.host[bindingsConfig.bindings].data || {};
|
|
373
373
|
}
|
|
374
|
-
if (scope.request.method === 'GET') {
|
|
375
|
-
// Ping
|
|
376
|
-
this.#backgroundMessaging.postMessage('navigation');
|
|
374
|
+
if (scope.request.method === 'GET' || (scope.request.method === 'POST' && scope.url.pathname !== this.location.pathname)) {
|
|
375
|
+
// Ping existing background process
|
|
376
|
+
this.#backgroundMessaging.postMessage({ ...Url.copy(scope.url), method: scope.request.method }, { messageType: 'navigation' });
|
|
377
377
|
}
|
|
378
378
|
// Dispatch for response
|
|
379
379
|
scope.response = await this.dispatch(scope.httpEvent, scope.context, async (event) => {
|
|
@@ -141,7 +141,6 @@ export class WebfloSubClient extends WebfloClient {
|
|
|
141
141
|
const top = (window.outerHeight - height) / 2;
|
|
142
142
|
const popup = window.open(location, '_blank', `popup=true,width=${width},height=${height},left=${left},top=${top}`);
|
|
143
143
|
if (backgroundMessaging) {
|
|
144
|
-
backgroundMessaging.postMessage('keepAlive');
|
|
145
144
|
Observer.set(this.navigator, 'redirecting', new Url/*NOT URL*/(location), { diff: true });
|
|
146
145
|
backgroundMessaging.addEventListener('close', (e) => {
|
|
147
146
|
Observer.set(this.navigator, 'redirecting', null);
|