- Socket emits are shown with the path in bold in the beginning
- Name is after that
- Sub points contain the payload
- Two users are connected.
- Calling them user1 and user2.
- user1 wants to send a file to user2
- user1 has selected a file and user2 approved the file request
- Torrent clients are created for both user1 and user2 (through
new Client, Client is a custom class)- The WebRTC config is passed to these clients
- user1's client starts seeding the file
- TRACKERS are passed here
- When torrent is ready (
client.on('torrent'..))- user1 to server fileReady
- torrent.magnetURI
- server to user2 addTorrent
- torrent.magnetURI
- user1 to server fileReady
- user2 on getting addTorrent:
client.add (magnetURI)(Also announces to tracker)- Also add ontorrent callback to previous function to show progress
- user2 on completing download:
- user2 to server downloadComplete
- server to user1 torrentDone
- On receiving 'torrentDone', user1 calls
torrent.destroy()to stop seeding.
- Client class is also an EventEmitter and has the following emits:
- error
- err: string | Error
- upload (Emitted whenever new packets are uploaded, for showing upload stats)
- uploaded: string (formatted as '20 MB' for example)
- uploadSpeed: string (formatted as '4 MB/s' for example)
- download (Emitted whenever new packets are downloaded, for showing download stats) (Note: these have same format as above)
- downloaded: string
- downloadSpeed: string
- progress: number (between 0 and 1)
- downloadComplete
- url: string (Downloaded file's BlobURL)
- torrentDestroyed (the torrent that was downloading/seeding was destroyed)
- clientDestroyed (WebTorrent client was destroyed, possibly due to some error)
- error
- Misc:
- torrent.timeRemaining can used to show user2 the time remaining for download to complete
- torrent.downloaded shows how much was downloaded
- torrent.uploaded can be used to show user1 how much progress has been made (can't be used if onetomany is required)
- On download completion, for both user1 and user2:
- client.remove(torrent) Docs claim it removes all saved data, so will have to check to what extent it deletes stuff