Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/webtorrent/webtorrent.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThaUnknown <6506529+ThaUnknown@users.noreply.github.com>2022-08-30 16:26:02 +0300
committerThaUnknown <6506529+ThaUnknown@users.noreply.github.com>2022-08-30 16:26:02 +0300
commit9ae5f177de6b7ba40440740b885098c58229e445 (patch)
tree37cebe7f59fe5d35abcd9fefde26afefcd6b66ab
parenta4bc0c3c5167405d0b93f8f061d9bad3229414fd (diff)
fix: documentation, unity
-rw-r--r--docs/api.md25
-rw-r--r--lib/server.js4
2 files changed, 16 insertions, 13 deletions
diff --git a/docs/api.md b/docs/api.md
index e2bf759..5c7b8f1 100644
--- a/docs/api.md
+++ b/docs/api.md
@@ -273,22 +273,22 @@ Here is a usage example for Node.js:
const client = new WebTorrent()
const magnetURI = 'magnet: ...'
-client.add(magnetURI, function (torrent) {
+const instance = client.createServer()
+instance.server.listen(0) // start the server listening to a port
+// 0 automatically finds an open port instead of forcing a potentially used one
+client.add(magnetURI, torrent => {
// create HTTP server for this torrent
- const instance = torrent.createServer()
- instance.server.listen(port) // start the server listening to a port
const url = torrent.files[0].getStreamURL()
console.log(url)
-
// visit http://localhost:<port>/webtorrent/ to see a list of torrents
// access individual torrents at http://localhost:<port>/webtorrent/<infoHash> where infoHash is the hash of the torrent
-
- // later, cleanup...
- instance.close()
- client.destroy()
})
+
+// later, cleanup...
+instance.close()
+client.destroy()
```
In browser needs either [this worker](https://github.com/webtorrent/webtorrent/blob/master/sw.min.js) to be used, or have [this functionality](https://github.com/webtorrent/webtorrent/blob/master/lib/worker.js) implemented.
@@ -305,14 +305,9 @@ function download (instance) {
client.add(magnetURI, torrent => {
const url = torrent.files[0].getStreamURL()
console.log(url)
-
// visit <origin>/webtorrent/ to see a list of torrents, where origin is the worker registration scope.
// access individual torrents at /webtorrent/<infoHash> where infoHash is the hash of the torrent
-
- // later, cleanup...
- instance.close()
- client.destroy()
})
}
navigator.serviceWorker.register('./sw.min.js', { scope }).then(reg => {
@@ -324,6 +319,10 @@ navigator.serviceWorker.register('./sw.min.js', { scope }).then(reg => {
worker.addEventListener('statechange', ({ target }) => checkState(target))
}
})
+
+// later, cleanup...
+client._server.close()
+client.destroy()
```
# Torrent API
diff --git a/lib/server.js b/lib/server.js
index 1d1bfa8..ed23152 100644
--- a/lib/server.js
+++ b/lib/server.js
@@ -381,6 +381,10 @@ class BrowserServer extends ServerBase {
})
}
+ listen () {
+ // noop for compatibility with node version
+ }
+
close (cb) {
navigator.serviceWorker.removeEventListener('message'.this.wrapRequest.bind(this))
super.close(cb)