-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
54 lines (51 loc) · 2.25 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js"></script>
<script type="text/javascript" src="http://cdn.binaryjs.com/0/binary.js"></script>
<script type="text/javascript">
var client = new BinaryClient('ws://' + location.host);
client.on('open', function() {
var box = $('#box');
box.on('dragenter', doNothing);
box.on('dragover', doNothing);
box.text('Drag files here');
box.on('drop', function(e) {
e.originalEvent.preventDefault();
var file = e.originalEvent.dataTransfer.files[0];
var filename = Math.round(Math.random() * 100000) +
'.' +
file.name.substr(file.name.lastIndexOf('.') + 1);
$('<div align="center"></div>')
.append($('<span></span>')
.text('http://' + location.host +
'/download/' + filename + '.html'))
.appendTo('body');
var stream;
var interval = setInterval(function() {
stream = client.send(file, {
name: filename,
size: file.size
});
var tx = 0;
stream.on('data', function(data) {
clearInterval(interval);
$('#progress').text(
Math.round(tx += data.rx * 100) +
'% complete');
});
}, 2000);
});
});
function doNothing(e) {
e.preventDefault();
e.stopPropagation();
}
</script>
</head>
<body>
<div id="progress" align="center">0% complete</div>
<div id="box" style="background: #eee; font-size: 26px; width: 400px; height: 300px;line-height: 300px; margin: 0 auto; text-align: center;">
Connecting...
</div>
</body>
</html>