diff --git a/README.md b/README.md index 8afe65b6..6e00dd51 100644 --- a/README.md +++ b/README.md @@ -142,12 +142,10 @@ standards (no plugins, just HTML5 and WebRTC)! It's easy to get started! ##### Downloading a file is simple: ```js -var WebTorrent = require('webtorrent') - var client = new WebTorrent() -var magnetURI = '...' +var torrentId = 'magnet:?xt=urn:btih:6a9759bffd5c0af65319979fb7832189f4f3c35d&dn=sintel.mp4&tr=wss%3A%2F%2Ftracker.btorrent.xyz&tr=wss%3A%2F%2Ftracker.fastcast.nz&tr=wss%3A%2F%2Ftracker.openwebtorrent.com&tr=wss%3A%2F%2Ftracker.webtorrent.io&ws=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2Fsintel-1024-surround.mp4' -client.add(magnetURI, function (torrent) { +client.add(torrentId, function (torrent) { // Got torrent metadata! console.log('Client is downloading:', torrent.infoHash) @@ -161,10 +159,15 @@ client.add(magnetURI, function (torrent) { ##### Seeding a file is simple, too: -```js -var dragDrop = require('drag-drop') -var WebTorrent = require('webtorrent') +This example uses the [`drag-drop`][drag-drop] package, to make the HTML5 Drag and +Drop API easier to work with. + +To start using `drag-drop`, simply include the +`dragdrop.min.js` script on your page. This exports a `dragDrop` function on `window`. +If you use [browserify](http://browserify.org), you can +`npm install drag-drop` and then use like this `var dragDrop = require('drag-drop')`. +```js var client = new WebTorrent() // When user drops files on the browser, create a new torrent and start seeding it! @@ -266,7 +269,14 @@ There are many supported streaming options: --stdout standard out [implies --quiet] ``` -In addition to magnet uris, webtorrent supports [many ways to specify a torrent](#clientaddtorrentid-opts-function-ontorrent-torrent-). +In addition to magnet uris, webtorrent supports many ways to specify a torrent: + +- magnet uri (string) +- torrent file (buffer) +- info hash (hex string or buffer) +- parsed torrent (from [parse-torrent](https://github.com/feross/parse-torrent)) +- http/https url to a torrent file (string) +- filesystem path to a torrent file (string) ### Modules diff --git a/docs/api.md b/docs/api.md index 0956d897..fd8053c2 100644 --- a/docs/api.md +++ b/docs/api.md @@ -298,9 +298,10 @@ Here is a usage example: ```js var client = new WebTorrent() -var magnetURI = 'magnet: ...' +var torrentId = 'magnet:?xt=urn:btih:6a9759bffd5c0af65319979fb7832189f4f3c35d&dn=sintel.mp4&tr=wss%3A%2F%2Ftracker.btorrent.xyz&tr=wss%3A%2F%2Ftracker.fastcast.nz&tr=wss%3A%2F%2Ftracker.openwebtorrent.com&tr=wss%3A%2F%2Ftracker.webtorrent.io&ws=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2Fsintel-1024-surround.mp4' +var port = 5003 -client.add(magnetURI, function (torrent) { +client.add(torrentId, function (torrent) { // create HTTP server for this torrent var server = torrent.createServer() server.listen(port) // start the server listening to a port diff --git a/docs/get-started.md b/docs/get-started.md index 83b069f3..e5f2319d 100644 --- a/docs/get-started.md +++ b/docs/get-started.md @@ -36,8 +36,6 @@ var WebTorrent = require('webtorrent') ### Downloading a torrent (in the browser) ```js -var WebTorrent = require('webtorrent') - var client = new WebTorrent() // Sintel, a free, Creative Commons movie @@ -63,10 +61,25 @@ the needed torrent pieces from the network on-demand. ### Creating a new torrent and seed it (in the browser) +This example uses the [`drag-drop`][drag-drop] package, to make the HTML5 Drag and +Drop API easier to work with. + +It works in the browser with [browserify](http://browserify.org). + +``` +npm install drag-drop +``` + +Then use `drag-drop` like this: + ```js var dragDrop = require('drag-drop') -var WebTorrent = require('webtorrent') +``` + +**Note:** If you do not use browserify, use the included standalone file +`dragdrop.min.js`. This exports a `DragDrop` function on `window`. +```js var client = new WebTorrent() // When user drops files on the browser, create a new torrent and start seeding it! @@ -77,9 +90,6 @@ dragDrop('body', function (files) { }) ``` -This example uses the [`drag-drop`][drag-drop] package, to make the HTML5 Drag and -Drop API easier to work with. - ### Download and save a torrent (in Node.js) ```js @@ -88,9 +98,9 @@ var fs = require('fs') var client = new WebTorrent() -var magnetURI = 'magnet:...' +var torrentId = 'magnet:?xt=urn:btih:6a9759bffd5c0af65319979fb7832189f4f3c35d&dn=sintel.mp4&tr=wss%3A%2F%2Ftracker.btorrent.xyz&tr=wss%3A%2F%2Ftracker.fastcast.nz&tr=wss%3A%2F%2Ftracker.openwebtorrent.com&tr=wss%3A%2F%2Ftracker.webtorrent.io&ws=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2Fsintel-1024-surround.mp4' -client.add(magnetURI, function (torrent) { +client.add(torrentId, function (torrent) { torrent.files.forEach(function (file) { console.log('Started saving ' + file.name)