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

4
node_modules/binaryjs/doc/README.md generated vendored Normal file
View File

@ -0,0 +1,4 @@
## BinaryJS Documentations
### [Getting started guide](https://github.com/binaryjs/binaryjs/blob/master/doc/start.md)
### [API reference](https://github.com/binaryjs/binaryjs/blob/master/doc/api.md)

216
node_modules/binaryjs/doc/api.md generated vendored Normal file
View File

@ -0,0 +1,216 @@
# BinaryJS API Reference
## Class: binaryjs.BinaryServer `Node.js only`
This class is a the BinaryJS websocket server. It is an `EventEmitter`.
### new binaryjs.BinaryServer([options], [callback])
* `options` Object
* `host` String. Default `0.0.0.0`
* `port` Number
* `server` Object. Use an existing `http.Server` or `ws.Server` instead of creating a new one.
* `path` String. The path on which to accept WebSocket connections
* `chunkSize` Number. Passed into constructor of connecting `BinaryClient`. Default `40960`
Construct a new server object.
Either `port` must be provided or `server` to use an existing `http.Server`.
### server.clients
A hash of all connected clients. Keys are client ids and values are instances of `binaryjs.BinaryClient`.
### server.close()
Close the server and terminate all clients.
### Event: 'error'
`function (error) { }`
If the underlying server emits an error, it will be forwarded here.
### Event: 'connection'
`function (client) { }`
When a new BinaryJS connection is established. `client` is an object of type `binaryjs.BinaryClient`.
## Class: binaryjs.BinaryClient `Node.js and browsers`
This class represents a BinaryJS websocket client connection. It is an `EventEmitter`.
### new binaryjs.BinaryClient(address, [options])
Connects to the given `address` (in the form `ws://url`).
* `options` Object
* `chunkSize` Number. Size of chunks when using `client.send`. Default `40960`
`BinaryClient` can also be obtained in the `connection` event of a `BinaryServer`
### client.streams
A hash of all current streams. Keys are stream ids and values are instances of `binaryjs.BinaryStream`.
### client.createStream([meta])
Returns `binaryjs.BinaryStream`
Creates a new readable and writable `binaryjs.BinaryStream` object, triggering a `stream` event on the remote client with the given `meta` data parameter.
### client.send(data, [meta])
Returns `binaryjs.BinaryStream`
Creates a new readable and writable `binaryjs.BinaryStream` object with the given `meta` data and sends `data` through the connection.
If `data` is a Node.js `Buffer` or browser `ArrayBuffer`, `ArrayBufferView`, `Blob`, or `File`, the data will be chunked according to `options.chunkSize` and streamed through the new `BinaryStream`.
If `data` is a Node.js stream (including `BinaryStream` objects), it will be piped into a new `BinaryStream`
If `data` is any other type, it will be sent through the stream in one chunk.
### client.close()
Gracefully closes the connection.
### Event: 'stream'
`function (stream, meta) { }`
Emitted when a new stream is initialized by the remote client.
`stream` is a `binaryjs.BinaryStream` object that is both readable and writable.
`meta` is the data given when the stream was created via `createStream(meta)` or `send(data, meta)`, sent verbatim.
### Event: 'error'
`function (error) { }`
If the client emits an error, this event is emitted (errors from the underlying `net.Socket` are forwarded here).
### Event: 'close'
`function () { }`
Is emitted when the connection is closed.
The `close` event is also emitted when then underlying `net.Socket` closes the connection (`end` or `close`).
### Event: 'open'
`function () { }`
Emitted when the connection is established.
## Class: binaryjs.BinaryStream `Node.js and browsers`
This class represents a BinaryJS client stream. It is a Node.js `Stream` and `EventEmitter`.
BinaryStreams are created through the `BinaryClient` `createStream` and `send` methods and received through the `stream` event.
Because `BinaryStream` extends the Node.js `stream`, all other streams can be piped into or from a `BinaryStream`. The browser implements a browser version of the Node.js `stream` API.
### stream.id
A id number identifying the stream. Unique to the given client, but not globally.
### stream.readable
Whether stream is readable.
### stream.writable
Whether stream is writable.
### stream.paused
Whether stream is paused.
### stream.pause()
Pause the stream.
### stream.resume()
Resume the stream.
### stream.end()
Sends an end message, triggering the `end` event and marks `stream.readable` false but does not close the socket.
### stream.write(data)
Returns `true` if data is written immediately or `false` if data is buffered in socket.
Writes `data` through the connection. `data` can be any JSON compatible type or binary data. Note data will not be chunked. `client.send` should be used for chunking.
### stream.destroy()
Immediately closed the socket.
### stream.pipe(destination, [options])
This is a Stream.prototype method available on all Streams.
See:
http://nodejs.org/api/stream.html#stream_stream_pipe_destination_options
### Event: 'data'
`function (data) { }`
Is emitted when data is received through the socket.
For non-binary types, data is received verbatim as sent.
On Node.js, binary data is received as `Buffer`.
On browsers, binary data is received as `ArrayBuffer`.
### Event: 'pause'
`function () { }`
Is emitted when stream is paused.
### Event: 'resume'
`function () { }`
Is emitted when stream is resumed.
### Event: 'end'
`function () { }`
Is emitted when `stream.end` has been called. `stream.readable` is set to `false`.
### Event: 'close'
`function () { }`
Emitted when the connection is destroyed or its underlying socket is closed.
### Event: 'drain'
`function () { }`
Emitted when the underlying socket buffer has drained. Used for stream pipe internals.
### Event: 'error'
`function (error) { }`
If the client emits an error, this event is emitted (errors from the underlying net.Socket are forwarded here). `stream.readable` and `stream.writable` are set to `false`.

168
node_modules/binaryjs/doc/start.md generated vendored Normal file
View File

@ -0,0 +1,168 @@
# Getting Started with BinaryJS
In this guide we'll download, install, and then build the [helloworld](https://github.com/binaryjs/binaryjs/tree/master/examples/helloworld) example. In this example we send clients a picture of a flower by piping the file into a binary websocket;
## Download
1. Install the BinaryJS server
```console
$ npm install binaryjs
```
or from Git
```console
$ git://github.com/binaryjs/binaryjs.git
$ cd binaryjs
$ npm install -g
```
2. Get the latest client library for your webpage
```html
<script src="http://cdn.binaryjs.com/0/binary.js"></script>
```
## Create the server
[View complete server.js source](https://github.com/binaryjs/binaryjs/blob/master/examples/helloworld/server.js)
First we include BinaryJS and the fs module
```js
var BinaryServer = require('binaryjs').BinaryServer;
var fs = require('fs');
```
Then we create a new server, specifying that we want to run it on port 9000:
```js
var server = BinaryServer({port: 9000});
```
Now we'll add a callback for new client connections
```js
server.on('connection', function(client){
//
});
```
Let's add to that callback so when a client connects, we'll send them a picture as a hello world
```js
server.on('connection', function(client){
var file = fs.createReadStream(__dirname + '/flower.png');
client.send(file);
});
```
Note that instead of `client.send(file)` we could've done this:
```js
var stream = client.createStream();
file.pipe(stream);
```
`client.send` is a helper function for doing just that when it takes a stream parameter, note that behavior is different for other parameter types. [See API reference](https://github.com/binaryjs/binaryjs/blob/master/doc/api.md#clientsenddata-meta).
That's it for the server!
## Create the client
[View complete index.html source](https://github.com/binaryjs/binaryjs/blob/master/examples/helloworld/index.html)
Make sure to include the client library, served by the cdn
```html
<script src="http://cdn.binaryjs.com/0/binary.js"></script>
```
Now here's our client side Javascript so we can receive that file
First we connection the server we just created
```js
var client = new BinaryClient('ws://localhost:9000');
```
Then we'll add a callback for the `stream` event, which is emitted when the server sends us the flower file stream.
```js
client.on('stream', function(stream, meta){
//
});
```
Now to finish up, inside that callback we need to do several things:
* Create an array to hold the parts of the image
* Add to array on the stream `data` event
* Create an `<img>` element and set the src to the data
```js
client.on('stream', function(stream, meta){
var parts = [];
stream.on('data', function(data){
parts.push(data);
});
stream.on('end', function(){
var img = document.createElement("img");
img.src = (window.URL || window.webkitURL).createObjectURL(new Blob(parts));
document.body.appendChild(img);
});
});
```
## Integrating with an existing node app
BinaryServer can listen on an existing [http.Server](http://nodejs.org/api/http.html#http_class_http_server) by specifying the `server` parameter in the options. See [fileupload](https://github.com/binaryjs/binaryjs/tree/master/examples/fileupload) example of this.
```js
var http = require('http');
var server = http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(9000);
var BinaryServer = require('binaryjs').BinaryServer,
fs = require('fs');
// Create a BinaryServer attached to our existing server
var binaryserver = new BinaryServer({server: server, path: '/binary-endpoint'});
binaryserver.on('connection', function(client){
var file = fs.createReadStream(__dirname + '/flower.png');
client.send(file);
});
```
Note that we've also supplied `path: 'binary-endpoint'` to set an endpoint that doesn't clash with the original application. When creating the client you can connect to this endpoint with:
```js
var client = new BinaryClient('ws://localhost:9000/binary-endpoint');
```
### Express.js
If your app runs on express js - the normal `app.listen(9000)` won't give you access to the base http server, instead you should create the a server and pass the express app as a request listener:
```js
var http = require('http');
var app = require('express')();
// create a server with the express app as a listener
var server = http.createServer(app).listen(9000);
// attach BinaryServer to the base http server
```
## Running the example
Run the server, and open index.html in your favorite binary socket compatible browser, and you'll see a lovely flower!
## Additonal details
This example shows you how to include the server and client BinaryJS libraries and stream your first piece of data.
BinaryJS is extremely flexible. You aren't limited to sending only binary data. In fact you can send any JSON compatible type and take advantage of the compact BinaryPack serialization format.
You aren't limited to piping streams around either. You can create as many streams as you want for each client, and send data bidirectionally, whether its a large buffer at once, chunked, or just strings and numbers and arrays and hashes.
[Check out the API reference](https://github.com/binaryjs/binaryjs/blob/master/doc/api.md)
[Ask questions on the mailing list](http://groups.google.com/group/binaryjs-group)