Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
331 lines (272 sloc) 11 KB
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>DirtyShare</title>
<LINK REL="SHORTCUT ICON" HREF="/public/favicon.ico" />
<meta name="keywords" content="node, nodejs, javascript, p2p, filesharing, webp2p, web peer to peer, p2pweb, open source" />
<meta name="description" content="DirtyShare is a proof of concept Peer to Peer filesharing system written in pure Javascript with Socket.io and Node.js." />
<link href="/public/style.css" rel="stylesheet" type="text/css" media="screen" />
<link href='http://fonts.googleapis.com/css?family=Trade+Winds' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Monsieur+La+Doulaise' rel='stylesheet' type='text/css'>
<script type="text/javascript"
src="http://code.jquery.com/jquery-1.5.2.js"></script>
<script src="/socket.io/socket.io.js"></script>
<script src="/public/socket.io.js"></script>
<script type="text/javascript" src="/public/jquery.url.js"></script>
</head>
<body>
<div id="header">
<b>Dirty</b>Share
</div>
<script type="text/javascript">
$(document).ready(function() {
filth =
[
"\"My God, That\'s Filthy!\"",
"\"You Dirty Bastards!\"",
"\"Sheer And Utter Filth!\"",
"\"What a Shame!\"",
];
$('#subheader').html('<i>' + filth[Math.floor(Math.random()*filth.length)] + '</i>');
});
</script>
<div id="subheader">
</div>
<div id="description">
This is WebP2P version 0.1, aka 'DirtyShare', a pure JavaScript "peer to peer" filesharing system written in Node.js and Socket.io. Don't use this for anything. What's wrong with you?
</div>
<div id="drop_zone" onClick="$('#files').click()" >
<div id="clicky"><br /><br /><br /><br />Loading..</div>
<div id="fileslist">
</div>
</div>
<input type="file" id="files" name="files[]" multiple style="height: 20px; opacity: 0; filter:alpha(opacity: 0); position: relative; top: -40px; left: -20px;" />
<div id="infoholder">
<div id="host">
</div>
<div id="peer">
Awaiting peer..
</div>
</div>
<script type="text/javascript">
$(document).ready(function() {
$('#shareurl').html('<b>http://${domain}/' + $.url().segment(1) + '</b>');
});
</script>
<br />
<div id="description">
Share this URL: <div id="shareurl"></div>
</div>
<div id="what">
<i><a onClick="$('#about').slideDown('slow');">What is this?</a><i>
</div>
<div id="about" style="display: none;">
<b>Dirty</b>Share is a proof of concept "Peer to Peer" filesharing system written in <b>pure Javascript</b> with Socket.io and Node.js. It's called <b>Dirty</b>Share because it's dirty as hell across the whole stack, from the concept to the code to the use case. <br/><br/>
File transfers in <b>Dirty</b>Share happen from a host client to a peer client, in chunks which go through the webserver over WebSockets provided by Socket.IO. The web server only holds onto the data while it is being received and transmitted through it, so there is <i>no data ever permanently stored on the web server</i>. This makes it perfect for sending dirty pictures!<br/><br/>
Ideally, the WebSockets will only be used to establish the P2P connections which will go over the HTML5 PeerConnection object, however, <i>no modern browsers support this feature yet</i>. Hopefully, it will become available within the next 6 months or so, and <b>we will be ready</b> for it !<br /><br />
Let's make a purely browser based, ad-free, Free and Open Source private filesharing system!
</div>
<div id="credits">
<b>Dirty</b>Share is written by <b>Rich Jones</b> of <b><a href="http://gun.io" target="_blank">Gun.io</a></b>. <br/><br/>
<a href="https://github.com/Miserlou/DirtyShare" target="_blank">Source code</a> is here.<br/> Patches graciously accepted! <br/><br/>
Interested in dicussing/hacking on web peer to peer software? Shoot an email to <b>webp2p@librelist.com</b> and you'll be part of the mailing list!
</div>
<div id="lower">
<div id="info">
</div>
<div id="warnings">
</div>
</center>
<script>
var fid = 0;
var files = {};
var downfiles = {};
var socket = io.connect('http://${domain}');
//read the requested bytes
var reader;
var canHost = true;
if (typeof FileReader !== "undefined"){
reader = new FileReader();
}
else{
$('#clicky').html('<br /><br />Your browser is not modern enough to serve as a host. :( <br /><br />(Try Chrome or Firefox!)');
canHost = false;
}
var chunksize = 65536;
socket.on('connect', function(data){
socket.emit('joiner', $.url().segment(1));
});
socket.on('fileslist', function(data){
$('#fileslist').show();
$('#clicky').html('');
$('#clicky').hide();
$('#fileslist').html('');
$('#fileslist').html(function(i,v){
return '<table id="filestable" cellspacing="0" summary=""><tr><th scope="col" abbr="Filename" class="nobg" width="60%">Filename</th><th scope="col" abbr="Status" width="20%" >Size</th> <th scope="col" abbr="Size"width="20%" >Action</th></tr>' + v;
});
files = {};
files = JSON.parse(data);
for (var file in files) {
console.log(file);
if (files.hasOwnProperty(file)) {
$('#filestable').append('<tr><th scope="row" class="spec">' + files[file][0] + '</th><td>' + files[file][1] + '</td><td class="end" ><div id="fidspan' + fid + '"></div><a href="" onclick="beginTransfer(\'' + files[file][0] + '\', ' + fid + ', ' + files[file][1] + '); return false;" id="fid' + fid + '">Transfer</a><a href="data:' + files[file][2] + ';base64," target="_blank" id="fidsave' + fid + '" style="display:none">Save to disk!</a></td></tr>');
fid++;
};
}
});
socket.on('warn', function(data){
$('#warnings').html(data);
});
socket.on('host', function(data){
if(canHost){
$('#host').html("You're hosting this party!");
$('#clicky').html("<br /><br /><br /><br />Click here to choose files");
$('#fileslist').hide();
}
});
socket.on('peer', function(data){
$('#peer').html("You're connected as a peer!");
$('#host').html("Host connected.");
$('#drop_zone').attr("onclick", function() {
return;
});
$('#files').remove();
$('#drop_zone').css("cursor", "default");
$('#fileslist').hide();
$('#clicky').html('Awaiting file list..');
});
socket.on('peerconnected', function(data){
$('#peer').html("Peer connected!");
});
socket.on('peerdisconnected', function(data){
$('#peer').html("Peer disconnected.");
});
socket.on('hostdisconnected', function(data){
$('#host').html("Host disconnected.");
$('#peer').html("You're disconnected!");
});
socket.on('info', function(data){
$('#info').append(data);
});
socket.on('begintransfer', function(file, chunk){
if(chunk == 0){
$('#info').append("Begining Transfer..");
}
fileholder= files[file];
fileo= files[file][3]; //ugly
start = chunk * chunksize;
if((parseInt(fileholder[1]) - 1) <= start + chunksize - 1){
stop = parseInt(fileholder[1]) - 1;
}
else{
stop = start + chunksize - 1;
}
// If we use onloadend, we need to check the readyState.
reader.onloadend = function(evt) {
if (evt.target.readyState == FileReader.DONE) { // DONE == 2
var data = evt.target.result;
socket.emit('datatransfer', data, file, chunk);
}
};
if (fileo.webkitSlice) {
var blob = fileo.webkitSlice(start, stop + 1);
} else if (fileo.mozSlice) {
var blob = fileo.mozSlice(start, stop + 1);
}
else{
alert("It won't work in your browser. Please use Chrome or Firefox.");
}
reader.readAsBinaryString(blob);
});
socket.on('datatransfer', function(data, file, chunk){
f = downfiles[file];
f.data = f.data + data;
if(f.chunks == chunk){
var fspan = "#fidspan" + f.fid;
$(fspan).html('');
$(fspan).hide();
var fsave = "#fidsave" + f.fid;
$(fsave).show();
$(fsave).attr('href', $(fsave).attr('href') + encode64(f.data));
$('#info').append("Transfer finished!");
}
else{
var fspan = "#fidspan" + f.fid;
$(fspan).html(Math.floor(((chunk/f.chunks) * 100)) + '%');
var nextchunk = parseInt(chunk);
socket.emit('begintransfer', file, nextchunk+1);
}
});
function beginTransfer(file, fid, size){
var f = "#fidspan" + fid;
$(f).html('0%');
f = "#fid" + fid;
$(f).hide();
var chunks = size/chunksize;
if(chunks% 1 != 0){
chunks = Math.floor(chunks) + 1;
}
downfiles[file] = {data:'', chunk:0, chunks:chunks, fid:fid};
socket.emit('begintransfer', file, 0);
};
function handleFileSelect(evt) {
var viles = evt.target.files; // FileList object
files = {};
// Loop through the FileList and append files to list.
for (var i = 0, f; f = viles[i]; i++) {
if (!files.hasOwnProperty(f)) {
files[f.name] = [f.name, f.size, f.type, f];
};
}
socket.emit('listfiles', JSON.stringify(files));
$('#fileslist').show();
$('#clicky').html('');
$('#clicky').hide();
$('#fileslist').html('');
$('#fileslist').html(function(i,v){
return '<table id="filestable" cellspacing="0" summary=""><tr><th scope="col" abbr="Filename" class="nobg" width="60%">Filename</th><th scope="col" abbr="Status" width="20%" >Size</th> <th scope="col" abbr="Size"width="20%" >Action</th></tr>' + v;
});
for (var file in files) {
if (files.hasOwnProperty(file)) {
$('#filestable').append('<tr><th scope="row" class="spec">' + files[file][0] + '</th><td>' + files[file][1] + '</td><td class="end"><b>Sharing!</b></td></tr>');
};
}
};
document.getElementById('files').addEventListener('change', handleFileSelect, false);
var keyStr = "ABCDEFGHIJKLMNOP" +
"QRSTUVWXYZabcdef" +
"ghijklmnopqrstuv" +
"wxyz0123456789+/" +
"=";
function encode64(input) {
var output = "";
var chr1, chr2, chr3 = "";
var enc1, enc2, enc3, enc4 = "";
var i = 0;
do {
chr1 = input.charCodeAt(i++);
chr2 = input.charCodeAt(i++);
chr3 = input.charCodeAt(i++);
enc1 = chr1 >> 2;
enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
enc4 = chr3 & 63;
if (isNaN(chr2)) {
enc3 = enc4 = 64;
} else if (isNaN(chr3)) {
enc4 = 64;
}
output = output +
keyStr.charAt(enc1) +
keyStr.charAt(enc2) +
keyStr.charAt(enc3) +
keyStr.charAt(enc4);
chr1 = chr2 = chr3 = "";
enc1 = enc2 = enc3 = enc4 = "";
} while (i < input.length);
return output;
}
</script>
</body>
</html>