postalworker-es 4.0.7 → 5.0.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.
@@ -1,404 +0,0 @@
1
- /* eslint-disable */
2
- /**
3
- * PostalWorker String Constants
4
- * @type {string}
5
- */
6
- function throwsMessage(e){return"[Throws: "+(e?e.message:"?")+"]"}function safeGetValueFromPropertyOnObject(e,s){if(hasProp.call(e,s))try{return e[s]}catch(e){return throwsMessage(e)}return e[s]}function ensureProperties(e){// store references to objects we have seen before
7
- function s(e){if(null===e||"object"!=typeof e)return e;if(-1!==t.indexOf(e))return"[Circular]";if(t.push(e),"function"==typeof e.toJSON)try{var n=s(e.toJSON());return t.pop(),n}catch(e){return throwsMessage(e)}if(Array.isArray(e)){var o=e.map(s);return t.pop(),o}var r=Object.keys(e).reduce(function(t,n){
8
- // prevent faulty defined getter properties
9
- return t[n]=s(safeGetValueFromPropertyOnObject(e,n)),t},{});return t.pop(),r}var t=[];return s(e)}function main(e){return _PostalWorker||(_PostalWorker=new PostalWorker(e,index))}const POSTAL_WORKER="PostalWorker",POSTAL_SHARED_WORKER="PostalSharedWorker",POLYFILL_SHARED_WORKER="PolyfillSharedWorker",ON="ON",UN="UN",FIRE="FIRE",CROSSFIRE="CROSSFIRE",BACKFIRE="BACKFIRE",CHILDREGISTER="CHILDREGISTER",WORKERREGISTER="WORKERREGISTER",REGISTERID="REGISTERID",UNREGISTERID="UNREGISTERID",BROADCASTNODE="BROADCASTNODE",CROSSNODE="CROSSNODE",ERROR="ERROR",MESSAGE="message",SCRIPT="script",JS="js",LOAD="LOAD",RESPONSE="RESPONSE",SET_ADDRESS="SET_ADDRESS",CONNECT="CONNECT",DISCONNECT="DISCONNECT",POBOX="POBOX",POST="POST",COLLECT="COLLECT",CLOSEBOX="CLOSEBOX",BOXCLOSED="BOXCLOSED",PACKAGE="PACKAGE",PACK="PACK",DELIVERY="DELIVERY",_BLANK="_blank";class Deprecated{static registerWorker(e,s,t,n){e.port.onmessage=(e=>{
10
- // Handle messages sent from worker by type
11
- switch(e.data.type){case FIRE:// If the legacy messaging is used, it will still work here
12
- // Send the message
13
- e.data.data.msgClass&&t.get(e.data.data.msgClass)&&t.get(e.data.data.msgClass)(e.data.data.message),
14
- // Let worker know message was received
15
- e.currentTarget.postMessage(s);break;case SET_ADDRESS:Deprecated.address=e.data.data;break;case ERROR:console.error(e.data.data);break;default:console.warn(e)}})}}/**
16
- * Postal Helper defines the public API methods and creates window event handlers
17
- * for the postal worker and add/remove internal postal subscriptions used by the library
18
- * @author: Russ Stratfull
19
- */
20
- class PostalHelper{/**
21
- * Primary PostalWorker public methods
22
- * @param {*} module
23
- */
24
- static rootMethods(e){e.on=((s,t)=>e._on(s,t)),e.on.example=`PostalWorker().on('example', (msg) => console.info(msg))`,e.un=(s=>e._un(s)),e.un.example=`PostalWorker().un('example')`,e.fire=((s,t,n)=>e._fire(s,t,n)),e.fire.example=`PostalWorker().fire('example', 'Hello world')`,e.crossOn=((s,t,n,o,r)=>e._crossOn(s,t,n,o,r)),e.crossOn.example=`PostalWorker().crossOn('example', (msg) => console.info(msg), 'http://example.com', 'Example Name', )`,e.unCross=((s,t)=>e._unCross(s,t)),e.unCross.example=`PostalWorker().unCross('example', 'http://example.com')`,e.crossFire=((s,t)=>e._crossFire(s,t)),e.crossFire.example=`PostalWorker().crossFire('example', 'message to all windows/tabs cross launched')`,e.fireAll=((s,t)=>e._fireAll(s,t)),e.fireAll.example=`PostalWorker().fireAll('example', 'message to ALL windows/tabs/workers')`,e.load=(s=>e._load(s)),e.load.example=`PostalWorker().load('path/to/script.js')`,e.postBox=((s,t)=>e._postBox(s,t)),e.postBox.example=`PostalWorker().PObox('example', function(value) { console.log(value); })`,e.post=((s,t)=>e._post(s,t)),e.post.example=`PostalWorker().post('example', 'This is an example value')`,e.closeBox=(s=>e._closeBox(s)),e.closeBox.example=`PostalWorker().closeBox("example")`,e.package=((s,t)=>e._package(s,t)),e.package.example=`PostalWorker().package('example', (todo) => {})`,e.pack=((s,t)=>e._pack(s,t)),e.pack.example=`PostalWorker().pack('example', 'url/of/file.jpg')`}/**
25
- * Special method added when script detects that the current window is an iframe
26
- * @param {*} module
27
- */
28
- static backMethod(e){e.backFire=((s,t)=>e._backFire(s,t)),e.backFire.example=`PostalWorker().backfire('example', 'Message to parent window')`}/**
29
- * Utility methods which in the future could maybe be removed from public access
30
- * @param {*} module
31
- */
32
- static utilityMethods(e){}/**
33
- * Attach global window event handlers needed by PostalWorker
34
- * @param {*} module
35
- */
36
- static attachHandlers(e){
37
- // Beforewindow unloads, announce disconnect to community
38
- window.addEventListener("beforeunload",()=>{const s=e;s._unmapFromBroadcastNetwork(s.id);s._fireAll(DISCONNECT,{id:s.id,subscriber:s._getSubscriber(window.location.href)})}),
39
- // When window loads, announce connection to community
40
- window.addEventListener("load",()=>{const s=e;s._fireAll(CONNECT,{id:s.id,subscriber:s._getSubscriber(window.location.href)})})}/**
41
- * Establish internal usage of PostalWorker to create connect, disconnect, msgClasses
42
- * @param {*} module
43
- */
44
- static internalSubscriptions(e){
45
- // Connect
46
- e._on(CONNECT,s=>{
47
- // console.info("CONNECT", msg);
48
- const t=e;t._mapToBroadcastNetwork(s.id)}),e._crossOn(CONNECT,s=>{
49
- // console.info("crossOn CONNECT", msg);
50
- const t=e;let n=t._getOpeningWindows();//.get(msg.subscriber);
51
- let o=[];if(n){
52
- // wins.size should be 1 but todo: support multiple?
53
- for(let[e,r]of n)t._mapToWindow(s.id,r,s.subscriber),o.push(e);for(let e of o)t._getOpeningWindows().delete(e)}}),
54
- // Disconnect
55
- e._on(DISCONNECT,s=>{
56
- // console.info("DISCONNECT", msg);
57
- const t=e;t._unmapFromWindow(s.id)}),e._crossOn(DISCONNECT,s=>{
58
- // console.info("crossOn: DISCONNECT", msg);
59
- const t=e;t._unmapFromWindow(s.id)})}/**
60
- * Subscribe to postbox collection msgClass to get updates
61
- * @param {*} module
62
- */
63
- static registerCollection(e){
64
- // let last;
65
- e._on(COLLECT,s=>{const t=e;
66
- // const serialized = JSON.stringify(msg);
67
- //if (last !== serialized) {
68
- t._collectBox(s)})}/**
69
- * Unregister postbox collection msgClass
70
- * @param {*} module
71
- */
72
- static unregisterCollection(e){e._un(COLLECT)}/**
73
- * Register for temporary msgClass to get final update when postbox is being closed
74
- * @param {*} module
75
- * @param {*} add
76
- * @param {*} collect
77
- */
78
- static registerClosure(e,s,t){const n=t;e._getEvents().get(BOXCLOSED)||e._on(BOXCLOSED,s=>{const t=e;t._clearBox(s)}),e._lastCollection(s,n)}/**
79
- * Register for msgClass to receive package updates and deliver them
80
- * @param {*} module
81
- */
82
- static registerDelivery(e){e._on(DELIVERY,s=>{const t=e;t._delivery(s)})}}/**
83
- * PostalWorker Post Messenger Event Bus Module (ES6)
84
- * @description: Listen for and broadcast out messages by "message class"
85
- * between windows/tabs & web workers using the postMessage API
86
- * @Author: Russ Stratfull
87
- * @Contributors: Sakshi Dheer, & François Wauquier
88
- */
89
- let _config=!1,_stringify,_worker=!1,_parentWindow=!1,_subscriptions=new Set,_events=new Map,_crossEvents=new Map,_openingWindows=new Map,_windows=new Map,_broadcastNetwork=new Set,_channel=new BroadcastChannel(POSTAL_WORKER),_queue=[],_POboxes=new Map,_closures=new Map,_packages=new Map;
90
- // Define the PostalWorker
91
- class PostalWorker{/**
92
- * Initialize object with configuration & setup the worker and listeners
93
- * @param configuration
94
- * @param safeJsonStringify
95
- */
96
- constructor(e,s){this.uniqueNumber=0,this.id=this._uniqueNumber(),this.sharedWorkerSupported=!1,this.workerOnline=!1,_config=e||!1,_stringify=s,
97
- // Public API
98
- PostalHelper.rootMethods(this),PostalHelper.utilityMethods(this),
99
- // Attach global handlers
100
- PostalHelper.attachHandlers(this),
101
- // Does this window have a parent?
102
- window.self!==window.top&&(
103
- // If it does, include additional public methods and then register it
104
- // and let it know this window is ready to receive messages
105
- PostalHelper.backMethod(this),_parentWindow=this._getSubscriber(document.referrer),this._backFire(CHILDREGISTER)),
106
- // Add event listener to incoming messages (from windows) and process with messageController
107
- window.addEventListener(MESSAGE,this._messageController),
108
- // Subscribe to internal message classes
109
- PostalHelper.internalSubscriptions(this),
110
- // Resolve worker threading
111
- this._resolveWorker()}/**
112
- * Get root URL for subscriptions
113
- * (postMessage treats ALL urls the same off the same root)
114
- * @param url
115
- * @return {*}
116
- * @private
117
- */
118
- _getSubscriber(e){let s=e.split("://"),t=s[0];if(void 0!==s[1]){let e=s[1].split("/")[0];return t.concat("://").concat(e)}return e}/**
119
- * Resolve what type of worker threading is available
120
- * todo: this is very incomplete
121
- * at the moment it only sets up the sharedworker - which is the priority in all cases anyways
122
- * @private
123
- */
124
- _resolveWorker(){
125
- // Browser supports SharedWorker
126
- let e=!!window.SharedWorker;return e=Boolean(e),e?(this.sharedWorkerSupported=!0,_worker=this._polyfillSharedWorker()):(this.sharedWorkerSupported=!1,_worker=this._polyfillSharedWorker()),_worker}/**
127
- * Attempt to start SharedWorker thread or fail and return false
128
- * @return {SharedWorker | boolean}
129
- * @private
130
- */
131
- _startSharedWorker(){let e,s=this._getPostalRoute();try{e=new SharedWorker(s.concat("PostalSharedWorker").concat(".").concat(JS),{name:POSTAL_WORKER});/* !!! DEPRECATED messaging route !!! but leaving in place as fallback for older browsers */
132
- // this stuff is no longer tested and does not work
133
- // (no more messaging, only the connection is being established here)
134
- // but leaving it in to polyfill older browsers potentially
135
- let t=_stringify({postal:!0,type:RESPONSE,id:this.id,status:!0});Deprecated.registerWorker(e,t,_events,this),/* !!! PRIMARY messaging - This should always be used first */
136
- _channel.onmessage=(e=>{
137
- // Handle messages sent from worker by type
138
- const s=JSON.parse(e.data);if(!0!==s.postal)return;// Not a postalWorker message
139
- switch(s.type){case WORKERREGISTER:if(
140
- // worker startup
141
- this.workerOnline=!0,this._mapToBroadcastNetwork(this.id),_queue.length){const e=()=>_queue.length;for(;e();)_queue.shift()()}break;case FIRE:s.data.msgClass&&_events.get(s.data.msgClass)&&_events.get(s.data.msgClass)(s.data.message);break;case ERROR:console.error(s.data)}})}catch(e){
142
- // todo: Add intelligent error handling, including destination options
143
- window.console.warn("PostalWorker - Unable to start SharedWorker"),window.console.debug(e)}return e||!1}/**
144
- * Start a basic web worker (not available at this time)
145
- * @private
146
- */
147
- _polyfillSharedWorker(){let e,s=this._getPostalRoute();try{e=new Worker(s.concat("PolyfillSharedWorker").concat(".").concat(JS),{name:POSTAL_WORKER}),console.info(e),
148
- // /* !!! DEPRECATED messaging route !!! but leaving in place as fallback for older browsers */
149
- // // this stuff is no longer tested and does not work
150
- // // (no more messaging, only the connection is being established here)
151
- // // but leaving it in to polyfill older browsers potentially
152
- // let OK = _stringify({
153
- // postal: true,
154
- // type: S.RESPONSE,
155
- // id: this.id,
156
- // status: true
157
- // });
158
- // Deprecated.registerWorker(worker, OK, _events, this);
159
- // /* !!! PRIMARY messaging - This should always be used first */
160
- _channel.onmessage=(e=>{
161
- // Handle messages sent from worker by type
162
- const s=JSON.parse(e.data);if(!0!==s.postal)return;// Not a postalWorker message
163
- switch(s.type){case WORKERREGISTER:if(
164
- // worker startup
165
- this.workerOnline=!0,this._mapToBroadcastNetwork(this.id),_queue.length){const e=()=>_queue.length;for(;e();)_queue.shift()()}break;case FIRE:s.data.msgClass&&_events.get(s.data.msgClass)&&_events.get(s.data.msgClass)(s.data.message);break;case ERROR:console.error(s.data)}})}catch(e){
166
- // todo: Add intelligent error handling, including destination options
167
- window.console.warn("PostalWorker - Unable to start SharedWorker"),window.console.debug(e)}return e||!1}/**
168
- * Resolve route to use to find the sharedworker file
169
- * Priority is:
170
- * 1. Configuration passed to library
171
- * 2. Find any script tag in document which is called PostalWorker and then see if PostalRoute is defined in the querystring
172
- * 3. Assume the file is adjacent to where this script is being run from
173
- * @return {String}
174
- * @private
175
- */
176
- _getPostalRoute(){let e=Array.from(document.querySelectorAll(SCRIPT)).filter(e=>e.src?e.src.match(POSTAL_WORKER):[]).filter(e=>null!==e);if(
177
- // What about if more than one postalworker is found?
178
- // This should be pointed out...
179
- e.length>1&&window.console.warn('PostalWorker - Discovered more than 1 script tag matching "PostalWorker"'),_config.PostalRoute)return _config.PostalRoute;if(e[0]&&e[0].src&&e[0].src.match("PostalRoute")){let s=e[0].src.match(/PostalRoute=.*&/)?e[0].src.match(/PostalRoute=.*&/)[0].replace("&",""):e[0].src.match(/PostalRoute=.*$/)[0];return s.match("PostalRoute=.*$")[0].replace("PostalRoute=","")}
180
- // Otherwise, look next to where the PostalWorker script is located
181
- return 1===e.length?e[0].src.replace(/PostalWorker\.min\.js.*$/,"").replace(/PostalWorker\.js.*$/,""):""}/**
182
- * Process window messaging events "data" by "type"
183
- * @param e { data: JSON{ id: number, msgClass: string, message: any }, id: number, origin: string, source: port }
184
- * @private
185
- */
186
- _messageController(e){if(!(!e.data||e.data.match&&e.data.match("webpack")||e.data.type&&e.data.type.match("webpack")||e.data.source&&e.data.source.match("react"))){let s=JSON.parse(e.data);if(s.postal&&!0===s.postal)// Not a postalWorker message
187
- // console.info(msg);
188
- switch(s.type){case CROSSFIRE:
189
- // Is this a parent we don't yet know about?
190
- _windows.has(s.id)||_windows.set(s.id,{win:e.source,subscriber:e.origin}),
191
- // Is this window known by the module? If not, add it to the registry
192
- _windows.has(s.id)||(_windows.set(s.id,{win:e.source,subscriber:e.origin}),_subscriptions.add(e.origin)),
193
- // Is this a cross event?
194
- _crossEvents.has(s.data.msgClass)&&
195
- // If so, invoke registered callback against message
196
- _crossEvents.get(s.data.msgClass)(s.data.message);break;case BACKFIRE:
197
- // Children register themselves with the parent
198
- s.data.msgClass===CHILDREGISTER?_windows.has(s.data.id)?(
199
- // When a duplicate attempts to register, delete the previous resource
200
- // This accounts for iframe reloading
201
- _windows.delete(s.id),// _windows.delete(e.source);
202
- _windows.set(s.id,{win:e.origin,subscriber:e.origin})):(
203
- // if (!_windows.has(e.source)) {
204
- _windows.set(s.id,{win:e.source,subscriber:e.origin}),//_windows.set(e.source, e.origin);
205
- _subscriptions.add(e.origin)):_crossEvents.has(s.data.msgClass)&&
206
- // Invoke registered callback
207
- _crossEvents.get(s.data.msgClass)(s.data.message);break;case ERROR:window.console.error(s.data.message);break;default:window.console.error("PostalWorker - Unexpected message event"),window.console.debug({type:"_messageController",event:e})}}}/**
208
- * Register for events
209
- * @param msgClass
210
- * @param action
211
- * @return {PostalWorker}
212
- */
213
- _on(e,s){if(e&&s){
214
- // Send message to worker thread
215
- let t=_stringify({postal:!0,type:ON,id:this.id,data:{msgClass:e,action:s}});
216
- // Update registry
217
- return _worker?_channel.postMessage(t):_queue.push(()=>_channel.postMessage(t)),_events.set(e,s),this}}/**
218
- * Unregister event
219
- * @param msgClass
220
- * @return {Boolean}
221
- */
222
- _un(e){try{
223
- // Send message to worker thread
224
- let s=_stringify({postal:!0,type:UN,id:this.id,data:e});_worker?_channel.postMessage(s):_queue.push(()=>_channel.postMessage(s)),
225
- // Update registry
226
- _events.delete(e)}catch(e){return window.console.error(e),!1}return!0}/**
227
- * Fire event
228
- * @param msgClass
229
- * @param msg
230
- * @param audience - not being used currently
231
- * @return {PostalWorker}
232
- */
233
- _fire(e,s,t){let n=_stringify({postal:!0,type:FIRE,id:this.id,data:{msgClass:e,message:s,audience:t}});return this.workerOnline&&_worker?_channel.postMessage(n):_queue.push(()=>_channel.postMessage(n)),!0}/**
234
- * Register for cross launched windows or iframes messages
235
- * @param msgClass {string}
236
- * @param action {function}
237
- * @param subscriber {string}
238
- * @param name {string}
239
- * @param windowparams {WindowParameters}
240
- * @return {PostalWorker}
241
- */
242
- _crossOn(e,s,t,n,o){let r,i,a="",c="";if(t){
243
- // It also cannot be the parent window as that is already taken
244
- if(
245
- // postMessage only needs the root protocol+domain to send messages
246
- r=this._getSubscriber(t),_parentWindow&&r!==_parentWindow)return window.console.warn("PostalWorker - Unable to crossOn parentWindow"),this;if(
247
- // Register subscription
248
- !1===_subscriptions.has(r)&&
249
- // If subscriber doesn't exist
250
- _subscriptions.add(r),
251
- // Open window for subscription
252
- i=n||_BLANK,o){for(const e of Object.entries(o))c=c.concat(`${a} ${e[0]}=${e[1]}`),""===a&&(a=",");
253
- // Open window (with extra params)
254
- // debug: console.info(`window.open(${subscriber}, ${winName}, ${params})`);
255
- // _windows.set(window.open(subscriber, winName, params), rootSubscriber);
256
- _openingWindows.set(r,window.open(t,i,c))}else
257
- // Open window (basic)
258
- // _windows.set(window.open(subscriber, winName), rootSubscriber);
259
- _openingWindows.set(r,window.open(t,i));
260
- // Register associated action in registry
261
- _crossEvents.set(e,s)}else
262
- // No subscriber means to ONLY listen but not to open the window reference
263
- _crossEvents.set(e,s);return this}/**
264
- * Unregister cross launch/iframes
265
- * @param msgClass
266
- * @param subscriber
267
- * @return {PostalWorker}
268
- */
269
- _unCross(e,s){// todo: this should check if any other subscribers are using it...
270
- if(
271
- // Remove from cross events registry
272
- _crossEvents.delete(e),s){
273
- // Get root subscriber
274
- let e=this._getSubscriber(s);
275
- // Remove from subscriptions
276
- _subscriptions.delete(e);
277
- // If a reference to a window exists
278
- let t=[];for(let[e,n]of _windows)n.subscriber===this._getSubscriber(s)&&(n.win.close(),t.push(e));t.forEach(e=>{_windows.delete(e)})}return this}/**
279
- * Broadcast/fire across the windows/frames
280
- * @param msgClass
281
- * @param msg
282
- * @return {PostalWorker}
283
- */
284
- _crossFire(e,s){let t=_stringify({postal:!0,type:CROSSFIRE,id:this.id,data:{msgClass:e,message:s}});if(0===_windows.size&&window.opener&&window.opener.postMessage(t,"*"),
285
- // Parent window is part of the crossFire group
286
- _parentWindow&&window.top.postMessage(t,_parentWindow),_windows.size>0)for(let[,e]of _windows)e.win.postMessage(t,e.subscriber);return this}/**
287
- * Fire to all the things!
288
- * @param msgClass
289
- * @param msg
290
- * @return {PostalWorker}
291
- */
292
- _fireAll(e,s){return this._fire(e,s),this._crossFire(e,s),this}/**
293
- * Special fire type that is specifically from child to parent window
294
- * @param msgClass
295
- * @param msg
296
- * @return {PostalWorker}
297
- */
298
- _backFire(e,s){if(_parentWindow&&e){let t=_stringify({postal:!0,type:BACKFIRE,id:this.id,data:{msgClass:e,message:s}});try{window.top.postMessage(t,_parentWindow)}catch(e){window.console.warn("PostalWorker - Unable to backFire"),window.console.debug({msg:t,parentWindow:_parentWindow,error:e})}}return this}/**
299
- * Load JavaScript library into worker thread
300
- * todo: @Russ - support for multiple threads...
301
- * @param library
302
- */
303
- _load(e){const s=_stringify({postal:!0,type:LOAD,id:this.id,data:e});this.workerOnline?_worker?
304
- // Otherwise, send the message to load the library
305
- _channel.postMessage(s):_queue.push(()=>_channel.postMessage(s)):
306
- // If the worker has not completed startup yet, queue the message
307
- _queue.push(()=>{_channel.postMessage(s)})}/**
308
- *
309
- * @returns
310
- */
311
- _getOpeningWindows(){return _openingWindows}/**
312
- * Get current window references registered with postal system
313
- * @return {Map<any, any>}
314
- */
315
- _getWindows(){return _windows}/**
316
- *
317
- * @return {Map<any, any>}
318
- */
319
- _getCrossEvents(){return _crossEvents}/**
320
- *
321
- * @return {Set<any>}
322
- */
323
- _getSubscriptions(){return _subscriptions}/**
324
- * @param subscriber
325
- * @return {boolean | Array}
326
- */
327
- _getWindowsBySubscriber(e){let s=[];for(let[,t]of _windows)e===t.subscriber&&s.push(t);return s}/**
328
- *
329
- * @return {Map<any, any>}
330
- */
331
- _getEvents(){return _events}/**
332
- * Generate unique number using timestamp + incrementing number
333
- * @returns number
334
- */
335
- _uniqueNumber(){let e=Date.now();return e<=this._uniqueNumber.previous?e=++this._uniqueNumber.previous:this._uniqueNumber.previous=e,e}/**
336
- * Map window being opened to the window instance which is confirmed by first message
337
- * @param {number} id
338
- * @param {*} win
339
- * @param {string} subscriber
340
- */
341
- _mapToWindow(e,s,t){_windows.set(e,{win:s,subscriber:t}),_channel.postMessage(_stringify({postal:!0,type:REGISTERID,id:e,nodeType:CROSSNODE}))}/**
342
- *
343
- * @param {number} id
344
- */
345
- _unmapFromWindow(e){_windows.delete(e),_channel.postMessage(_stringify({postal:!0,type:UNREGISTERID,id:e}))}/**
346
- *
347
- * @param {number} id
348
- */
349
- _mapToBroadcastNetwork(e){_broadcastNetwork.add(e),_channel.postMessage(_stringify({postal:!0,type:REGISTERID,id:e,nodeType:BROADCASTNODE}))}/**
350
- *
351
- * @param {number} id
352
- */
353
- _unmapFromBroadcastNetwork(e){_broadcastNetwork.delete(e),_channel.postMessage(_stringify({postal:!0,type:UNREGISTERID,id:e}))}/**
354
- *
355
- * @param {*} address
356
- * @param {Function} handler - { update, box }
357
- */
358
- _postBox(e,s){const t=_stringify({postal:!0,type:POBOX,id:this.id,address:e});this.workerOnline?_worker&&_channel.postMessage(t):_queue.push(()=>_channel.postMessage(t)),_POboxes.size||PostalHelper.registerCollection(this),_POboxes.get(e)||_POboxes.set(e,s)}/**
359
- *
360
- * @param {*} address
361
- */
362
- _closeBox(e){const s=_POboxes.get(e);PostalHelper.registerClosure(this,e,s),_POboxes.delete(e),_channel.postMessage(_stringify({postal:!0,type:CLOSEBOX,id:this.id,address:e}))}
363
- // _getPostBoxes() {
364
- // return _POboxes;
365
- // }
366
- /**
367
- *
368
- * @param {*} address
369
- * @param {*} value
370
- */
371
- _post(e,s){const t=_stringify({postal:!0,type:POST,id:this.id,address:e,value:s});this.workerOnline&&_worker?_channel.postMessage(t):_queue.push(()=>_channel.postMessage(t))}/**
372
- *
373
- * @param {*} drop
374
- */
375
- _collectBox(e){const{address:address,value:value,box:box}=e;let s=_POboxes.get(address);s&&s({address:address,value:value,box:box})}/**
376
- *
377
- * @param {*} address
378
- * @param {*} collect
379
- */
380
- _lastCollection(e,s){_closures.set(e,s)}/**
381
- *
382
- * @param {*} msg
383
- */
384
- _clearBox(e){const{id:id,address:address,box:box}=e;if(id===this.id){if(_closures.get(address)){_closures.get(address)({address:address,value:null,box:box}),_closures.delete(address)}_POboxes.delete(address),_closures.size||_POboxes.size||PostalHelper.unregisterCollection(this)}}/**
385
- *
386
- * @param {*} address
387
- * @param {*} content
388
- * @param {*} handling
389
- */
390
- _package(e,s){const t=_stringify({postal:!0,type:PACKAGE,id:this.id,address:e});this.workerOnline?_worker&&_channel.postMessage(t):_queue.push(()=>_channel.postMessage(t)),_packages.size||PostalHelper.registerDelivery(this),_packages.get(e)||_packages.set(e,s)}/**
391
- *
392
- * @param {*} address
393
- * @param {*} content
394
- */
395
- _pack(e,s){let t=new XMLHttpRequest,n=this;t.onload=function(){let s=new FileReader;s.onloadend=function(){const t=_stringify({postal:!0,type:PACK,id:n.id,address:e,content:s.result});n.workerOnline?_worker&&_channel.postMessage(t):_queue.push(()=>{_channel.postMessage(t)})},s.readAsDataURL(t.response)},t.open("GET",s),t.responseType="blob",t.send()}/**
396
- *
397
- * @param {*} msg
398
- */
399
- _delivery(e){const{address:address,content:content}=e;let s=_packages.get(address);s&&s({address:address,content:content})}}var hasProp=Object.prototype.hasOwnProperty,index=function(e,s,t){return JSON.stringify(ensureProperties(e),s,t)},ensureProperties_1=ensureProperties;index.ensureProperties=ensureProperties_1;/**
400
- * PostalWorker Main Source (ES6 Version - Exports )
401
- * Build ES6 module version
402
- * @Author: Russ Stratfull - 2018
403
- */
404
- let _PostalWorker;export default main;