Skip to content

Commit

Permalink
fix rebind
Browse files Browse the repository at this point in the history
  • Loading branch information
David authored and David committed Nov 3, 2024
1 parent 9deec93 commit c41eae6
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ Adds a hook that allows mpv to stream torrents using [webtorrent](https://github
Run `webtorrent-mpv-hook` for instructions.
You only need to do this once.

## Update

`npm update --global webtorrent-mpv-hook`

## Usage

`mpv <torrent-id>`
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "webtorrent-mpv-hook",
"version": "1.4.4",
"version": "1.4.5",
"description": "Adds a hook that allows mpv to stream torrents",
"license": "Unlicense",
"repository": {
Expand Down
8 changes: 7 additions & 1 deletion src/webtorrent.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ declare module 'webtorrent' {
server: net.Server;
listen(port: number): void;
close(cb: () => void): void;
destroy(cb?: () => void): void;
}
interface Instance {
createServer(): Server;
_server: Server | undefined;
}
interface TorrentFile {
offset: number;
Expand Down Expand Up @@ -105,12 +107,16 @@ const torrent = client.add(options.torrentId, {
torrent.on('infoHash', () => log('Info hash:', torrent.infoHash));
torrent.on('metadata', () => log('Metadata downloaded'));

const server = client.createServer();
let server = client.createServer();
server.server.on('error', serverError);
server.listen(options.port);

function serverError(err: NodeJS.ErrnoException): void {
if (err.code === 'EADDRINUSE' || err.code === 'EACCES') {
server.destroy();
client._server = undefined;
server = client.createServer();
server.server.on('error', serverError);
server.listen(0);
return;
}
Expand Down

0 comments on commit c41eae6

Please sign in to comment.