Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upFeature Request: state object #872
Comments
This comment has been minimized.
This comment has been minimized.
|
This seems reasonable. It will definitely simplify things in A few suggestions:
|
This comment has been minimized.
This comment has been minimized.
|
I don't know what selections are. It sounds like they are what implement piece priority and file select/deselect behind the scenes? |
This comment has been minimized.
This comment has been minimized.
|
Yes, selections are how ranges of bytes in the torrent are prioritized behind-the-scenes. It's basically an array of objects that specify Unless I'm missing something, I don't think I'm not sure exactly what's right to do here, but I think that storing the full selections array has some big downsides. For one, it doesn't make sense to persist the particular part of the video that the user was watching in WebTorrent Desktop when the app was quit. As a first pass, what about if we just persist calls to |
This comment has been minimized.
This comment has been minimized.
|
@dcposch Do you have thoughts on the design of this? |
This comment has been minimized.
This comment has been minimized.
|
Ah, understood, then yes I'm +1 on only persisting file state for now. Every application will probably have its own way of prioritizing/deprioritizing pieces that need to be downloaded, so it might make sense to leave persisting that logic to the application entirely. |
This comment has been minimized.
This comment has been minimized.
|
Shouldn't DHT nodes be persisted as well? According to bittorrent-dht docs:
|
This is an attempt to standardize how applications resume a WebTorrent
clientafter a restart.WebTorrent Desktop is manually doing a subset of this already: webtorrent/webtorrent-desktop#46
This proposal introduces the
stateobject. This object contains the subset of aclients state necessary to create a newclientdownloading the same torrent files in the same way.I would be happy to do the legwork of implementing this if it seems like a sane thing to do.
I'd like to make the following API additions:
Client API
client = new WebTorrent([opts])
Create a new
WebTorrentinstance.If
optsis specified, then the default options (shown below) will be overridden.{ dht: Boolean|Object, // Enable DHT (default=true), or options object for DHT maxConns: Number, // Max number of connections per torrent (default=55) nodeId: String|Buffer, // DHT protocol node ID (default=randomly generated) peerId: String|Buffer, // Wire protocol peer ID (default=randomly generated) tracker: Boolean|Object, // Enable trackers (default=true), or options object for Tracker state: Object // Start WebTorrent in the supplied state (default = null) }For possible values of
opts.dhtsee thebittorrent-dhtdocumentation.For possible values of
opts.trackersee thebittorrent-trackerdocumentation.client.getState()Returns the
stateof theclient.client.on('state', function(state) {})Emitted whenever a client's state object is updated.
State API
State is an object that reflects the state of a WebTorrent
client. This object can be used to construct a new WebTorrentclient.state.torrentsA list of all torrents being tracked by the client
state.torrents[i].filesAll files inside of a torrent.
nullif we don't yet know the files. This isn't enforced in any way when supplied to theclientconstructor as an option but is used to set the state of the files in a torrent if they match any of the files in this list.state.torrents[i].files[i].selectedIs this file being downloaded?
state.torrents[i].files[i].nameThe name of the file, as specified by the torrent.
state.torrents[i].files[i].pathThe path of the file, as specified by the torrent.
state.torrents[i].piecesAll the pieces inside of a torrent.
nullif we don't yet know how many pieces there are. This isn't enforced in any way when supplied to theclientconstructor as an option, but is used to set the state of pieces in a torrent if they match any of the pieces in this list.state.torrents[i].pieces[i].priorityThe priority of the torrent piece.
state.torrents[i].pathThe path that the torrent is being downloaded to.
state.torrents[i].torrentIdA torrent file if known, otherwise an infohash.
state.torrents[i].pausedWhether or not a torrent is currently paused.