@webqit/webflo 1.0.16 → 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 });
|
|
@@ -78,15 +78,17 @@ export class WebfloRouter {
|
|
|
78
78
|
thisTick.event.onRespondWith = null;
|
|
79
79
|
res(response);
|
|
80
80
|
};
|
|
81
|
-
const $returnValue = handler.call(thisContext, thisTick.event, thisTick.arg, _next/*next*/, remoteFetch);
|
|
81
|
+
const $returnValue = Promise.resolve(handler.call(thisContext, thisTick.event, thisTick.arg, _next/*next*/, remoteFetch));
|
|
82
|
+
// This should listen first before waitUntil's listener
|
|
83
|
+
$returnValue.then(async (returnValue) => {
|
|
84
|
+
if (thisTick.event.onRespondWith) {
|
|
85
|
+
thisTick.event.onRespondWith = null;
|
|
86
|
+
res(returnValue);
|
|
87
|
+
} else if (typeof returnValue !== 'undefined') {
|
|
88
|
+
await thisTick.event.respondWith(returnValue);
|
|
89
|
+
}
|
|
90
|
+
});
|
|
82
91
|
thisTick.event.waitUntil($returnValue);
|
|
83
|
-
const returnValue = await $returnValue;
|
|
84
|
-
if (thisTick.event.onRespondWith) {
|
|
85
|
-
thisTick.event.onRespondWith = null;
|
|
86
|
-
res(returnValue);
|
|
87
|
-
} else if (typeof returnValue !== 'undefined') {
|
|
88
|
-
await thisTick.event.respondWith(returnValue);
|
|
89
|
-
}
|
|
90
92
|
});
|
|
91
93
|
}
|
|
92
94
|
// Handler not found but exports found
|
|
@@ -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) => {
|
|
@@ -397,13 +397,10 @@ export class WebfloClient extends WebfloRuntime {
|
|
|
397
397
|
}
|
|
398
398
|
}
|
|
399
399
|
Promise.all([...scope.eventLifecyclePromises]).then(() => {
|
|
400
|
-
if (scope.clientMessaging.isMessaging()) {
|
|
401
|
-
scope.
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
}, 100);
|
|
405
|
-
});
|
|
406
|
-
} else scope.clientMessaging.close();
|
|
400
|
+
if (!scope.clientMessaging.isMessaging()) {
|
|
401
|
+
// DOn't clos the below; think the below: scope.httpEvent.client.postMessage()
|
|
402
|
+
//scope.clientMessaging.close();
|
|
403
|
+
}
|
|
407
404
|
});
|
|
408
405
|
// ---------------
|
|
409
406
|
// Decode response
|
|
@@ -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);
|