This repository has been archived by the owner on Jun 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cdn requester: use worker as blob to avoid worker hosting problems (f…
…ixes #36)
- Loading branch information
1 parent
0470d6e
commit 8d928ee
Showing
2 changed files
with
18 additions
and
62 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
// Copyright 2014 Flávio Ribeiro <[email protected]>. | ||
// All rights reserved. | ||
// Use of this source code is governed by Apache | ||
// Use of this source code is governed by Apache | ||
// license that can be found in the LICENSE file. | ||
|
||
var BaseObject = require('base_object'); | ||
|
@@ -10,10 +10,26 @@ class CDNRequester extends BaseObject { | |
get name() { return 'CDNRequester'; } | ||
initialize() { | ||
this.storage = Storage.getInstance() | ||
this.utils = new Worker("asyncxhr.js") | ||
this.utils = new Worker(this.getWorkerURL()) | ||
this.utils.onmessage = (e) => this.resourceLoaded(e.data) | ||
} | ||
|
||
getWorkerURL() { | ||
console.log("using getWorkerURL") | ||
var content = 'request=function(e,r,s){var n=new XMLHttpRequest;return n.open("GET",e,r?!0:!1),s&&(n.responseType=s),r?(n.onload=r,void n.send()):(n.send(),200==n.status?n.response:"")},base64ArrayBuffer=function(e){for(var r,s,n,t,a,o="",u="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",d=new Uint8Array(e),f=d.byteLength,i=f%3,c=f-i,p=0;c>p;p+=3)a=d[p]<<16|d[p+1]<<8|d[p+2],r=(16515072&a)>>18,s=(258048&a)>>12,n=(4032&a)>>6,t=63&a,o+=u[r]+u[s]+u[n]+u[t];return 1==i?(a=d[c],r=(252&a)>>2,s=(3&a)<<4,o+=u[r]+u[s]+"=="):2==i&&(a=d[c]<<8|d[c+1],r=(64512&a)>>10,s=(1008&a)>>4,n=(15&a)<<2,o+=u[r]+u[s]+u[n]+"="),o},resourceLoaded=function(e){var r=base64ArrayBuffer(e.currentTarget.response);this.postMessage(r)},this.addEventListener("message",function(e){request(e.data,resourceLoaded.bind(this),"arraybuffer")},!1);' | ||
var blob | ||
try { | ||
blob = new Blob([content], {type: 'application/javascript'}) | ||
} catch (e) { | ||
window.BlobBuilder = window.BlobBuilder || window.WebKitBlobBuilder || window.MozBlobBuilder | ||
blob = new BlobBuilder() | ||
blob.append(content) | ||
blob = blob.getBlob() | ||
} | ||
|
||
return URL.createObjectURL(blob) | ||
} | ||
|
||
requestResource(resource, callback) { | ||
this.callback = callback | ||
this.resource = resource | ||
|