@webqit/webflo 0.10.5 → 0.11.2
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/README.md +1082 -323
- package/package.json +2 -2
- package/src/config-pi/runtime/Client.js +7 -10
- package/src/config-pi/runtime/client/Worker.js +30 -12
- package/src/runtime-pi/Router.js +1 -1
- package/src/runtime-pi/client/Runtime.js +98 -49
- package/src/runtime-pi/client/RuntimeClient.js +12 -40
- package/src/runtime-pi/client/Workport.js +163 -0
- package/src/runtime-pi/client/generate.js +71 -37
- package/src/runtime-pi/client/worker/Worker.js +57 -23
- package/src/runtime-pi/client/worker/Workport.js +80 -0
- package/src/runtime-pi/server/Runtime.js +22 -8
- package/src/runtime-pi/server/RuntimeClient.js +6 -6
- package/src/runtime-pi/util.js +2 -2
- package/test/site/package.json +9 -0
- package/test/site/public/bundle.html +3 -0
- package/test/site/public/bundle.html.json +1 -0
- package/test/site/public/bundle.js +1 -1
- package/test/site/public/bundle.js.gz +0 -0
- package/test/site/public/bundle.webflo.js +8 -8
- package/test/site/public/bundle.webflo.js.gz +0 -0
- package/test/site/public/index.html +5 -5
- package/test/site/public/index1.html +35 -0
- package/test/site/public/page-2/bundle.js +1 -1
- package/test/site/public/page-2/bundle.js.gz +0 -0
- package/test/site/public/page-2/index.html +3 -4
- package/test/site/public/page-3/logo-130x130.png +0 -0
- package/test/site/public/page-4/subpage/bundle.js +1 -1
- package/test/site/public/page-4/subpage/bundle.js.gz +0 -0
- package/test/site/public/sparoots.json +5 -0
- package/test/site/public/worker.js +1 -1
- package/test/site/public/worker.js.gz +0 -0
- package/test/site/server/index.js +14 -6
- package/docker/Dockerfile +0 -26
- package/docker/README.md +0 -77
- package/src/runtime-pi/client/WorkerComm.js +0 -102
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @imports
|
|
5
|
-
*/
|
|
6
|
-
import { _isFunction } from '@webqit/util/js/index.js';
|
|
7
|
-
import { Observer } from './Runtime.js';
|
|
8
|
-
|
|
9
|
-
export default class WorkerComm {
|
|
10
|
-
|
|
11
|
-
constructor(file, params = {}) {
|
|
12
|
-
this.ready = navigator.serviceWorker.ready;
|
|
13
|
-
// --------
|
|
14
|
-
// Registration and lifecycle
|
|
15
|
-
// --------
|
|
16
|
-
this.registration = new Promise((resolve, reject) => {
|
|
17
|
-
const register = () => {
|
|
18
|
-
navigator.serviceWorker.register(file, { scope: params.scope || '/' }).then(async registration => {
|
|
19
|
-
|
|
20
|
-
// Helper that updates instance's state
|
|
21
|
-
const state = target => {
|
|
22
|
-
// instance2.state can be any of: "installing", "installed", "activating", "activated", "redundant"
|
|
23
|
-
const equivState = target.state === 'installed' ? 'waiting' :
|
|
24
|
-
(target.state === 'activating' || target.state === 'activated' ? 'active' : target.state)
|
|
25
|
-
Observer.set(this, equivState, target);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// We're always installing at first for a new service worker.
|
|
29
|
-
// An existing service would immediately be active
|
|
30
|
-
const worker = registration.active || registration.waiting || registration.installing;
|
|
31
|
-
state(worker);
|
|
32
|
-
worker.addEventListener('statechange', e => state(e.target));
|
|
33
|
-
|
|
34
|
-
// "updatefound" event - a new worker that will control
|
|
35
|
-
// this page is installing somewhere
|
|
36
|
-
registration.addEventListener('updatefound', () => {
|
|
37
|
-
// If updatefound is fired, it means that there's
|
|
38
|
-
// a new service worker being installed.
|
|
39
|
-
state(registration.installing);
|
|
40
|
-
registration.installing.addEventListener('statechange', e => state(e.target));
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
resolve(registration);
|
|
44
|
-
}).catch(e => reject(e));
|
|
45
|
-
};
|
|
46
|
-
if (params.onWondowLoad) {
|
|
47
|
-
window.addEventListener('load', register);
|
|
48
|
-
} else {
|
|
49
|
-
register();
|
|
50
|
-
}
|
|
51
|
-
if (params.startMessages) {
|
|
52
|
-
navigator.serviceWorker.startMessages();
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
// --------
|
|
56
|
-
// Post messaging
|
|
57
|
-
// --------
|
|
58
|
-
this.post = {
|
|
59
|
-
send: (message, onAvailability = 1) => {
|
|
60
|
-
if (this.active) {
|
|
61
|
-
if (_isFunction(message)) message = message();
|
|
62
|
-
this.active.postMessage(message);
|
|
63
|
-
} else if (onAvailability) {
|
|
64
|
-
// Availability Handling
|
|
65
|
-
const availabilityHandler = entry => {
|
|
66
|
-
if (_isFunction(message)) message = message();
|
|
67
|
-
entry.value.postMessage(message);
|
|
68
|
-
if (onAvailability !== 2) {
|
|
69
|
-
Observer.unobserve(this, 'active', availabilityHandler);
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
Observer.observe(this, 'active', availabilityHandler);
|
|
73
|
-
}
|
|
74
|
-
return this.post;
|
|
75
|
-
},
|
|
76
|
-
receive: callback => {
|
|
77
|
-
navigator.serviceWorker.addEventListener('message', callback);
|
|
78
|
-
return this.post;
|
|
79
|
-
},
|
|
80
|
-
}
|
|
81
|
-
// --------
|
|
82
|
-
// Push notifications
|
|
83
|
-
// --------
|
|
84
|
-
this.push = {
|
|
85
|
-
getSubscription: async () => {
|
|
86
|
-
return (await this.registration).pushManager.getSubscription();
|
|
87
|
-
},
|
|
88
|
-
subscribe: async (publicKey, params = {}) => {
|
|
89
|
-
var subscription = await this.push.getSubscription();
|
|
90
|
-
return subscription ? subscription : (await this.registration).pushManager.subscribe({
|
|
91
|
-
applicationServerKey: urlBase64ToUint8Array(publicKey),
|
|
92
|
-
...params,
|
|
93
|
-
});
|
|
94
|
-
},
|
|
95
|
-
unsubscribe: async () => {
|
|
96
|
-
var subscription = await this.push.getSubscription();
|
|
97
|
-
return !subscription ? null : subscription.unsubscribe();
|
|
98
|
-
},
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
}
|