first commit

This commit is contained in:
developertrinidad08
2023-01-16 18:11:14 -03:00
commit 7e6cf29479
233 changed files with 26791 additions and 0 deletions

19
node_modules/binaryjs/examples/fileupload/README.md generated vendored Normal file
View File

@ -0,0 +1,19 @@
## Drag and Drop File Upload Example w/ Percentage completion
1. Run the server:
```
node server.js
```
2. Go to
```
http://localhost:9000/
```
3. Drag a file into the box. Percent transferred will be shown and the file will be saved in the example's directory.
Server code is contained in `server.js`
Client side code is contained in `public/index.html`

View File

@ -0,0 +1,46 @@
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js"></script>
<script src="http://cdn.binaryjs.com/0/binary.js"></script>
<script>
var client = new BinaryClient('ws://localhost:9000');
// Wait for connection to BinaryJS server
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];
// Add to list of uploaded files
$('<div align="center"></div>').append($('<a></a>').text(file.name).prop('href', '/'+file.name)).appendTo('body');
// `client.send` is a helper function that creates a stream with the
// given metadata, and then chunks up and streams the data.
var stream = client.send(file, {name: file.name, size: file.size});
// Print progress
var tx = 0;
stream.on('data', function(data){
$('#progress').text(Math.round(tx+=data.rx*100) + '% complete');
});
});
});
// Deal with DOM quirks
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>

34
node_modules/binaryjs/examples/fileupload/server.js generated vendored Normal file
View File

@ -0,0 +1,34 @@
var fs = require('fs');
var http = require('http');
// Serve client side statically
var express = require('express');
var app = express();
app.use(express.static(__dirname + '/public'));
var server = http.createServer(app);
// Start Binary.js server
var BinaryServer = require('../../').BinaryServer;
var bs = BinaryServer({server: server});
// Wait for new user connections
bs.on('connection', function(client){
// Incoming stream from browsers
client.on('stream', function(stream, meta){
//
var file = fs.createWriteStream(__dirname+ '/public/' + meta.name);
stream.pipe(file);
//
// Send progress back
stream.on('data', function(data){
stream.write({rx: data.length / meta.size});
});
//
});
});
//
//
server.listen(9000);
console.log('HTTP and BinaryJS server started on port 9000');