From 671882915185d2b4b4b8f13511678f340799db92 Mon Sep 17 00:00:00 2001 From: jc3213 Date: Mon, 19 Aug 2024 10:52:51 +0800 Subject: [PATCH] Update v0.7.0 --- archived/aria2_0.7.0.js | 8 ++++---- aria2.js | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/archived/aria2_0.7.0.js b/archived/aria2_0.7.0.js index c68eb0d..f994e3a 100644 --- a/archived/aria2_0.7.0.js +++ b/archived/aria2_0.7.0.js @@ -2,14 +2,14 @@ class Aria2 { constructor (...args) { let path = args.join('#').match(/^(https?|wss?)(?:#|:\/\/)([^#]+)#?(.*)$/); if (!path) { throw new Error('Invalid JSON-RPC entry: "' + args.join('", "') + '"'); } - this.jsonrpc = {}; - this.timeout = this.retry = 10; this.scheme = path[1]; this.url = path[2]; this.secret = path[3]; + this.retry = this.timeout = 10; this.onmessage = this.onclose = null; } version = '0.7.0'; + jsonrpc = {}; set scheme (scheme) { this.call = { 'http': this.post, 'https': this.post, 'ws': this.send, 'wss': this.send }[ scheme ]; if (!this.call) { throw new Error('Invalid JSON-RPC scheme: "' + scheme + '" is not supported!'); } @@ -36,7 +36,7 @@ class Aria2 { return this.jsonrpc.secret; } set retry (number) { - this.jsonrpc.retry = number; + this.jsonrpc.retry = number === 0 ? Infinity : number; this.jsonrpc.trial = 0; } get retry () { @@ -58,7 +58,7 @@ class Aria2 { response.method ? this.jsonrpc.onmessage(response) : ws.resolve(response); }; ws.onclose = (event) => { - if (!event.wasClean && this.jsonrpc.trial < this.jsonrpc.retry) { console.log(this.jsonrpc.trial); setTimeout(() => this.connect(), this.jsonrpc.timeout); } + if (!event.wasClean && this.jsonrpc.trial < this.jsonrpc.retry) { setTimeout(() => this.connect(), this.jsonrpc.timeout); } this.jsonrpc.onclose(event); this.jsonrpc.trial ++; }; diff --git a/aria2.js b/aria2.js index c68eb0d..f994e3a 100644 --- a/aria2.js +++ b/aria2.js @@ -2,14 +2,14 @@ class Aria2 { constructor (...args) { let path = args.join('#').match(/^(https?|wss?)(?:#|:\/\/)([^#]+)#?(.*)$/); if (!path) { throw new Error('Invalid JSON-RPC entry: "' + args.join('", "') + '"'); } - this.jsonrpc = {}; - this.timeout = this.retry = 10; this.scheme = path[1]; this.url = path[2]; this.secret = path[3]; + this.retry = this.timeout = 10; this.onmessage = this.onclose = null; } version = '0.7.0'; + jsonrpc = {}; set scheme (scheme) { this.call = { 'http': this.post, 'https': this.post, 'ws': this.send, 'wss': this.send }[ scheme ]; if (!this.call) { throw new Error('Invalid JSON-RPC scheme: "' + scheme + '" is not supported!'); } @@ -36,7 +36,7 @@ class Aria2 { return this.jsonrpc.secret; } set retry (number) { - this.jsonrpc.retry = number; + this.jsonrpc.retry = number === 0 ? Infinity : number; this.jsonrpc.trial = 0; } get retry () { @@ -58,7 +58,7 @@ class Aria2 { response.method ? this.jsonrpc.onmessage(response) : ws.resolve(response); }; ws.onclose = (event) => { - if (!event.wasClean && this.jsonrpc.trial < this.jsonrpc.retry) { console.log(this.jsonrpc.trial); setTimeout(() => this.connect(), this.jsonrpc.timeout); } + if (!event.wasClean && this.jsonrpc.trial < this.jsonrpc.retry) { setTimeout(() => this.connect(), this.jsonrpc.timeout); } this.jsonrpc.onclose(event); this.jsonrpc.trial ++; };