socketio-file-upload
Advanced tools
Comparing version 0.3.2 to 0.3.3
@@ -415,2 +415,3 @@ /* | ||
_removeInputElement(); | ||
callbacks = {}, uploadedFiles = [], readyCallbacks = []; | ||
}; | ||
@@ -498,6 +499,6 @@ | ||
// CONSTRUCTOR: Listen to the "complete", "ready", and "error" messages on the socket. | ||
socket.on("siofu_ready", function(data){ | ||
_listenTo(socket, "siofu_ready", function(data){ | ||
readyCallbacks[data.id](data.name); | ||
}); | ||
socket.on("siofu_complete", function(data){ | ||
_listenTo(socket, "siofu_complete", function(data){ | ||
_dispatch("complete", { | ||
@@ -509,3 +510,3 @@ file: uploadedFiles[data.id], | ||
}); | ||
socket.on("siofu_error", function(data){ | ||
_listenTo(socket, "siofu_error", function(data){ | ||
_dispatch("error", { | ||
@@ -512,0 +513,0 @@ file: uploadedFiles[data.id], |
@@ -7,9 +7,9 @@ /* Socket IO File Upload Client-Side Library | ||
(function(k,e,f){"function"===typeof define&&define.amd?define(e,f):k[e]=f()})(this,"SocketIOFileUpload",function(){return function(k){var e=this;if(!window.File||!window.FileReader)throw Error("Socket.IO File Upload: Browser Not Supported");var f={},p=[],v=[];e.fileInputElementId="siofu_input";e.useText=!1;e.serializedOctets=!1;e.useBuffer=!0;var r=function(a,b){var c=document.createEvent("Event");c.initEvent(a,!1,!1);for(var d in b)b.hasOwnProperty(d)&&(c[d]=b[d]);return e.dispatchEvent(c)},n=[], | ||
g=function(a,b,c,d){a.addEventListener(b,c,d);n.push(arguments)},w=function(a,b,c,d){a.removeEventListener&&a.removeEventListener(b,c,d)},x=function(){for(var a=n.length-1;0<=a;a--)w.apply(this,n[a]);n=[]},y=function(a){if(null!==e.maxFileSize&&a.size>e.maxFileSize)r("error",{file:a,message:"Attempt by client to upload file exceeding the maximum file size",code:1});else if(r("start",{file:a})){var b=new FileReader,c=0,d=p.length,f=e.useText,n;p.push(a);g(b,"progress",function(a){});g(b,"load",function(t){a:{t= | ||
t.loaded;var g,p=!1;if(f)g=b.result.slice(c,t);else try{var m=new Uint8Array(b.result,c,t);if(e.serializedOctets)g=m;else if(e.useBuffer)g=m.buffer;else{var p=!0,l,q=m.buffer.byteLength,h="";for(l=0;l<q;l+=3)h+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[m[l]>>2],h+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[(m[l]&3)<<4|m[l+1]>>4],h+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[(m[l+1]&15)<<2|m[l+2]>>6],h+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[m[l+ | ||
2]&63];2===q%3?h=h.substring(0,h.length-1)+"=":1===q%3&&(h=h.substring(0,h.length-2)+"==");g=h}}catch(u){k.emit("siofu_done",{id:d,interrupt:!0});break a}k.emit("siofu_progress",{id:d,start:c,end:t,content:g,base64:p});c=t}k.emit("siofu_done",{id:d});r("load",{file:a,reader:b,name:n})});g(b,"error",function(){k.emit("siofu_done",{id:d,interrupt:!0})});g(b,"abort",function(){k.emit("siofu_done",{id:d,interrupt:!0})});k.emit("siofu_start",{name:a.name,mtime:a.lastModifiedDate,meta:a.meta,encoding:f? | ||
"text":"octet",id:d});v.push(f?function(c){b.readAsText(a);n=c}:function(c){b.readAsArrayBuffer(a);n=c})}},q=function(a){if(0!==a.length){for(var b=0;b<a.length;b++)a[b].meta={};if(r("choose",{files:a}))for(b=0;b<a.length;b++)y(a[b])}},u=function(a){var b=a.target.files||a.dataTransfer.files;a.preventDefault();q(b)};this.submitFiles=function(a){a&&q(a)};this.listenOnSubmit=function(a,b){b.files&&g(a,"click",function(){q(b.files)},!1)};this.listenOnArraySubmit=function(a,b){for(var c in b)this.listenOnSubmit(a, | ||
b[c])};this.listenOnInput=function(a){a.files&&g(a,"change",u,!1)};this.listenOnDrop=function(a){g(a,"dragover",function(a){a.preventDefault()},!1);g(a,"drop",u)};this.prompt=function(){var a;a=document.getElementById(e.fileInputElementId);a||(a=document.createElement("input"),a.setAttribute("type","file"),a.setAttribute("id",e.fileInputElementId),a.style.display="none",document.body.appendChild(a));g(a,"change",u,!1);var b=document.createEvent("MouseEvents");b.initMouseEvent("click",!0,!0,window, | ||
0,0,0,0,0,!1,!1,!1,!1,0,null);a.dispatchEvent(b)};this.destroy=function(){x();var a=document.getElementById(e.fileInputElementId);a&&a.parentNode.removeChild(a)};this.addEventListener=function(a,b){f[a]||(f[a]=[]);f[a].push(b)};this.removeEventListener=function(a,b){if(!f[a])return!1;for(var c=0;c<f[a].length;c++)if(f[a][c]===b)return f[a].splice(c,1),!0;return!1};this.dispatchEvent=function(a){var b=f[a.type];if(!b)return!0;for(var c=!0,d=0;d<b.length;d++)!1===b[d](a)&&(c=!1);return c};k.on("siofu_ready", | ||
function(a){v[a.id](a.name)});k.on("siofu_complete",function(a){r("complete",{file:p[a.id],detail:a.detail,success:a.success})});k.on("siofu_error",function(a){r("error",{file:p[a.id],message:a.message,code:0})})}}); | ||
(function(k,e,f){"function"===typeof define&&define.amd?define(e,f):k[e]=f()})(this,"SocketIOFileUpload",function(){return function(k){var e=this;if(!window.File||!window.FileReader)throw Error("Socket.IO File Upload: Browser Not Supported");var f={},l=[],r=[];e.fileInputElementId="siofu_input";e.useText=!1;e.serializedOctets=!1;e.useBuffer=!0;var t=function(a,b){var c=document.createEvent("Event");c.initEvent(a,!1,!1);for(var h in b)b.hasOwnProperty(h)&&(c[h]=b[h]);return e.dispatchEvent(c)},p=[], | ||
d=function(a,b,c,h){a.addEventListener(b,c,h);p.push(arguments)},v=function(a,b,c,h){a.removeEventListener&&a.removeEventListener(b,c,h)},w=function(){for(var a=p.length-1;0<=a;a--)v.apply(this,p[a]);p=[]},x=function(a){if(null!==e.maxFileSize&&a.size>e.maxFileSize)t("error",{file:a,message:"Attempt by client to upload file exceeding the maximum file size",code:1});else if(t("start",{file:a})){var b=new FileReader,c=0,h=l.length,f=e.useText,p;l.push(a);d(b,"progress",function(a){});d(b,"load",function(d){a:{d= | ||
d.loaded;var l,r=!1;if(f)l=b.result.slice(c,d);else try{var n=new Uint8Array(b.result,c,d);if(e.serializedOctets)l=n;else if(e.useBuffer)l=n.buffer;else{var r=!0,m,q=n.buffer.byteLength,g="";for(m=0;m<q;m+=3)g+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[n[m]>>2],g+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[(n[m]&3)<<4|n[m+1]>>4],g+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[(n[m+1]&15)<<2|n[m+2]>>6],g+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[n[m+ | ||
2]&63];2===q%3?g=g.substring(0,g.length-1)+"=":1===q%3&&(g=g.substring(0,g.length-2)+"==");l=g}}catch(u){k.emit("siofu_done",{id:h,interrupt:!0});break a}k.emit("siofu_progress",{id:h,start:c,end:d,content:l,base64:r});c=d}k.emit("siofu_done",{id:h});t("load",{file:a,reader:b,name:p})});d(b,"error",function(){k.emit("siofu_done",{id:h,interrupt:!0})});d(b,"abort",function(){k.emit("siofu_done",{id:h,interrupt:!0})});k.emit("siofu_start",{name:a.name,mtime:a.lastModifiedDate,meta:a.meta,encoding:f? | ||
"text":"octet",id:h});r.push(f?function(c){b.readAsText(a);p=c}:function(c){b.readAsArrayBuffer(a);p=c})}},q=function(a){if(0!==a.length){for(var b=0;b<a.length;b++)a[b].meta={};if(t("choose",{files:a}))for(b=0;b<a.length;b++)x(a[b])}},u=function(a){var b=a.target.files||a.dataTransfer.files;a.preventDefault();q(b)};this.submitFiles=function(a){a&&q(a)};this.listenOnSubmit=function(a,b){b.files&&d(a,"click",function(){q(b.files)},!1)};this.listenOnArraySubmit=function(a,b){for(var c in b)this.listenOnSubmit(a, | ||
b[c])};this.listenOnInput=function(a){a.files&&d(a,"change",u,!1)};this.listenOnDrop=function(a){d(a,"dragover",function(a){a.preventDefault()},!1);d(a,"drop",u)};this.prompt=function(){var a;a=document.getElementById(e.fileInputElementId);a||(a=document.createElement("input"),a.setAttribute("type","file"),a.setAttribute("id",e.fileInputElementId),a.style.display="none",document.body.appendChild(a));d(a,"change",u,!1);var b=document.createEvent("MouseEvents");b.initMouseEvent("click",!0,!0,window, | ||
0,0,0,0,0,!1,!1,!1,!1,0,null);a.dispatchEvent(b)};this.destroy=function(){w();var a=document.getElementById(e.fileInputElementId);a&&a.parentNode.removeChild(a);f={};l=[];r=[]};this.addEventListener=function(a,b){f[a]||(f[a]=[]);f[a].push(b)};this.removeEventListener=function(a,b){if(!f[a])return!1;for(var c=0;c<f[a].length;c++)if(f[a][c]===b)return f[a].splice(c,1),!0;return!1};this.dispatchEvent=function(a){var b=f[a.type];if(!b)return!0;for(var c=!0,d=0;d<b.length;d++)!1===b[d](a)&&(c=!1);return c}; | ||
d(k,"siofu_ready",function(a){r[a.id](a.name)});d(k,"siofu_complete",function(a){t("complete",{file:l[a.id],detail:a.detail,success:a.success})});d(k,"siofu_error",function(a){t("error",{file:l[a.id],message:a.message,code:0})})}}); |
{ | ||
"name": "socketio-file-upload", | ||
"version": "0.3.2", | ||
"version": "0.3.3", | ||
"description": "Uploads files to a Node.JS server using Socket.IO", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -71,3 +71,3 @@ Socket.IO File Upload | ||
- [instance.useText = false](#instanceusetext--false) | ||
- [instance.useBuffer = false](#instanceusebuffer--false) | ||
- [instance.useBuffer = true](#instanceusebuffer--true) | ||
- [instance.serializeOctets = false](#instanceserializeoctets--false) | ||
@@ -241,5 +241,5 @@ - [Client-Side Events](#events) | ||
#### instance.useBuffer = false | ||
#### instance.useBuffer = true | ||
Starting with Socket.IO 1.0, binary data may now be transmitted through the Web Socket. You may tell SIOFU to transmit files as binary data by setting this option to `true`. Defaults to `false`, which transmits files as base 64-encoded strings. | ||
Starting with Socket.IO 1.0, binary data may now be transmitted through the Web Socket. Begining with SIOFU version 0.3.2 (December 17, 2014), this option is enabled by default. To support older versions of Socket.IO (e.g. version 0.9.x), set this option to `false`, which transmits files as base 64-encoded strings. | ||
@@ -256,3 +256,3 @@ Advantages of enabling this option: | ||
As you use this option, [please leave feedback](https://github.com/vote539/socketio-file-upload/issues/16). I'm hoping to enable this feature by default in a future version of Socket.IO File Upload. | ||
As you use this option, [please leave feedback](https://github.com/vote539/socketio-file-upload/issues/16). | ||
@@ -259,0 +259,0 @@ #### instance.serializeOctets = false |
50656