From 9270a146da2c4e487074c1dc1b3646cf328f3868 Mon Sep 17 00:00:00 2001 From: CommanderRoot Date: Thu, 24 Mar 2022 23:22:10 +0100 Subject: refactor: replace deprecated String.prototype.substr() (#2282) .substr() is deprecated so we replace it with .slice() which works similarily but isn't deprecated Signed-off-by: Tobias Speicher --- index.js | 2 +- lib/file.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 26bf323..31c318b 100644 --- a/index.js +++ b/index.js @@ -214,7 +214,7 @@ class WebTorrent extends EventEmitter { } port.postMessage(chunk) if (!chunk) cleanup() - if (!this.workerKeepAliveInterval) this.workerKeepAliveInterval = setInterval(() => fetch(`${this.serviceWorker.scriptURL.substr(0, this.serviceWorker.scriptURL.lastIndexOf('/') + 1).slice(window.location.origin.length)}webtorrent/keepalive/`), keepAliveTime) + if (!this.workerKeepAliveInterval) this.workerKeepAliveInterval = setInterval(() => fetch(`${this.serviceWorker.scriptURL.slice(0, this.serviceWorker.scriptURL.lastIndexOf('/') + 1).slice(window.location.origin.length)}webtorrent/keepalive/`), keepAliveTime) } else { cleanup() } diff --git a/lib/file.js b/lib/file.js index cbbc484..c5e5f1e 100644 --- a/lib/file.js +++ b/lib/file.js @@ -206,7 +206,7 @@ class File extends EventEmitter { if (typeof window === 'undefined') throw new Error('browser-only method') if (!this._serviceWorker) throw new Error('No worker registered') if (this._serviceWorker.state !== 'activated') throw new Error('Worker isn\'t activated') - const workerPath = this._serviceWorker.scriptURL.substr(0, this._serviceWorker.scriptURL.lastIndexOf('/') + 1).slice(window.location.origin.length) + const workerPath = this._serviceWorker.scriptURL.slice(0, this._serviceWorker.scriptURL.lastIndexOf('/') + 1).slice(window.location.origin.length) const url = `${workerPath}webtorrent/${this._torrent.infoHash}/${encodeURI(this.path)}` cb(null, url) } @@ -215,7 +215,7 @@ class File extends EventEmitter { if (typeof window === 'undefined') throw new Error('browser-only method') if (!this._serviceWorker) throw new Error('No worker registered') if (this._serviceWorker.state !== 'activated') throw new Error('Worker isn\'t activated') - const workerPath = this._serviceWorker.scriptURL.substr(0, this._serviceWorker.scriptURL.lastIndexOf('/') + 1).slice(window.location.origin.length) + const workerPath = this._serviceWorker.scriptURL.slice(0, this._serviceWorker.scriptURL.lastIndexOf('/') + 1).slice(window.location.origin.length) elem.src = `${workerPath}webtorrent/${this._torrent.infoHash}/${encodeURI(this.path)}` cb(null, elem) } -- cgit v1.2.3