@webqit/webflo 0.8.76 → 0.9.0

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.
Files changed (97) hide show
  1. package/package.json +5 -12
  2. package/src/Cli.js +131 -0
  3. package/src/Configurator.js +97 -0
  4. package/src/Context.js +76 -0
  5. package/src/config-pi/deployment/Env.js +69 -0
  6. package/src/config-pi/deployment/Layout.js +65 -0
  7. package/src/config-pi/deployment/Origins.js +133 -0
  8. package/src/config-pi/deployment/Virtualization.js +65 -0
  9. package/src/config-pi/deployment/index.js +18 -0
  10. package/src/config-pi/index.js +16 -0
  11. package/src/config-pi/runtime/Client.js +59 -0
  12. package/src/config-pi/runtime/Server.js +174 -0
  13. package/src/config-pi/runtime/client/Worker.js +117 -0
  14. package/src/config-pi/runtime/client/index.js +12 -0
  15. package/src/config-pi/runtime/index.js +18 -0
  16. package/src/config-pi/runtime/server/Headers.js +90 -0
  17. package/src/config-pi/runtime/server/Redirects.js +108 -0
  18. package/src/config-pi/runtime/server/index.js +14 -0
  19. package/src/config-pi/static/Manifest.js +321 -0
  20. package/src/config-pi/static/Ssg.js +72 -0
  21. package/src/config-pi/static/index.js +14 -0
  22. package/src/deployment-pi/index.js +10 -0
  23. package/src/{services → deployment-pi}/origins/index.js +88 -58
  24. package/src/index.js +14 -147
  25. package/src/{runtime → runtime-pi}/Router.js +19 -19
  26. package/src/runtime-pi/client/Context.js +7 -0
  27. package/src/{runtime → runtime-pi}/client/Router.js +2 -2
  28. package/src/{runtime/client/Navigator.js → runtime-pi/client/Runtime.js} +143 -102
  29. package/src/runtime-pi/client/RuntimeClient.js +114 -0
  30. package/src/{runtime → runtime-pi}/client/Storage.js +8 -7
  31. package/src/{runtime → runtime-pi}/client/Url.js +2 -6
  32. package/src/{runtime/client/WorkerClient.js → runtime-pi/client/WorkerComm.js} +2 -2
  33. package/src/runtime-pi/client/generate.js +242 -0
  34. package/src/runtime-pi/client/generate.oohtml.js +7 -0
  35. package/src/runtime-pi/client/index.js +18 -0
  36. package/src/runtime-pi/client/whatwag.js +27 -0
  37. package/src/runtime-pi/client/worker/Context.js +7 -0
  38. package/src/runtime-pi/client/worker/Worker.js +243 -0
  39. package/src/runtime-pi/client/worker/WorkerClient.js +46 -0
  40. package/src/runtime-pi/client/worker/index.js +18 -0
  41. package/src/runtime-pi/index.js +14 -0
  42. package/src/runtime-pi/server/Context.js +16 -0
  43. package/src/{runtime → runtime-pi}/server/Router.js +6 -6
  44. package/src/runtime-pi/server/Runtime.js +531 -0
  45. package/src/runtime-pi/server/RuntimeClient.js +102 -0
  46. package/src/runtime-pi/server/index.js +41 -0
  47. package/src/runtime-pi/server/whatwag.js +35 -0
  48. package/src/{runtime → runtime-pi}/util.js +0 -0
  49. package/src/{runtime/_FormData.js → runtime-pi/xFormData.js} +2 -2
  50. package/src/{runtime/_Headers.js → runtime-pi/xHeaders.js} +4 -4
  51. package/src/runtime-pi/xHttpEvent.js +93 -0
  52. package/src/runtime-pi/xHttpMessage.js +179 -0
  53. package/src/runtime-pi/xRequest.js +67 -0
  54. package/src/runtime-pi/xRequestHeaders.js +95 -0
  55. package/src/runtime-pi/xResponse.js +62 -0
  56. package/src/{runtime/_ResponseHeaders.js → runtime-pi/xResponseHeaders.js} +38 -18
  57. package/src/{runtime/_URL.js → runtime-pi/xURL.js} +4 -4
  58. package/src/runtime-pi/xfetch.js +7 -0
  59. package/src/{services → services-pi}/certbot/http-auth-hook.js +0 -0
  60. package/src/{services → services-pi}/certbot/http-cleanup-hook.js +0 -0
  61. package/src/{services → services-pi}/certbot/index.js +21 -15
  62. package/src/services-pi/index.js +9 -0
  63. package/src/static-pi/index.js +11 -0
  64. package/src/webflo.js +33 -0
  65. package/test/index.test.js +26 -0
  66. package/src/build/client/index.js +0 -261
  67. package/src/build/index.js +0 -5
  68. package/src/config/client.js +0 -191
  69. package/src/config/headers.js +0 -121
  70. package/src/config/index.js +0 -14
  71. package/src/config/layout.js +0 -83
  72. package/src/config/manifest.js +0 -341
  73. package/src/config/origins.js +0 -165
  74. package/src/config/prerendering.js +0 -100
  75. package/src/config/redirects.js +0 -137
  76. package/src/config/server.js +0 -201
  77. package/src/config/variables.js +0 -102
  78. package/src/config/vhosts.js +0 -93
  79. package/src/runtime/_MessageStream.js +0 -195
  80. package/src/runtime/_NavigationEvent.js +0 -91
  81. package/src/runtime/_Request.js +0 -61
  82. package/src/runtime/_RequestHeaders.js +0 -72
  83. package/src/runtime/_Response.js +0 -56
  84. package/src/runtime/client/Cache.js +0 -38
  85. package/src/runtime/client/Http.js +0 -225
  86. package/src/runtime/client/NavigationEvent.js +0 -21
  87. package/src/runtime/client/Runtime.js +0 -126
  88. package/src/runtime/client/StdRequest.js +0 -74
  89. package/src/runtime/client/Worker.js +0 -312
  90. package/src/runtime/client/WorkerComm.js +0 -183
  91. package/src/runtime/client/effects/sounds.js +0 -64
  92. package/src/runtime/index.js +0 -5
  93. package/src/runtime/server/NavigationEvent.js +0 -39
  94. package/src/runtime/server/Runtime.js +0 -593
  95. package/src/runtime/server/index.js +0 -183
  96. package/src/runtime/server/index.mjs +0 -10
  97. package/src/services/index.js +0 -6
@@ -1,312 +0,0 @@
1
-
2
- /**
3
- * @imports
4
- */
5
- import Router from './Router.js';
6
- import _isGlobe from 'is-glob';
7
- import Minimatch from 'minimatch';
8
- import Observer from '@webqit/observer';
9
- import _isArray from '@webqit/util/js/isArray.js';
10
- import _afterLast from '@webqit/util/str/afterLast.js';
11
- import _after from '@webqit/util/str/after.js';
12
- import _before from '@webqit/util/str/before.js';
13
- import _any from '@webqit/util/arr/any.js';
14
- import _copy from '@webqit/util/obj/copy.js';
15
- import NavigationEvent from './NavigationEvent.js';
16
-
17
- /**
18
- * ---------------------------
19
- * The Worker Initializer
20
- * ---------------------------
21
- */
22
-
23
- export default function(layout, params) {
24
-
25
- // Copy...
26
- layout = { ...layout };
27
- params = { ...params };
28
- const sessionStores = Object.create(null);
29
- const localStores = Object.create(null);
30
-
31
- /**
32
- * -------------
33
- * ONINSTALL
34
- * -------------
35
- */
36
-
37
- self.addEventListener('install', evt => {
38
-
39
- if (params.skip_waiting) {
40
- self.skipWaiting();
41
- }
42
- // Manage CACHE
43
- if (params.cache_name && params.static_caching_list) {
44
- // Add files to cache
45
- evt.waitUntil(
46
- self.caches.open(params.cache_name).then(cache => {
47
- if (params.lifecycle_logs) {
48
- console.log('[ServiceWorker] Pre-caching resources.');
49
- }
50
- const cache_only_url_list = (params.cache_only_url_list || []).map(c => c.trim()).filter(c => c);//.reduce((all, url) => all.concat(Micromatch.brace(url, { expand: true })), []);
51
- return cache.addAll(cache_only_url_list.filter(url => !_isGlobe(url) && !_afterLast(url, '.').includes('/')));
52
- })
53
- );
54
- }
55
-
56
- });
57
-
58
- /**
59
- * -------------
60
- * ONACTIVATE
61
- * -------------
62
- */
63
-
64
- self.addEventListener('activate', evt => {
65
-
66
- evt.waitUntil(
67
- new Promise(async resolve => {
68
- if (params.skip_waiting) {
69
- await self.clients.claim();
70
- }
71
- // Manage CACHE
72
- if (params.cache_name) {
73
- // Clear outdated CACHES
74
- await self.caches.keys().then(keyList => {
75
- return Promise.all(keyList.map(key => {
76
- if (key !== params.cache_name && key !== params.cache_name + '_json') {
77
- if (params.lifecycle_logs) {
78
- console.log('[ServiceWorker] Removing old cache:', key);
79
- }
80
- return self.caches.delete(key);
81
- }
82
- }));
83
- })
84
- }
85
- resolve();
86
- })
87
- );
88
-
89
- });
90
-
91
- /**
92
- * -------------
93
- * ONFETCH
94
- * -------------
95
- */
96
-
97
- // Listen now...
98
- self.addEventListener('fetch', async evt => {
99
- // URL schemes that might arrive here but not supported; e.g.: chrome-extension://
100
- if (!evt.request.url.startsWith('http')) return;
101
- // Fetches request
102
- const handleFetch = async evt => {
103
-
104
- if (evt.request.url.startsWith(self.origin) && (evt.request.mode === 'navigate' || evt.request.headers.get('X-Powered-By') === '@webqit/webflo')) {
105
- // -----------------
106
- // Sync session data to cache to be available to service-worker routers
107
- // Sync only takes for requests that actually do send the "$session" cookie
108
- const sessionData = Observer.proxy(sessionStores[evt.clientId] || {});
109
- const clientNavigationEvent = new NavigationEvent(new NavigationEvent.Request(evt.request), sessionData);
110
- // -----------------
111
- // The app router
112
- const router = new Router(_before(evt.request.url, '?'), layout, { layout });
113
- const httpMethodName = evt.request.method.toLowerCase();
114
- const _response = await router.route([httpMethodName === 'delete' ? 'del' : httpMethodName, 'default'], clientNavigationEvent, null, (event, arg) => defaultFetch(evt));
115
- if (!(_response instanceof Response)/* _response being a native Response instance is fine */) {
116
- return new NavigationEvent.Response(_response);
117
- }
118
- return _response;
119
- }
120
-
121
- return defaultFetch(evt);
122
- };
123
- let response = handleFetch(evt);
124
- evt.respondWith(response);
125
- });
126
-
127
- const defaultFetch = function(evt) {
128
- if (_any((params.cache_only_url_list || []).map(c => c.trim()).filter(c => c), pattern => Minimatch.Minimatch(evt.request.url, pattern))) {
129
- return cache_fetch(evt);
130
- }
131
- // Now, the following is key:
132
- // The browser likes to use "force-cache" for "navigate" requests
133
- // when, for example, the back button was used.
134
- // Thus the origin server would still not be contacted by the self.fetch() below, leading to inconsistencies in responses.
135
- // So, we detect this scenerio and avoid it.
136
- if (evt.request.mode === 'navigate' && evt.request.cache === 'force-cache' && evt.request.destination === 'document') {
137
- return cache_fetch(evt, false, true);
138
- }
139
- if (_any((params.cache_first_url_list || []).map(c => c.trim()).filter(c => c), pattern => Minimatch.Minimatch(evt.request.url, pattern))) {
140
- return cache_fetch(evt, true/** cacheRefresh */);
141
- }
142
- if (_any((params.network_first_url_list || []).map(c => c.trim()).filter(c => c), pattern => Minimatch.Minimatch(evt.request.url, pattern))) {
143
- return network_fetch(evt, true/** cacheFallback */);
144
- }
145
- return network_fetch(evt);
146
- };
147
-
148
- //evt.request.mode navigate evt.request.cache force-cache evt.request.destination document request.headers.get('Accept') text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
149
-
150
- const getCacheName = request => request.headers.get('Accept') === 'application/json'
151
- ? params.cache_name + '_json'
152
- : params.cache_name;
153
-
154
- // Caching strategy: cache_first
155
- const cache_fetch = (evt, cacheRefresh = false, is_Navigate_ForceCache_Document = false) => {
156
-
157
- return self.caches.open(getCacheName(evt.request)).then(cache => {
158
- return cache.match(evt.request).then(response => {
159
- const force_network_fetch = evt => {
160
- let request = evt.request;
161
- if (is_Navigate_ForceCache_Document) {
162
- let url = new URL(request.url);
163
- url.searchParams.set('$force-cache', '1');
164
- request = new Request(url, {
165
- method: request.method,
166
- headers: request.headers,
167
- body: request.body,
168
- mode: request.mode === 'navigate'/* throws */ ? null : request.mode,
169
- credentials: request.credentials,
170
- cache: request.cache,
171
- redirect: request.redirect,
172
- referrer: request.referrer,
173
- integrity: request.integrity,
174
- });
175
- }
176
- return self.fetch(request);
177
- }
178
- if (response) {
179
- if (cacheRefresh) {
180
- // Fetch, but return this immediately
181
- force_network_fetch(evt).then(response => refreshCache(evt.request, response));
182
- }
183
- return response;
184
- }
185
- return force_network_fetch(evt).then(response => refreshCache(evt.request, response));
186
- });
187
- });
188
-
189
- };
190
-
191
- // Caching strategy: network_first
192
- const network_fetch = (evt, cacheFallback) => {
193
- if (!cacheFallback) {
194
- return self.fetch(evt.request);
195
- }
196
- return self.fetch(evt.request).then(response => refreshCache(evt.request, response)).catch(e => {
197
- return self.caches.open(getCacheName(evt.request)).then(cache => {
198
- return cache.match(evt.request);
199
- });
200
- });
201
- };
202
-
203
- // Caches response
204
- const refreshCache = (request, response) => {
205
-
206
- // Check if we received a valid response
207
- if ((request._method || request.method) !== 'GET' || !response || response.status !== 200 || (response.type !== 'basic' && response.type !== 'cors')) {
208
- return response;
209
- }
210
-
211
- // IMPORTANT: Clone the response. A response is a stream
212
- // and because we want the browser to consume the response
213
- // as well as the cache consuming the response, we need
214
- // to clone it so we have two streams.
215
- var responseToCache = response.clone();
216
- self.caches.open(getCacheName(request)).then(cache => {
217
- if (params.lifecycle_logs) {
218
- console.log('[ServiceWorker] Refreshing cache:', request.url);
219
- }
220
- cache.put(request, responseToCache);
221
- });
222
-
223
- return response;
224
- };
225
-
226
- // -----------------------------
227
-
228
- const relay = function(evt, messageData) {
229
- return self.clients.matchAll().then(clientList => {
230
- clientList.forEach(client => {
231
- if (client.id === evt.source.id) {
232
- return;
233
- }
234
- client.postMessage(messageData);
235
- });
236
- });
237
- };
238
-
239
- self.addEventListener('message', evt => {
240
-
241
- // Handle normally
242
- const router = new Router('/', layout, { layout });
243
- evt.waitUntil(
244
- router.route('postmessage', evt, null, function() {
245
- return self;
246
- })
247
- );
248
-
249
- });
250
-
251
- self.addEventListener('push', evt => {
252
- const router = new Router('/', layout, { layout });
253
- evt.waitUntil(
254
- router.route('push', evt, null, function() {
255
- return self;
256
- })
257
- );
258
- });
259
-
260
- self.addEventListener('notificationclick', evt => {
261
- const router = new Router('/', layout, { layout });
262
- evt.waitUntil(
263
- router.route('notificationclick', evt, null, function() {
264
- return self;
265
- })
266
- );
267
- });
268
-
269
- self.addEventListener('notificationclose', evt => {
270
- const router = new Router('/', layout, { layout });
271
- evt.waitUntil(
272
- router.route('notificationclose', evt, null, function() {
273
- return self;
274
- })
275
- );
276
- });
277
-
278
- };
279
-
280
- /**
281
- * @utils
282
- */
283
- const matchClientUrl = (client, url) => '/' + _after(_after(client.url, '//'), '/') === url;
284
-
285
- /**
286
-
287
- if (notificationData) {
288
- var title = params.NOTIFICATION_TITLE || '';
289
- if (_isArray(notificationData)) {
290
- title = notificationData[0];
291
- notificationData = notificationData[1];
292
- }
293
- return self.registration.showNotification(title, notificationData);
294
- }
295
-
296
- var cuurentClientAtUrl = self.clients.matchAll().then(clientList => {
297
- // Take the user to the app... the current open window or a new window
298
- return clientList.reduce((cuurentClientAtUrl, client) => {
299
- return cuurentClientAtUrl || matchClientUrl(client, pathname) ? client : null;
300
- }, null);
301
- });
302
- if (cuurentClientAtUrl) {
303
- return cuurentClientAtUrl.focus();
304
- }
305
- return self.clients.openWindow(pathname);
306
-
307
- return self.clients.matchAll().then(clientList => {
308
- // Take the user to the app
309
- return clientList.reduce((cuurentClientAtUrl, client) => cuurentClientAtUrl || matchClientUrl(client, pathname) ? client : null, null);
310
- });
311
-
312
- */
@@ -1,183 +0,0 @@
1
-
2
-
3
- /**
4
- * @imports
5
- */
6
-
7
- var _sab;
8
- export function request(context, data = {}) {
9
- var response;
10
- const channel = new MessageChannel();
11
- channel.port1.onmessage = e => (console.log('-----receiving'), response = e.data);
12
- console.log('------waiting 11111', self.crossOriginIsolated);
13
- try {
14
- _sab = _sab || new ArrayBuffer(4); Atomics;
15
- context.postMessage({ _sab, ...data, }, [ channel.port2 ]);
16
- Atomics.wait(new Int32Array(_sab), 0, 0, 400);
17
- return channel;
18
- } catch (e) {
19
- console.error('error1', e);
20
- var x = new XMLHttpRequest();
21
- x.timeout = 400;
22
- x.open('get', '/@sleep@/t.js?t=400', false);
23
- x.setRequestHeader('cache-control', 'no-cache, no-store, max-age=0');
24
- try { x.send() } catch(e) { console.error('error2', e, response) }
25
- }
26
-
27
- return response;
28
- }
29
-
30
- export function listen(context, handler) {
31
- console.log('::::::::::::::::::', crossOriginIsolated)
32
- context.addEventListener('message', e => {
33
- if (e.data._sab instanceof SharedArrayBuffer && e.ports.length) {
34
- console.log('--------handling', e.data)
35
- var response = handler(e.data);
36
- if (response !== undefined) {
37
- e.ports[0].postMessage(response);
38
- console.log('--------sent');
39
- Atomics.notify(new Int32Array(e.data._sab), 0, 1);
40
- console.log('--------notified');
41
- }
42
- }
43
- });
44
- }
45
-
46
- /**
47
- * ------------------
48
- * https://www.sitepen.com/blog/the-return-of-sharedarraybuffers-and-atomics
49
- * ------------------
50
- */
51
-
52
- export function sharedArrayBufferToUtf16String(buf) {
53
- const array = new Uint16Array(buf);
54
- return String.fromCharCode.apply(null, array);
55
- }
56
-
57
- export function utf16StringToSharedArrayBuffer(str) {
58
- // 2 bytes for each char
59
- const bytes = str.length *2;
60
- const buffer = new SharedArrayBuffer(bytes);
61
- const arrayBuffer = new Uint16Array(buffer);
62
- for (let i = 0, strLen = str.length; i < strLen; i++) {
63
- arrayBuffer[i] = str.charCodeAt(i);
64
- }
65
- return { array: arrayBuffer, buffer: buffer };
66
- }
67
-
68
- export function encodeUf8StringToSharedArrayBuffer(string) {
69
- // Calculate the byte size of the UTF-8 string
70
- let bytes = string.length;
71
- for (let i = string.length -1; i <= 0; i--) {
72
- const code = string.charCodeAt(i);
73
- if (code > 0x7f && code <= 0x7ff) {
74
- bytes++;
75
- } else if (code > 0x7ff && code <= 0xffff) {
76
- bytes+=2;
77
- }
78
- if (code >= 0xdc00 && code <= 0xdfff) {
79
- i--; // trail surrogate
80
- }
81
- }
82
- const buffer = new SharedArrayBuffer(bytes);
83
- const arrayBuffer = new Uint8Array(buffer);
84
- const encoded = unescape(encodeURIComponent(string));
85
- for (var i = 0; i < encoded.length; i++) {
86
- arrayBuffer[i] = encoded[i].charCodeAt(0);
87
- }
88
- return { array: arrayBuffer, buffer: buffer };
89
- }
90
-
91
- export function decodeUtf8StringFromSharedArrayBuffer(array) {
92
- var encodedString = String.fromCharCode.apply(null, array);
93
- var decodedString = decodeURIComponent(escape(encodedString));
94
- return decodedString;
95
- }
96
-
97
- /**
98
- * // main.js
99
- worker.postMessage(sharedBuffer);
100
- // worker.js
101
- constsharedArray = new Int32Array(m.data);
102
-
103
- const exampleString = "Hello world, this is an example string!";
104
- const sharedArrayBuffer = utf16StringToSharedArrayBuffer(exampleString).buffer;
105
- const backToString = sharedArrayBufferToUtf16String(sharedArrayBuffer);
106
- */
107
-
108
- // Sync Local Storage
109
- function sharedStore(store, persistent = false, onAvailability = 1) {
110
- const storeData = () => Object.keys(store).reduce((_store, key) => (_store[key] = store[key], _store), {});
111
- this.post.send(() => ({ _type: 'WHOLE_STORAGE_SYNC', _persistent: persistent, store: storeData() }), onAvailability);
112
- window.addEventListener('beforeunload', e => {
113
- this.post.send({ _type: 'WHOLE_STORAGE_SYNC', _persistent: persistent });
114
- });
115
- // --------
116
- Observer.observe(store, changes => {
117
- changes.forEach(change => {
118
- if (change.type === 'set') {
119
- if (!(change.detail || {}).noSync) {
120
- this.post.send({ _type: 'STORAGE_SYNC', _persistent: persistent, ..._copy(change, [ 'type', 'name', 'path', 'value', 'oldValue', 'isUpdate', 'related', ]) });
121
- }
122
- } else if (change.type === 'deletion') {
123
- if (!(change.detail || {}).noSync) {
124
- this.post.send({ _type: 'STORAGE_SYNC', _persistent: persistent, ..._copy(change, [ 'type', 'name', 'path', 'value', 'oldValue', 'isUpdate', 'related', ]) });
125
- }
126
- }
127
- });
128
- });
129
- // --------
130
- this.post.receive(e => {
131
- if (e.data && e.data._type === 'STORAGE_SYNC' && e.data._persistent === persistent) {
132
- if (e.data.type === 'set') {
133
- Observer.set(store, e.data.name, e.data.value, { detail: { noSync: true } });
134
- } else if (e.data.type === 'deletion') {
135
- Observer.deleteProperty(store, e.data.name, { detail: { noSync: true } });
136
- }
137
- }
138
- }, onAvailability);
139
- }
140
-
141
- self.addEventListener('message', evt => {
142
-
143
- // SESSION_SYNC
144
- var clientId = evt.source.id;
145
- if (evt.data && evt.data._type === 'WHOLE_STORAGE_SYNC') {
146
- const storage = evt.data._persistent ? localStores : sessionStores;
147
- if (evt.data.store) {
148
- storage[clientId] = evt.data.store;
149
- // --------------------------
150
- // Get mutations synced TO client
151
- Observer.observe(storage[clientId], changes => {
152
- changes.forEach(change => {
153
- if (!(change.detail || {}).noSync) {
154
- self.clients.get(clientId).then(client => {
155
- client.postMessage({ _type: 'STORAGE_SYNC', _persistent: evt.data._persistent, ..._copy(change, [ 'type', 'name', 'path', 'value', 'oldValue', 'isUpdate', 'related', ]), });
156
- });
157
- }
158
- });
159
- });
160
- // --------------------------
161
- } else {
162
- delete storage[clientId];
163
- }
164
- } else if (evt.data && evt.data._type === 'STORAGE_SYNC') {
165
- // --------------------------
166
- // Get mutations synced FROM client
167
- const storage = evt.data._persistent ? localStores : sessionStores;
168
- if (evt.data.type === 'set') {
169
- if (storage[clientId]) Observer.set(storage[clientId], evt.data.name, evt.data.value, { detail: { noSync: true } });
170
- } else if (evt.data.type === 'deletion') {
171
- if (storage[clientId]) Observer.deleteProperty(storage[clientId], evt.data.name, { detail: { noSync: true } });
172
- }
173
- // --------------------------
174
-
175
- // --------------------------
176
- // Relay to other clients
177
- if (evt.data._persistent) {
178
- relay(evt, evt.data);
179
- }
180
- // --------------------------
181
- return;
182
- }
183
- });
@@ -1,64 +0,0 @@
1
- const context = new window.AudioContext();
2
-
3
- export function playFile(filepath) {
4
- // see https://jakearchibald.com/2016/sounds-fun/
5
- // Fetch the file
6
- fetch(filepath)
7
- // Read it into memory as an arrayBuffer
8
- .then(response => response.arrayBuffer())
9
- // Turn it from mp3/aac/whatever into raw audio data
10
- .then(arrayBuffer => context.decodeAudioData(arrayBuffer))
11
- .then(audioBuffer => {
12
- // Now we're ready to play!
13
- const soundSource = context.createBufferSource();
14
- soundSource.buffer = audioBuffer;
15
- soundSource.connect(context.destination);
16
- soundSource.start();
17
- });
18
- }
19
-
20
- export function playSuccess() {
21
- const successNoise = context.createOscillator();
22
- successNoise.frequency = "600";
23
- successNoise.type = "sine";
24
- successNoise.frequency.exponentialRampToValueAtTime(800, context.currentTime + 0.05);
25
- successNoise.frequency.exponentialRampToValueAtTime(1000, context.currentTime + 0.15);
26
-
27
- successGain = context.createGain();
28
- successGain.gain.exponentialRampToValueAtTime(0.01, context.currentTime + 0.3);
29
-
30
- successFilter = context.createBiquadFilter("bandpass");
31
- successFilter.Q = 0.01;
32
-
33
- successNoise
34
- .connect(successFilter)
35
- .connect(successGain)
36
- .connect(context.destination);
37
- successNoise.start();
38
- successNoise.stop(context.currentTime + 0.2);
39
- }
40
-
41
- export function playError() {
42
- const errorNoise = context.createOscillator();
43
- errorNoise.frequency = "400";
44
- errorNoise.type = "sine";
45
- errorNoise.frequency.exponentialRampToValueAtTime(200, context.currentTime + 0.05);
46
- errorNoise.frequency.exponentialRampToValueAtTime(100, context.currentTime + 0.2);
47
-
48
- errorGain = context.createGain();
49
- errorGain.gain.exponentialRampToValueAtTime(0.01, context.currentTime + 0.3);
50
-
51
- errorNoise.connect(errorGain).connect(context.destination);
52
- errorNoise.start();
53
- errorNoise.stop(context.currentTime + 0.3);
54
- }
55
-
56
- let successButton = document.querySelector("#success");
57
- successButton.addEventListener("click", function() {
58
- playFile('https://s3-us-west-2.amazonaws.com/s.cdpn.io/3/success.mp3');
59
- });
60
-
61
- let errorButton = document.querySelector("#error");
62
- errorButton.addEventListener("click", function() {
63
- playFile('https://s3-us-west-2.amazonaws.com/s.cdpn.io/3/error.mp3');
64
- });
@@ -1,5 +0,0 @@
1
-
2
- /**
3
- * exports
4
- */
5
- export * as server from './server/index.js';
@@ -1,39 +0,0 @@
1
-
2
- /**
3
- * @imports
4
- */
5
- import { URL } from 'url';
6
- import { Readable } from "stream";
7
- import { FormData, File, Blob } from 'formdata-node';
8
- import { FormDataEncoder } from 'form-data-encoder';
9
- import fetch, { Request, Response, Headers } from 'node-fetch';
10
- import _NavigationEvent from '../_NavigationEvent.js';
11
- import _FormData from '../_FormData.js';
12
-
13
- /**
14
- * Patch MessageStream with formData()
15
- */
16
- const _streamFormDataPatch = MessageStream => class extends MessageStream {
17
-
18
- // formData() polyfill
19
- async formData() {
20
- return null;
21
- }
22
-
23
- };
24
-
25
- /**
26
- * The NavigationEvent class
27
- */
28
- export default _NavigationEvent({
29
- URL,
30
- Request: _streamFormDataPatch(Request),
31
- Response: _streamFormDataPatch(Response),
32
- Headers,
33
- FormData: _FormData(FormData),
34
- File,
35
- Blob,
36
- ReadableStream: Readable,
37
- FormDataEncoder,
38
- fetch
39
- });