Git Product home page Git Product logo

webtorrent-remote's Introduction

webtorrent-remote npm downloads javascript style guide

run WebTorrent in one process, control it from another process or even another machine.

plain Javascript, no es6

server process

var WebTorrentRemoteServer = require('webtorrent-remote/server')

var opts = null
var server = new WebTorrentRemoteServer(send, opts)

function send (message) {
  // Send `message` to the correct client. It's JSON serializable.
  // Use TCP, some kind of IPC, whatever.
  // If there are multiple clients, look at message.clientKey
}

// When messages come back from the IPC channel, call:
server.receive(message)

server options

opts.heartbeatTimeout

remove clients if we don't hear a heartbeat for this many milliseconds. default 30000 (30 seconds). set to 0 to disable the heartbeat check. once a torrent has no remaining clients, it will be removed. once there are no remaining torrents, the whole webtorrent instance will be destroyed. the webtorrent instance is created lazily the first time a client calls add().

opts.updateInterval

send progress updates every x milliseconds to all clients of all torrents. default 1000 (1 second). set to 0 to disable progress updates.

other options

all WebTorrent options. the options object is passed to the constructor for the underlying WebTorrent instance.

debugging

This package uses debug for debug logging. Set the environment variable DEBUG=webtorrent-remote for detailed debug logs.

client process(es)

var WebTorrentRemoteClient = require('webtorrent-remote/client')

var opts = null
var client = new WebTorrentRemoteClient(send, opts)

function send (message) {
  // Same as above, except send the message to the server process
}

// When messages come back from the server, call:
client.receive(message)

// Now `client` is a drop-in replacement for the normal WebTorrent object!
var torrentId = 'magnet:?xt=urn:btih:6a9759bffd5c0af65319979fb7832189f4f3c35d'
client.add(torrentId, function (err, torrent) {
  torrent.on('metadata', function () {
    console.log(JSON.stringify(torrent.files))
    // Prints [{name:'sintel.mp4'}]
  })

  var server = torrent.createServer()
  server.listen(function () {
    console.log('http://localhost:' + server.address().port)
    // Paste that into your browser to stream Sintel!
  })
})

client options

opts.heartbeat

send a heartbeat once every x milliseconds. default 5000 (5 seconds). set to 0 to disable heartbeats.

client methods

client.add(torrentID, [options], callback)

like WebTorrent.add, but only async. calls back with (err, torrent). The torrent is a torrent object (see below for methods).

client.get(torrentID, callback)

like WebTorrent.get, but async. calls back with (err, torrent). if the torrentId is not yet in the client, err.name will be 'TorrentMissingError'.

client.destroy()

like WebTorrent.destroy, but destroys only this client. if a given torrent has no clients left, it will be destroyed too. if all torrents are gone, the whole WebTorrent instance will be destroyed on the server side.

client events, from webtorrent

  • client.on('error', () => {...})
  • client.on('warning', () => {...})

torrent methods

the client gives you a torrent object in the callback to get or add. this supports a subset of the WebTorrent API, forwarding commands to the WebTorrentRemoteServer and emitting events:

torrent.createServer()

create a local torrent-to-HTTP streaming server.

torrent events, unique to webtorrent-remote, not in webtorrent

  • torrent.on('update', () => {...}): fires periodically, see updateInterval

torrent events, from webtorrent

  • torrent.on('infohash', () => {...})
  • torrent.on('metadata', () => {...})
  • torrent.on('download', () => {...})
  • torrent.on('upload', () => {...})
  • torrent.on('done', () => {...})
  • torrent.on('error', () => {...})
  • torrent.on('warning', () => {...})

torrent props unique to webtorrent-remote, not in webtorrent

  • torrent.client: the WebTorrentRemoteClient
  • torrent.key: the clientKey used for messaging

torrent props, from webtorrent (updated once on infohash or metadata)

  • torrent.infoHash
  • torrent.name
  • torrent.length
  • torrent.files

torrent props, from webtorrent (updated on every progress event)

  • torrent.progress
  • torrent.downloaded
  • torrent.uploaded
  • torrent.downloadSpeed
  • torrent.uploadSpeed
  • torrent.numPeers
  • torrent.progress
  • torrent.timeRemaining

server methods

server.address()

gets an address object like { address: '::', family: 'IPv6', port: 52505 } that shows what host and port the server is listening on.

server.listen(onlistening)

tells the server to start listening. the onlistening function is called when the server starts listening.

server events

  • server.on('listening', () => {...})

webtorrent-remote's People

Contributors

dcposch avatar diegorbaquero avatar diracdeltas avatar feross avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

webtorrent-remote's Issues

Release 1.0.0

Hey @dcposch,

What do you think about releasing this as 1.0.0?

These days, it's common to start all but the most experimental packages off at 1.0.0 instead of 0.0.0.

The semver operators ^ and ~ behave weirdly below 1.0.0, making it hard for dependents like Brave to automatically inherit minor and patch versions without constantly bumping their package.json.

What do you say?

Clarify usage instructions

Hello,
Thanks for setting this up. It seems to be a useful way of using webtorrent remotely.
However, after reading the instructions in the README I'm not able to figure out how exactly to use this package.
I would like to set up a remote webtorrent process on a server and be able to access it from a local client. So far, I haven't figured out where I should specify options such as the server URL so that I can connect to the remote webtorrent process, and where I should include that info in the client so that it knows to connect to the correct server.

I'm not sure if this is the correct place to ask this, but I would really appreciate some clarification.
Thanks in advance.

Add a server as an executable

Like in, $ webtorrent-server -p 8000. It can be JSON-RPC, or whatever. Just to establish a standard way to communicate with webtorrent-remote from other processes; those who want can just set up their own communication channel like they would do now. What do you think?

I'm working on a Python client right now, by the way.

Support file.createReadStream()

Would it be feasible to support file.createReadStream()?

The torrent.createServer() only works on environments that can bind to a local port and not browser or mobile. So for those there is no way to stream a file.

file.createReadStream() could be supported by creating a proxy stream on the client that would invoke/mirror calls on the server. It could be static support just the necessary events and methods to read the stream or could use Proxy() to support every Stream method.

Client not emitting events

Thanks for writing this utility ๐Ÿ˜„

I'm not able to get the example working since torrent never fires events on the client besides error and warning. I can PR my current fork if it's not something you're already working on.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.