20 releases
new 0.1.19 | May 12, 2025 |
---|---|
0.1.18 | May 12, 2025 |
#1467 in Network programming
241 downloads per month
14KB
219 lines
WebTorrent Rust WebAssembly Wrapper
This project is a WebAssembly (WASM) wrapper for WebTorrent implemented in Rust. It allows you to create a browser-based file sharing application using WebTorrent functionality, with the core logic written in Rust.
Features
- Share files via WebTorrent using a magnet URI
- Download files from peers via WebTorrent in the browser
- Displays file progress and peers count during downloads
Prerequisites
- Rust installed on your system (Make sure to install Rust via
rustup
if you haven't already) wasm-pack
installed (Install it viacargo install wasm-pack
)- Python installed for serving the HTML page
Setup
1. Clone the Repository
Clone the repository to your local machine:
git clone https://github.com/anchalshivank/webtorrent-rs-wrapper.git
cd webtorrent-rs-wrapper
2. Install Dependencies
Install the necessary dependencies:
cargo install wasm-pack
3. Build the Project
Run the following commands to build the WebAssembly binary:
# Clean any previous builds
cargo clean
# Build the project for the WebAssembly target (web)
wasm-pack build --target web
4. Serve the Application
To view the application, you need to serve the generated index.html
in a local server. You can use Python's built-in HTTP server:
python3 -m http.server 8080
5. Open in a Browser
Once the server is running, open your browser and go to http://localhost:8080
. The application will allow you to upload and share files, or download files from other peers.
Build Script (Optional)
If you have a build.sh
script for automating the build process, make sure to grant it execute permissions by running:
chmod +x ./build.sh
You can then execute the script with the following:
./build.sh
This will run the necessary build steps for the project.
Project Structure
src/
: Contains the Rust source code for the WebTorrent wrapperpkg/
: Contains the generated WebAssembly packageindex.html
: The HTML file for the browser-based file-sharing app
Troubleshooting
- Ensure you have all the necessary dependencies installed, including
wasm-pack
, Rust, and Python. - If you encounter issues related to missing files (e.g.,
package.json
), make sure the required files are present in the directory.
Contributing
Feel free to contribute by opening issues or pull requests. Contributions are welcome!
License
This project is licensed under the MIT License - see the LICENSE file for details.
Dependencies
~8–11MB
~187K SLoC