@lmjs/core 1.0.6 → 2.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.
- package/build/bundle.js +264 -0
- package/build/plugins-registry.js +216 -0
- package/dist/lumenjs-core-with-plugins.js +59258 -0
- package/dist/lumenjs-core.js +50 -0
- package/dist/lumenjs-plugins.css +2822 -0
- package/package.json +59 -28
- package/src/_re.js +2307 -0
- package/src/dom-shim.js +473 -0
- package/src/index-bootstrap.js +47 -0
- package/src/lstnrs.js +1391 -0
- package/src/walk.js +749 -0
- package/src/workers/css.js +1 -0
- package/src/workers/cssRaw.js +1173 -0
- package/src/workers/esp.js +1 -0
- package/src/workers/espRaw.js +78 -0
- package/src/workers/up.js +1 -0
- package/src/workers/upRaw.js +491 -0
- package/src/workers/work.js +1 -0
- package/src/workers/workRaw.js +1097 -0
- package/src/ws.js +1162 -0
- package/vendor/astring.js +3 -0
- package/vendor/bootstrap2-less-stubs/mixins.less +16 -0
- package/vendor/bootstrap2-less-stubs/variables.less +13 -0
- package/vendor/md5.js +1 -0
- package/vendor/reconnecting-websocket.js +4118 -0
- package/vendor/webworker-helper.js +1 -0
- package/LICENSE +0 -201
- package/README.md +0 -3
- package/index.js +0 -14
|
@@ -0,0 +1 @@
|
|
|
1
|
+
let _w=self;function defer(){var r,e,n=new Promise(((n,t)=>{r=n,e=t}));return n.resolve=r,n.reject=e,n.success=r,n.failed=e,n}function findDeclarations(r,e){var n,t,a=e?r:esprima.parseScript(r),i=[],c=[],s=[];return n=function(r){if("FunctionDeclaration"===r.type){var e={name:r.id.name,params:r.params.map((function(r){return r.name})),variables:[]};i.push(e),s.push(e)}if("VariableDeclaration"===r.type){var n=r.declarations.map((function(e){return{kind:r.kind,name:e.id.name}}));if(0===s.length)c=c.concat(n);else{var t=s[s.length-1];t.variables=t.variables.concat(n)}}},t=function(r){"FunctionDeclaration"===r.type&&s.pop()},function r(e){n(e);for(var a=Object.keys(e).filter((function(r){var n=e[r];if(null===n)return!1;if("object"!=typeof n)return!1;if(n.constructor===Array)return"range"!==r;if("loc"===r)return!1;if("type"in n){if(n.type in esprima.Syntax)return!0;throw new Error("unexpected")}return!1})),i=0;i<a.length;i++){var c=a[i];r(e[c])}t(e)}(a),{vars:c,funcs:i}}!function(){"use strict";importScripts("https://cdn.jsdelivr.net/npm/esprima@4.0.1/dist/esprima.min.js"),_w.on("msg",(function(r){var e=r.data.code;const n=esprima.parseScript(e);_w.trigger("msg",{i:r.data.i,code:n,declarations:findDeclarations(n,!0)})}))}();
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
let _w=self;
|
|
2
|
+
function defer(){var e,t,s=new Promise(((s,r)=>{e=s,t=r}));return s.resolve=e,s.reject=t,s.success=e,s.failed=t,s}
|
|
3
|
+
function findDeclarations(code, parsed){
|
|
4
|
+
var ast = parsed ? code : esprima.parseScript(code);
|
|
5
|
+
var funcDecls = [];
|
|
6
|
+
var globalVarDecls = [];
|
|
7
|
+
var funcStack = [];
|
|
8
|
+
function visitEachAstNode(root, enter, leave){
|
|
9
|
+
function visit(node){
|
|
10
|
+
function isSubNode(key){
|
|
11
|
+
var child = node[key];
|
|
12
|
+
if (child===null) return false;
|
|
13
|
+
var ty = typeof child;
|
|
14
|
+
if (ty!=='object') return false;
|
|
15
|
+
if (child.constructor===Array) return ( key!=='range' );
|
|
16
|
+
if (key==='loc') return false;
|
|
17
|
+
if ('type' in child){
|
|
18
|
+
if (child.type in esprima.Syntax) return true;
|
|
19
|
+
debugger; throw new Error('unexpected');
|
|
20
|
+
} else { return false; }
|
|
21
|
+
}
|
|
22
|
+
enter(node);
|
|
23
|
+
var keys = Object.keys(node);
|
|
24
|
+
var subNodeKeys = keys.filter(isSubNode);
|
|
25
|
+
for (var i=0; i<subNodeKeys.length; i++){
|
|
26
|
+
var key = subNodeKeys[i];
|
|
27
|
+
visit(node[key]);
|
|
28
|
+
}
|
|
29
|
+
leave(node);
|
|
30
|
+
}
|
|
31
|
+
visit(root);
|
|
32
|
+
}
|
|
33
|
+
function myEnter(node){
|
|
34
|
+
if (node.type==='FunctionDeclaration') {
|
|
35
|
+
var current = {
|
|
36
|
+
name : node.id.name,
|
|
37
|
+
params : node.params.map(function(p){return p.name;}),
|
|
38
|
+
variables : []
|
|
39
|
+
}
|
|
40
|
+
funcDecls.push(current);
|
|
41
|
+
funcStack.push(current);
|
|
42
|
+
}
|
|
43
|
+
if (node.type==='VariableDeclaration'){
|
|
44
|
+
var foundVarNames = node.declarations.map(function(d){ return {kind: node.kind,name: d.id.name}; });
|
|
45
|
+
if (funcStack.length===0){
|
|
46
|
+
globalVarDecls = globalVarDecls.concat(foundVarNames);
|
|
47
|
+
} else {
|
|
48
|
+
var onTopOfStack = funcStack[funcStack.length-1];
|
|
49
|
+
onTopOfStack.variables = onTopOfStack.variables.concat(foundVarNames);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function myLeave(node){
|
|
54
|
+
if (node.type==='FunctionDeclaration') {
|
|
55
|
+
funcStack.pop();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
visitEachAstNode(ast, myEnter, myLeave);
|
|
59
|
+
return {
|
|
60
|
+
vars : globalVarDecls,
|
|
61
|
+
funcs : funcDecls
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
(function () {
|
|
66
|
+
'use strict';
|
|
67
|
+
importScripts('https://cdn.jsdelivr.net/npm/esprima@4.0.1/dist/esprima.min.js');
|
|
68
|
+
_w.on('msg', function (e) {
|
|
69
|
+
var code = e.data.code;
|
|
70
|
+
const result = esprima.parseScript(code);
|
|
71
|
+
_w.trigger('msg', {
|
|
72
|
+
"i":e.data.i,
|
|
73
|
+
"code": result,
|
|
74
|
+
"declarations": findDeclarations(result, true)
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
return;
|
|
78
|
+
})();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
let _w=self;var files=[];function defer(){var e,t,s=new Promise(((s,r)=>{e=s,t=r}));return s.resolve=e,s.reject=t,s.success=e,s.failed=t,s}class _Live{_chnls={};_users={};_iter=0;reconnectAttempts=0;timeoutInterval=4e3;cbs={};_cbs={};lstnrs={};_ws;srvr=void 0;constructor(e,t){return this.srvr=e,this.init(t),this}on(e,t){return this.lstnrs.hasOwnProperty(e)||(this.lstnrs[e]=[]),this.lstnrs[e].push(t),"open"==e&&1==this._ws?.readyState&&this.trigger("open",this._ws),this}off(e){return"connect"==e||this.lstnrs.hasOwnProperty(e)&&delete this.lstnrs[e],this}createUser(e){return new _User(e,this)}subscribe(e,t){return this.on(e,t)}unsubscribe(e,t){return this.off(e,t)}trigger(e,t){if(this.lstnrs.hasOwnProperty(e))for(let s=0;s<this.lstnrs[e].length;s++)this.lstnrs[e][s](t);return this}emit(e,t,s){try{this._iter++,s&&(this.cbs["cb_"+this._iter]=s),this.ready()?this._ws.send(JSON.stringify({e:e,payload:t,_iter:this._iter})):this._send(JSON.stringify({e:e,payload:t,_iter:this._iter}))}catch(e){_debugMode&&cl(e)}return this}_emit(e,t,s){this._iter++;let r=defer();return this._cbs["cb_"+this._iter]=r,s?this.ready()?(this._ws.binaryType="arraybuffer",this._ws.send(this._binData({e:e,payloadBin:t,_iter:this._iter})),this._ws.binaryType="blob"):this._send(this._binData({e:e,payloadBin:t,_iter:this._iter})):this.ready()?this._ws.send(JSON.stringify({e:e,payload:t,_iter:this._iter})):this._send(JSON.stringify({e:e,payload:t,_iter:this._iter})),r}_send(e){let t=this;setTimeout((function(){t.ready()?t._ws.send(e):t._send(e)}),500)}ready(){return void 0!==this._ws&&this._ws.readyState==WebSocket.OPEN}connecting(){return void 0!==this._ws&&this._ws.readyState==WebSocket.CONNECTING}init(e){var t=this;if(t.ready())e&&"STARTED"==e.status&&upload(e);else if(t.connecting())setTimeout((function(){t.ready()?e&&"STARTED"==e.status&&upload(e):t.init(e)}),500);else{this._ws=new WebSocket(this.srvr?this.srvr:"wss://www.beaapis.com/");var s=this._ws,r=setTimeout((function(){1!=s.readyState&&s.close()}),this.timeoutInterval);this._ws.onopen=function(s){e&&"STARTED"==e.status&&upload(e),clearTimeout(r),t.trigger("connect",s),t.trigger("open",s)},this._ws.onclose=function(s){clearTimeout(r),t._ws=void 0,t._iter=0,t.cbs={},setTimeout((function(){t.reconnectAttempts++,t.init(e)}),1e3)},this._ws.onmessage=function(e){try{let s=JSON.parse(e.data);if(s.hasOwnProperty("for")){let e=s.type??"room",r=s.ev??"message";const i=new CustomEvent(r,{detail:s.payload});i.data=s.payload;let n=s.payload;n.hasOwnProperty("user")&&("user"==e?t._users[s.for].trigger(r,i):t._chnls[n.user.id][s.for].trigger(r,i))}else if(s.hasOwnProperty("e")){let e=s.e,r=s._iter;const i=new CustomEvent(e,{detail:s.payload});i.data=s.payload,"rooms"!=e&&t.trigger(e,i),t.cbs["cb_"+r]&&t.cbs["cb_"+r](i),t._cbs["cb_"+r].resolve(i)}}catch(e){}},this._ws.onerror=function(e){t._ws&&t._ws.close()}}}_binData(e){var t=e.payloadBin,s=t.chunk;delete t.chunk;const r=JSON.stringify({payload:t,e:e.e,_iter:e._iter}),i=new TextEncoder,n=i.encode("!"),a=i.encode(r),o=i.encode("_B_:_E_:_A_"),u=s;let l=new Uint8Array(n.byteLength+a.byteLength+o.byteLength+u.byteLength);return l.set(new Uint8Array(n),0),l.set(new Uint8Array(a),n.byteLength),l.set(new Uint8Array(o),n.byteLength+a.byteLength),l.set(new Uint8Array(u),n.byteLength+a.byteLength+o.byteLength),l}}var LIVE=new _Live("wss://www.beaapis.com/");function openSocket(e){LIVE.init(e)}function readFileAsync(e){return new Promise(((t,s)=>{let r=new FileReader;r.onload=e=>{let s=new ArrayBuffer;s=e.target.result,t(s)},r.onerror=s,r.readAsArrayBuffer(e)}))}var _queue={};function fid(){return"file_"+Date.now().toString(36)+Math.floor(Math.pow(10,12)+9*Math.random()*Math.pow(10,12)).toString(36)}const wait=e=>new Promise(((t,s)=>{setTimeout(t,e)}));async function upload(e){if(e&&"STARTED"!=e.status)return;const t=Math.ceil(256000);for(var s=0;s<Object.keys(e.files).length;s++){let l=Object.keys(e.files)[s],d=Object.values(e.files)[s];if(e&&"STOPPED"==e.status)return;if("DONE"==d.status)continue;let c=e.blobs[l],h=e.data[l],f=c.size;var r=0,i=t,n=Math.ceil(f/t),a={cmd:1,name:c.name,id:l,chunks:n};await LIVE._emit("upload",a);let p=1;for(h.part>1&&(p=h.part?h.part:1,i=(r=(p-1)*t)+t);r<f;){if(e&&"STOPPED"==e.status)return;if(!e.files.hasOwnProperty(l))return;if("mozSlice"in c)var o=c.mozSlice(r,i);else if("slice"in c)o=c.slice(r,i);else o=c.webkitSlice(r,i);var u=await readFileAsync(o);a={cmd:2,name:c.name,part:p,chunks:n,id:l,chunk:u};h.chunks=n,h.part=p+1,d.status="UPLOADING",d.loaded=d.loaded+o.size,d.percent=Math.ceil(100*p/n),d.loaded>d.size&&(d.loaded=d.size),d.percent>100&&(d.percent=100);let s=await LIVE._emit("upload",a,!0);s?.data?.url&&(d.url=s?.data?.url),_w.trigger("upload-progress",{upid:d.upid,files:e.files}),i=(r=i)+t,p++}d.status="DONE",_w.trigger("file-uploaded",{upid:d.upid,files:e.files,file:d})}e.status="DONE",_w.trigger("upload-complete",{upid:e.upid,files:e.files})}function process(e){var t=e.upid,s=e.files;_queue.hasOwnProperty(t)||(_queue[t]={status:"QUEUED",upid:t,files:{},blobs:{},data:{}});for(var r=_queue[t],i=[],n={},a={},o=0;o<s.length;o++)i.push(s[o]);for(;i.length>0;){var u=i.shift(),l=fid();n[l]={id:l,upid:t,name:u.name,type:u.type,size:u.size,loaded:0,percent:0,status:"QUEUED",lastModifiedDate:u.lastModifiedDate?u.lastModifiedDate.toLocaleDateString():"n/a"},a[l]={id:l,upid:t,chunks:1,part:1},r.files={...r.files,...n},r.data={...r.data,...a},r.blobs[l]=u,_w.trigger("queue-changed",{upid:t,files:r.files})}_w.trigger("files-added",{upid:t,files:r.files,newfiles:n})}!function(){"use strict";_w.on("handle-files",(function(e){process(e.data)})),_w.on("start-upload",(function(e){var t=e.data.upid,s=_queue[t];s?"STARTED"!=s.status?(s.status="STARTED",LIVE.ready()?upload(s):openSocket(s)):_w.trigger("message","Already Started!"):_w.trigger("queue-empty",{upid:t})})),_w.on("stop-upload",(function(e){var t=e.data.upid,s=_queue[t];s?(s.status="STOPPED",_w.trigger("upload-stop",{upid:t,files:s})):_w.trigger("queue-empty",{upid:t})})),_w.on("remove-file",(function(e){var t=e.data.upid,s=_queue[t],r=e.data.id;if(s.files?.hasOwnProperty(r)){var i=s.files[r];delete s.files[r],_w.trigger("file-removed",{upid:t,files:s.files,removedfile:i}),_w.trigger("queue-changed",{upid:t,files:s.files}),0==Object.keys(s.files).length&&(delete _queue[t],_w.trigger("queue-empty",{upid:t}))}}))}();
|
|
@@ -0,0 +1,491 @@
|
|
|
1
|
+
let _w = self;
|
|
2
|
+
var files = [];
|
|
3
|
+
function defer() {
|
|
4
|
+
var res, rej;
|
|
5
|
+
var promise = new Promise((resolve, reject) => {
|
|
6
|
+
res = resolve;
|
|
7
|
+
rej = reject;
|
|
8
|
+
});
|
|
9
|
+
promise.resolve = res;
|
|
10
|
+
promise.reject = rej;
|
|
11
|
+
promise.success = res;
|
|
12
|
+
promise.failed = rej;
|
|
13
|
+
return promise;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
class _Live {
|
|
17
|
+
_chnls = {};
|
|
18
|
+
_users = {};
|
|
19
|
+
_iter = 0;
|
|
20
|
+
reconnectAttempts = 0;
|
|
21
|
+
timeoutInterval = 4000;
|
|
22
|
+
cbs = {};
|
|
23
|
+
_cbs = {};
|
|
24
|
+
lstnrs = {};
|
|
25
|
+
_ws;
|
|
26
|
+
srvr = undefined;
|
|
27
|
+
|
|
28
|
+
constructor(srvr, que) {
|
|
29
|
+
this.srvr = srvr;
|
|
30
|
+
|
|
31
|
+
this.init(que);
|
|
32
|
+
return this;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
on(e, cb) {
|
|
36
|
+
if (!this.lstnrs.hasOwnProperty(e)) this.lstnrs[e] = [];
|
|
37
|
+
this.lstnrs[e].push(cb);
|
|
38
|
+
if (e == "open" && this._ws?.readyState == 1) {
|
|
39
|
+
this.trigger("open", this._ws);
|
|
40
|
+
}
|
|
41
|
+
return this;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
off(e) {
|
|
45
|
+
if (e == "connect") return this;
|
|
46
|
+
if (this.lstnrs.hasOwnProperty(e)) delete this.lstnrs[e];
|
|
47
|
+
return this;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
createUser(id) {
|
|
51
|
+
let user = new _User(id, this);
|
|
52
|
+
return user;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
subscribe(e, cb) {
|
|
56
|
+
return this.on(e, cb);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
unsubscribe(e, cb) {
|
|
60
|
+
return this.off(e, cb);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
trigger(n, e) {
|
|
64
|
+
if (this.lstnrs.hasOwnProperty(n)) {
|
|
65
|
+
for (let x = 0; x < this.lstnrs[n].length; x++) {
|
|
66
|
+
this.lstnrs[n][x](e);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return this;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
emit(e, data, cb) {
|
|
73
|
+
try {
|
|
74
|
+
this._iter++;
|
|
75
|
+
if (cb) this.cbs["cb_" + this._iter] = cb;
|
|
76
|
+
if (this.ready()) {
|
|
77
|
+
this._ws.send(JSON.stringify({ e: e, payload: data, _iter: this._iter }));
|
|
78
|
+
} else {
|
|
79
|
+
this._send(JSON.stringify({ e: e, payload: data, _iter: this._iter }));
|
|
80
|
+
}
|
|
81
|
+
} catch (error) {
|
|
82
|
+
if (_debugMode) cl(error);
|
|
83
|
+
}
|
|
84
|
+
return this;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
_emit(e, data, _isBin) {
|
|
88
|
+
this._iter++;
|
|
89
|
+
let prom = defer();
|
|
90
|
+
this._cbs["cb_" + this._iter] = prom;
|
|
91
|
+
if (_isBin) {
|
|
92
|
+
if (this.ready()) {
|
|
93
|
+
this._ws.binaryType = "arraybuffer";
|
|
94
|
+
this._ws.send(this._binData({ e: e, payloadBin: data, _iter: this._iter }));
|
|
95
|
+
this._ws.binaryType = "blob";
|
|
96
|
+
} else {
|
|
97
|
+
this._send(this._binData({ e: e, payloadBin: data, _iter: this._iter }));
|
|
98
|
+
}
|
|
99
|
+
} else {
|
|
100
|
+
if (this.ready()) {
|
|
101
|
+
this._ws.send(JSON.stringify({ e: e, payload: data, _iter: this._iter }));
|
|
102
|
+
} else {
|
|
103
|
+
this._send(JSON.stringify({ e: e, payload: data, _iter: this._iter }));
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return prom;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
_send(m) {
|
|
110
|
+
let _s = this;
|
|
111
|
+
setTimeout(function () {
|
|
112
|
+
if (_s.ready()) _s._ws.send(m);
|
|
113
|
+
else _s._send(m);
|
|
114
|
+
}, 500);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
ready() {
|
|
118
|
+
return this._ws !== undefined && this._ws.readyState == WebSocket.OPEN;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
connecting() {
|
|
122
|
+
return this._ws !== undefined && this._ws.readyState == WebSocket.CONNECTING;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
init(que) {
|
|
126
|
+
var _s = this;
|
|
127
|
+
|
|
128
|
+
if (_s.ready()) {
|
|
129
|
+
if (que && que['status'] == "STARTED") upload(que);
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
if (_s.connecting()) {
|
|
133
|
+
setTimeout(function () {
|
|
134
|
+
if (_s.ready()) { if (que && que['status'] == "STARTED") upload(que); }
|
|
135
|
+
else _s.init(que);
|
|
136
|
+
}, 500);
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
this._ws = new WebSocket(
|
|
141
|
+
this.srvr ? this.srvr : "wss://www.beaapis.com/"
|
|
142
|
+
);
|
|
143
|
+
|
|
144
|
+
var localws = this._ws;
|
|
145
|
+
var timeout = setTimeout(function () {
|
|
146
|
+
if (localws.readyState != 1) localws.close();
|
|
147
|
+
}, this.timeoutInterval);
|
|
148
|
+
|
|
149
|
+
this._ws.onopen = function (e) {
|
|
150
|
+
if (que && que['status'] == "STARTED") upload(que);
|
|
151
|
+
clearTimeout(timeout);
|
|
152
|
+
_s.trigger("connect", e);
|
|
153
|
+
_s.trigger("open", e);
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
this._ws.onclose = function (e) {
|
|
157
|
+
clearTimeout(timeout);
|
|
158
|
+
_s._ws = undefined;
|
|
159
|
+
_s._iter = 0;
|
|
160
|
+
_s.cbs = {};
|
|
161
|
+
|
|
162
|
+
setTimeout(function () {
|
|
163
|
+
_s.reconnectAttempts++;
|
|
164
|
+
_s.init(que);
|
|
165
|
+
}, 1000);
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
this._ws.onmessage = function (e) {
|
|
169
|
+
try {
|
|
170
|
+
let data = JSON.parse(e.data);
|
|
171
|
+
if (data.hasOwnProperty("for")) {
|
|
172
|
+
let t = data["type"] ?? "room";
|
|
173
|
+
let ev = data["ev"] ?? "message";
|
|
174
|
+
const customEvent = new CustomEvent(ev, {
|
|
175
|
+
detail: data["payload"],
|
|
176
|
+
});
|
|
177
|
+
customEvent.data = data["payload"];
|
|
178
|
+
let payload = data["payload"];
|
|
179
|
+
if (payload.hasOwnProperty("user")) {
|
|
180
|
+
if (t == "user") {
|
|
181
|
+
_s._users[data["for"]].trigger(ev, customEvent);
|
|
182
|
+
} else
|
|
183
|
+
_s._chnls[payload.user.id][data["for"]].trigger(
|
|
184
|
+
ev,
|
|
185
|
+
customEvent
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
} else if (data.hasOwnProperty("e")) {
|
|
189
|
+
let event = data["e"];
|
|
190
|
+
let iter = data["_iter"];
|
|
191
|
+
const customEvent = new CustomEvent(event, {
|
|
192
|
+
detail: data["payload"],
|
|
193
|
+
});
|
|
194
|
+
customEvent.data = data["payload"];
|
|
195
|
+
if (event != "rooms") _s.trigger(event, customEvent);
|
|
196
|
+
if (_s.cbs["cb_" + iter]) _s.cbs["cb_" + iter](customEvent);
|
|
197
|
+
_s._cbs["cb_" + iter].resolve(customEvent);
|
|
198
|
+
}
|
|
199
|
+
} catch (e) { }
|
|
200
|
+
};
|
|
201
|
+
this._ws.onerror = function (e) {
|
|
202
|
+
if (_s._ws) {
|
|
203
|
+
_s._ws.close();
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
_binData(_data) {
|
|
209
|
+
var data = _data.payloadBin;
|
|
210
|
+
var fileData = data.chunk;
|
|
211
|
+
delete data['chunk'];
|
|
212
|
+
|
|
213
|
+
const fileMetaJson = JSON.stringify({
|
|
214
|
+
payload: data,
|
|
215
|
+
e: _data.e,
|
|
216
|
+
_iter: _data._iter,
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
// _must_ do this to encode as a ArrayBuffer / Uint8Array
|
|
220
|
+
const enc = new TextEncoder(); // always utf-8, Uint8Array()
|
|
221
|
+
const buf1 = enc.encode("!");
|
|
222
|
+
const buf2 = enc.encode(fileMetaJson);
|
|
223
|
+
const buf3 = enc.encode("_B_:_E_:_A_");
|
|
224
|
+
const buf4 = fileData;
|
|
225
|
+
|
|
226
|
+
let sendData = new Uint8Array(
|
|
227
|
+
buf1.byteLength + buf2.byteLength + buf3.byteLength + buf4.byteLength
|
|
228
|
+
);
|
|
229
|
+
sendData.set(new Uint8Array(buf1), 0);
|
|
230
|
+
sendData.set(new Uint8Array(buf2), buf1.byteLength);
|
|
231
|
+
sendData.set(new Uint8Array(buf3), buf1.byteLength + buf2.byteLength);
|
|
232
|
+
sendData.set(
|
|
233
|
+
new Uint8Array(buf4),
|
|
234
|
+
buf1.byteLength + buf2.byteLength + buf3.byteLength
|
|
235
|
+
);
|
|
236
|
+
|
|
237
|
+
return sendData;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
var LIVE = new _Live("wss://www.beaapis.com/");
|
|
242
|
+
|
|
243
|
+
function openSocket(que) {
|
|
244
|
+
LIVE.init(que);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
function readFileAsync(file) {
|
|
248
|
+
return new Promise((resolve, reject) => {
|
|
249
|
+
let reader = new FileReader();
|
|
250
|
+
|
|
251
|
+
reader.onload = (e) => {
|
|
252
|
+
let rawData = new ArrayBuffer();
|
|
253
|
+
rawData = e.target.result;
|
|
254
|
+
resolve(rawData);
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
reader.onerror = reject;
|
|
258
|
+
reader.readAsArrayBuffer(file);
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
var _queue = {};
|
|
263
|
+
function fid() {
|
|
264
|
+
return 'file_' + Date.now().toString(36) + Math.floor(Math.pow(10, 12) + Math.random() * 9 * Math.pow(10, 12)).toString(36);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
const wait = (msec) => new Promise((resolve, _) => {
|
|
268
|
+
setTimeout(resolve, msec);
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
async function upload(que) {
|
|
272
|
+
|
|
273
|
+
if (que && que['status'] != "STARTED") {
|
|
274
|
+
// _w.trigger('message', "que stopped before upload start");
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
const BYTES_PER_CHUNK = Math.ceil(1024 * 1024 * 0.25);
|
|
278
|
+
|
|
279
|
+
for (var x = 0; x < Object.keys(que['files']).length; x++) {
|
|
280
|
+
let id = Object.keys(que['files'])[x];
|
|
281
|
+
let file = Object.values(que['files'])[x];
|
|
282
|
+
if (que && que['status'] == "STOPPED") {
|
|
283
|
+
// _w.trigger('message', "que stopped while uploading!");
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
if (file.status == "DONE") continue;
|
|
288
|
+
// else if(file.status=="UPLOADING") continue;
|
|
289
|
+
|
|
290
|
+
let blob = que['blobs'][id];
|
|
291
|
+
let _data = que['data'][id];
|
|
292
|
+
let SIZE = blob.size;
|
|
293
|
+
|
|
294
|
+
var start = 0;
|
|
295
|
+
var end = BYTES_PER_CHUNK;
|
|
296
|
+
var chunks = Math.ceil(SIZE / BYTES_PER_CHUNK);
|
|
297
|
+
var data = {
|
|
298
|
+
cmd: 1,
|
|
299
|
+
name: blob.name,
|
|
300
|
+
id: id,
|
|
301
|
+
chunks: chunks,
|
|
302
|
+
};
|
|
303
|
+
|
|
304
|
+
var _e = await LIVE._emit("upload", data);
|
|
305
|
+
|
|
306
|
+
let part = 1;
|
|
307
|
+
if (_data['part'] > 1) {
|
|
308
|
+
part = _data['part'] ? _data['part'] : 1;
|
|
309
|
+
start = (part - 1) * BYTES_PER_CHUNK;
|
|
310
|
+
end = start + BYTES_PER_CHUNK;
|
|
311
|
+
}
|
|
312
|
+
while (start < SIZE) {
|
|
313
|
+
if (que && que['status'] == "STOPPED") {
|
|
314
|
+
// _w.trigger('message', "que stopped while uploading inside!");
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
if (!que['files'].hasOwnProperty(id)) {
|
|
318
|
+
// _w.trigger('message', "file removed while uploading");
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
if ("mozSlice" in blob) {
|
|
322
|
+
var chunk = blob.mozSlice(start, end);
|
|
323
|
+
} else if ("slice" in blob) {
|
|
324
|
+
var chunk = blob.slice(start, end);
|
|
325
|
+
} else {
|
|
326
|
+
var chunk = blob.webkitSlice(start, end);
|
|
327
|
+
}
|
|
328
|
+
var text = await readFileAsync(chunk);
|
|
329
|
+
|
|
330
|
+
var data = {
|
|
331
|
+
cmd: 2,
|
|
332
|
+
name: blob.name,
|
|
333
|
+
part: part,
|
|
334
|
+
chunks: chunks,
|
|
335
|
+
id: id,
|
|
336
|
+
chunk: text
|
|
337
|
+
};
|
|
338
|
+
_data['chunks'] = chunks;
|
|
339
|
+
_data['part'] = part + 1;
|
|
340
|
+
file['status'] = "UPLOADING";
|
|
341
|
+
file['loaded'] = file['loaded'] + chunk.size;
|
|
342
|
+
file['percent'] = Math.ceil(part * 100 / chunks);
|
|
343
|
+
|
|
344
|
+
if (file['loaded'] > file.size) file.loaded = file.size;
|
|
345
|
+
if (file['percent'] > 100) file.percent = 100;
|
|
346
|
+
|
|
347
|
+
|
|
348
|
+
let response = await LIVE._emit("upload", data, true);
|
|
349
|
+
if (response?.data?.url) {
|
|
350
|
+
file["url"] = response?.data?.url;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
_w.trigger('upload-progress', {
|
|
354
|
+
"upid": file.upid,
|
|
355
|
+
"files": que['files']
|
|
356
|
+
});
|
|
357
|
+
start = end;
|
|
358
|
+
end = start + BYTES_PER_CHUNK;
|
|
359
|
+
part++;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
file['status'] = "DONE";
|
|
363
|
+
_w.trigger('file-uploaded', {
|
|
364
|
+
"upid": file.upid,
|
|
365
|
+
"files": que['files'],
|
|
366
|
+
"file": file
|
|
367
|
+
});
|
|
368
|
+
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
que['status'] = "DONE";
|
|
372
|
+
_w.trigger('upload-complete', {
|
|
373
|
+
"upid": que.upid,
|
|
374
|
+
"files": que['files'],
|
|
375
|
+
});
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
function process(data) {
|
|
379
|
+
var upid = data.upid;
|
|
380
|
+
var _files = data.files;
|
|
381
|
+
if (!_queue.hasOwnProperty(upid)) _queue[upid] = {
|
|
382
|
+
"status": "QUEUED",
|
|
383
|
+
"upid": upid,
|
|
384
|
+
"files": {},
|
|
385
|
+
"blobs": {},
|
|
386
|
+
"data": {}
|
|
387
|
+
};
|
|
388
|
+
var que = _queue[upid];
|
|
389
|
+
var files = [];
|
|
390
|
+
var newFiles = {};
|
|
391
|
+
var newData = {};
|
|
392
|
+
for (var j = 0; j < _files.length; j++) files.push(_files[j]);
|
|
393
|
+
while (files.length > 0) {
|
|
394
|
+
var blob = files.shift();
|
|
395
|
+
var id = fid();
|
|
396
|
+
newFiles[id] = {
|
|
397
|
+
"id": id,
|
|
398
|
+
"upid": upid,
|
|
399
|
+
"name": blob.name,
|
|
400
|
+
"type": blob.type,
|
|
401
|
+
"size": blob.size,
|
|
402
|
+
"loaded": 0,
|
|
403
|
+
"percent": 0,
|
|
404
|
+
"status": "QUEUED",
|
|
405
|
+
"lastModifiedDate": blob.lastModifiedDate ? blob.lastModifiedDate.toLocaleDateString() : 'n/a'
|
|
406
|
+
};
|
|
407
|
+
newData[id] = {
|
|
408
|
+
"id": id,
|
|
409
|
+
"upid": upid,
|
|
410
|
+
"chunks": 1,
|
|
411
|
+
"part": 1
|
|
412
|
+
};
|
|
413
|
+
que['files'] = { ...que['files'], ...newFiles };
|
|
414
|
+
que['data'] = { ...que['data'], ...newData };
|
|
415
|
+
que['blobs'][id] = blob;
|
|
416
|
+
_w.trigger('queue-changed', {
|
|
417
|
+
"upid": upid,
|
|
418
|
+
"files": que['files']
|
|
419
|
+
});
|
|
420
|
+
}
|
|
421
|
+
_w.trigger('files-added', {
|
|
422
|
+
"upid": upid,
|
|
423
|
+
"files": que['files'],
|
|
424
|
+
"newfiles": newFiles
|
|
425
|
+
});
|
|
426
|
+
}
|
|
427
|
+
(function () {
|
|
428
|
+
'use strict';
|
|
429
|
+
_w.on('handle-files', function (e) {
|
|
430
|
+
process(e.data);
|
|
431
|
+
});
|
|
432
|
+
_w.on('start-upload', function (e) {
|
|
433
|
+
var upid = e.data.upid;
|
|
434
|
+
var que = _queue[upid];
|
|
435
|
+
if (que) {
|
|
436
|
+
if (que['status'] == "STARTED") {
|
|
437
|
+
_w.trigger('message', "Already Started!");
|
|
438
|
+
return;
|
|
439
|
+
}
|
|
440
|
+
} else {
|
|
441
|
+
_w.trigger('queue-empty', {
|
|
442
|
+
"upid": upid
|
|
443
|
+
});
|
|
444
|
+
return;
|
|
445
|
+
}
|
|
446
|
+
que['status'] = "STARTED";
|
|
447
|
+
if (LIVE.ready()) {
|
|
448
|
+
upload(que);
|
|
449
|
+
} else openSocket(que);
|
|
450
|
+
});
|
|
451
|
+
_w.on('stop-upload', function (e) {
|
|
452
|
+
var upid = e.data.upid;
|
|
453
|
+
var que = _queue[upid];
|
|
454
|
+
if (que) {
|
|
455
|
+
que['status'] = "STOPPED";
|
|
456
|
+
_w.trigger('upload-stop', {
|
|
457
|
+
"upid": upid,
|
|
458
|
+
"files": que
|
|
459
|
+
});
|
|
460
|
+
} else {
|
|
461
|
+
_w.trigger('queue-empty', {
|
|
462
|
+
"upid": upid
|
|
463
|
+
});
|
|
464
|
+
}
|
|
465
|
+
});
|
|
466
|
+
_w.on('remove-file', function (e) {
|
|
467
|
+
var upid = e.data.upid;
|
|
468
|
+
var que = _queue[upid];
|
|
469
|
+
var id = e.data.id;
|
|
470
|
+
if (que['files']?.hasOwnProperty(id)) {
|
|
471
|
+
var removedfile = que['files'][id];
|
|
472
|
+
delete que['files'][id];
|
|
473
|
+
_w.trigger('file-removed', {
|
|
474
|
+
"upid": upid,
|
|
475
|
+
"files": que['files'],
|
|
476
|
+
"removedfile": removedfile
|
|
477
|
+
});
|
|
478
|
+
_w.trigger('queue-changed', {
|
|
479
|
+
"upid": upid,
|
|
480
|
+
"files": que['files']
|
|
481
|
+
});
|
|
482
|
+
if (Object.keys(que['files']).length == 0) {
|
|
483
|
+
delete _queue[upid];
|
|
484
|
+
_w.trigger('queue-empty', {
|
|
485
|
+
"upid": upid
|
|
486
|
+
});
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
});
|
|
490
|
+
return;
|
|
491
|
+
})();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(t){"use strict";var e=null,r=null,n=null,i=null,l=null,o=window,s="WebWorker",a=null,u=null,f=null,p=null,g=null,c=null,h=null;function _(t){return function(e){var r=this._callbackStack[t];return"function"==typeof e&&r.push(e),this}}for(h in null!==(e=(i=i||o)[l=l||s]||null)&&(r=e),c=Array.prototype.slice,n=window.Worker,e=function(){this._constructor.apply(this,arguments)},e.prototype._$=null,e.prototype._callbackStack=null,e.prototype._lastError=null,e.prototype._log=null,e.prototype._nativeWorker=null,e.prototype._state=null,e.prototype._workerBlobUrl=null,e.prototype._workerScript=null,e.prototype._workerUrl=null,e.prototype._constructor=function(e){var r=null,n=null,i=null;if(Object.defineProperty(this,"_$",{configurable:!1,enumerable:!0,value:t(this),writable:!1}),null===(e=e||null)&&this.throwError(g.INVALID_ARGUMENTS,null,!0),"string"==typeof e){let l="";e=t.trim(e);try{window.hasOwnProperty(e)&&"string"==typeof window[e]?(l=window[e],this._workerScript=l):r=t(e)}catch(t){}null!==r&&r.length>0?(n=r.text(),this._workerScript=n):""==l&&(i=e)}this._workerUrl=i,this._callbackStack={error:[],loading:[],loaded:[],starting:[],started:[],terminating:[],terminated:[]},this._assignEventHandlers(),this._state=a.INITIALIZED,this.trigger(f.INITIALIZED)},e.prototype._initLog=function(){return this._log=[],this._log},e.prototype.getUrl=function(){return this._workerUrl},e.prototype.getBlobUrl=function(){return this._workerBlobUrl},e.prototype.getLog=function(){return this._log||this._initLog()},e.prototype.getNativeWorker=function(){return this._nativeWorker},e.prototype.getState=function(){return this._state},e.prototype.isLoading=function(){return this.getState()===a.LOADING},e.prototype.isLoaded=function(){return this.getState()>=a.LOADED&&!this.isTerminated()},e.prototype.isStarting=function(){return this.getState()===a.STARTING},e.prototype.isStarted=function(){return this.getState()>=a.STARTED&&!this.isTerminated()},e.prototype.isTerminating=function(){return this.getState()===a.TERMINATING},e.prototype.isTerminated=function(){return this.getState()===a.TERMINATED},e.prototype.load=function(){var r,n,i=this;return i.isLoading()||i.isLoaded()||(i.trigger(f.WORKER_LOADING),r=i.getUrl()||null,n=function(){var t,r=null;r=i._workerScript,r=e._workerScriptWrapper.replace(/\{\{main-function\}\}/g,r),t=new window.Blob([r],{type:"text/javascript"}),i._workerBlobUrl=window.URL.createObjectURL(t),i._createWorker()},null===r?n():t.ajax({async:!0,url:r,dataType:"text",crossDomain:!0,success:function(t){i._workerScript=t,n()},error:function(){i.throwError(g.WORKER_DID_NOT_LOAD,arguments)}})),i},e.prototype.log=function(t){return(this._log||this._initLog()).push(t),this},e.prototype._createWorker=function(){return this._nativeWorker=new n(this.getBlobUrl()),this._attachMessageParser(),this},e.prototype._assignEventHandlers=function(){function t(t){return function(){var e,r,n=this._callbackStack[t];(e=t.toUpperCase())in a&&(this._state=a[e]);for(;r=n.pop();)r.apply(this,arguments)}}return this.on(f.ERROR,t("error")),this.on(f.WORKER_LOADING,t("loading")),this.on(f.WORKER_LOADED,t("loaded")),this.on(f.WORKER_STARTING,t("starting")),this.on(f.WORKER_STARTED,t("started")),this.on(f.WORKER_TERMINATING,t("terminating")),this.on(f.WORKER_TERMINATED,t("terminated")),this},e.prototype.error=_("error"),e.prototype.loading=_("loading"),e.prototype.loaded=_("loaded"),e.prototype.starting=_("starting"),e.prototype.started=_("started"),e.prototype.terminating=_("terminating"),e.prototype.terminated=_("terminated"),e.prototype.start=function(){var t;return this.isStarting()||this.isStarted()?this:(t=c.call(arguments),this.isLoaded()?(this.trigger(f.WORKER_STARTING),this.sendMessage(u.START,t),this):(this.on(f.WORKER_LOADED,(function(){this.start.apply(this,t)})),this.load(),this))},e.prototype.sendMessage=function(t,e){var r=null,n=null;return e=e||null,null===(t=t||null)||((n={__isWebWorkerMsg:!0}).action=t,n.args=e,(r=this.getNativeWorker())&&r.postMessage(n)),this},e.prototype._attachMessageParser=function(){var e=null;return(e=t(this.getNativeWorker())).on("message",t.proxy((function(t){var e=(t.originalEvent||t).data,r=null,n=null;"object"==typeof e&&"__isWebWorkerMsg"in e&&e.__isWebWorkerMsg&&(r=e.action,n=e.args,this[r].apply(this,n))}),this)),e.on("error",t.proxy(this.throwError,this)),this},e.prototype.terminate=function(){return(this.getNativeWorker()||null)&&(this.trigger(f.WORKER_TERMINATING),this.sendMessage(u.TERMINATE,c.call(arguments))),this},e.prototype.terminateNow=function(){var t=null;return this.isTerminating()||this.trigger(f.WORKER_TERMINATING),(t=this.getNativeWorker()||null)&&(t.terminate(),this._nativeWorker=null,this.trigger(f.WORKER_TERMINATED)),this},e.prototype.on=function(){var t=this._$;return t.on.apply(t,arguments),this},e.prototype.one=function(){var t=this._$;return t.one.apply(t,arguments),this},e.prototype.off=function(){var t=this._$;return t.off.apply(t,arguments),this._assignEventHandlers(),this},e.prototype.trigger=function(e){var r=!1,n=null,i=null;return"object"==typeof e&&(n=e.type||null),"string"==typeof e&&(n=e||null,r=!0),null===n?this:n in p?(r&&(e=new t.Event(n)),e.worker=this,i=[e],arguments.length>1&&(i=i.concat(c.call(arguments,1))),this._triggerSelf.apply(this,i),this):(r&&(e={type:n,data:arguments[1]?arguments[1]:{}}),i=[e],this.sendMessage(u.TRIGGER_SELF,i),this)},e.prototype.triggerSelf=function(e){var r=null,n=null;return null===(e=e||null)||("string"==typeof e&&(r=e,e=new t.Event(r)),e.originalEvent=e.originalEvent||e,e.worker=this,n=[e],arguments.length>1&&(n=n.concat(c.call(arguments,1))),this._triggerSelf.apply(this,n)),this},e.prototype._triggerSelf=function(){var t=null;return(t=this._$).trigger.apply(t,arguments),this},e.prototype.throwError=function(t,r,n){var i=null;if("object"==typeof(t=t||g.UNKNOWN)&&(i=(t=t.originalEvent||t).data||null),i=void 0===r?i:r,n=n||!1,this._lastError=t,e._lastError=t,"_triggerError"in this&&this._triggerError(t,r,n),n)throw new window.Error(t);return this},e.prototype._triggerError=function(e,r,n){var i=null;return(i=new t.Event(f.ERROR)).message=this.getLastError(),i.errorData=r,i.throwsException=!!n,this.trigger(i),this},e.prototype.getLastError=function(){return this._lastError},e._lastError=null,a={INITIALIZED:0,LOADING:1,LOADED:2,STARTING:3,STARTED:4,TERMINATING:5,TERMINATED:6},e.State=a,u={LOG:"log",START:"start",TERMINATE:"terminate",TERMINATE_NOW:"terminateNow",TRIGGER:"trigger",TRIGGER_SELF:"triggerSelf"},e.Action=u,f={INITIALIZED:"initialized",ERROR:"error",WORKER_LOADING:"worker-loading",WORKER_LOADED:"worker-loaded",WORKER_STARTING:"worker-starting",WORKER_STARTED:"worker-started",WORKER_TERMINATING:"worker-terminating",WORKER_TERMINATED:"worker-terminated"},e.Event=f,p={},e.EventMap=p,f)f[h]="webworker:"+f[h],p[f[h]]=h;g={UNKNOWN:"An unknown error occured.",INVALID_ARGUMENTS:"Invalid arguments were supplied to this method.",WORKER_DID_NOT_LOAD:"Unable to load worker."},e.Error=g,e._workerScriptWrapper='var e=null,t=null,n=null,r={};e={{state-data}};t={{action-data}};n={{event-data}};self._callbackStack=null;self._listeners=r;self._isTerminating=false;self._state=null;self.State=e;self.Action=t;self.Event=n;self._assignEventHandlers=function(){function t(t){return function(){var n=self._callbackStack[t],r,i;r=t.toUpperCase();if(r in e){self._state=e[r]}while(i=n.pop()){i.apply(self,arguments)}}}self.on(n.WORKER_TERMINATING,t("terminating"));return self};self.getState=function(){return this._state};self.isInitialized=function(){var e=self.getState();return e!==null&&e>=0};self.isTerminating=function(){return self.getState()===e.TERMINATING};self._main=function(){var startArgs=arguments;{{main-function}};return self};self._init=function(){self._callbackStack={terminating:[]};self._assignEventHandlers();self._state=e.INITIALIZED;self.trigger(n.WORKER_LOADED);return self};self.start=function(){if(!self.isInitialized()){return self}self.triggerSelf(n.WORKER_STARTING);self._main.apply(self,arguments);self.triggerSelf(n.WORKER_STARTED);self.trigger(n.WORKER_STARTED);return self};self.log=function(e){self.sendMessage(t.LOG,[e]);return self};self.on=function(e,t){e+="";t=t||null;if(typeof t!=="function"){return self}if(!(e in r)){r[e]=[]}r[e].push(t);return self};self.one=function(e,t){var n=null;n=function(){t.apply(this,arguments);self.off(e,n);return};self.on(e,n);return};self.off=function(e,t){var n=null;e=e||null;t=t||null;if(e===null&&t===null){for(n in r){delete r[n]}self._assignEventHandlers();return self}self._removeListenerFromEventType(e,t);return self};self._removeListenerFromEventType=function(e,t){var n=r[e],i=0;t=t||null;if(t===null){r[e]=[];return self}for(;i<n.length;i++){if(n[i]===t){n.splice(i,1);i--}}return self};self.terminating=function(e){var t=self._callbackStack.terminating;if(typeof e==="function"){t.push(e)}return self};self.trigger=function(e,n){var r=null;e=e||null;if(e===null){return self}if(typeof e==="string"){r=e||null;e={type:r}}else if(typeof e==="object"){r=e.type||null;n=e.data}if(r===null){return self}e.data=n;self.sendMessage(t.TRIGGER_SELF,[e]);return self};self.triggerSelf=function(e,t){var n=null,i=null,s=null,o=null,u=0;e=e||null;if(e===null){return this}if(typeof e==="string"){n=e||null;e={type:e}}else if(typeof e==="object"){n=e.type||null;t=e.data}if(n===null){return this}e.data=t;i=r[n]||null;if(i===null){return this}s=i.length;for(u=0;u<s;u++){o=i[u];o.apply(this,[e]);if(s!==i.length){u--;s=i.length}}return this};self.sendMessage=function(e,t){var n=null;e=e||null;t=t||[];if(e===null){return self}n={__isWebWorkerMsg:true};n.action=e;n.args=t;self.postMessage(n);return self};self.terminate=function(e){e=!!e;if(!self.isTerminating()){self._setTerminatingStatus();self.triggerSelf(n.WORKER_TERMINATING);self.trigger(n.WORKER_TERMINATING)}self.sendMessage(t.TERMINATE_NOW,[]);if(e){self._nativeClose()}return self};self.terminateNow=function(){return self.terminate(true)};self._setTerminatingStatus=function(){self._state=e.TERMINATING;return self};self._nativeClose=self.close;self.close=self.terminate;self.addEventListener("message",function(e){var t=e.originalEvent||e,n=t.data,r=null,i=null;if(typeof n==="object"&&"__isWebWorkerMsg"in n&&n.__isWebWorkerMsg){r=n.action;i=n.args;self[r].apply(self,i)}},false);self._init()',e._workerScriptWrapper=e._workerScriptWrapper.replace(/\{\{state-data\}\}/g,JSON.stringify(a)).replace(/\{\{action-data\}\}/g,JSON.stringify(u)).replace(/\{\{event-data\}\}/g,JSON.stringify(f)),e.getLastError=e.prototype.getLastError,e.noConflict=function(t,n){return t=t||null,n=n||null,o[s]===e&&(delete o[s],r&&(o[s]=r)),t&&n&&(t[n]=e),e},i[l]=e}(jQuery);
|