Skip to content

Commit

Permalink
Make new socket for every download to avoid socket expiration
Browse files Browse the repository at this point in the history
  • Loading branch information
BilawalAhmed0900 committed Jul 13, 2020
1 parent 9524d3f commit 8822595
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
16 changes: 13 additions & 3 deletions background.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const sUsrAg = window.navigator.userAgent;
const isFirefox = (sUsrAg.indexOf("Chrome") === -1);
const browserVar = (!isFirefox) ? chrome : browser;
const socket = new WebSocket("ws://127.0.0.1:49152");
var socket = null;
const toDownloadMime = [
"application/f4m+xml",
"application/gzip",
Expand Down Expand Up @@ -59,7 +59,13 @@ function sendUsingCookies(downloadItem, cookies, isAudio, isVideo, isExecutable)
"referrer": downloadItem.referrer || "", "fileSize": downloadItem.fileSize, "mime": downloadItem.mime,
"cookies": cookiesString, "youtubeLink": false, "isAudio": isAudio, "isVideo": isVideo, "isExecutable": isExecutable,
"userAgent": sUsrAg});
socket.send(toBeSent);
let socket = new WebSocket("ws://127.0.0.1:49152");
socket.addEventListener("open", (e) =>
{
socket.send(toBeSent);
socket.close();
socket = null;
});
}

function updater_function(downloadItem)
Expand All @@ -74,7 +80,7 @@ function updater_function(downloadItem)

const audioFound = (audioRegex.exec(downloadItem.mime) != null);
const videoFound = (videoRegex.exec(downloadItem.mime) != null);
if ((socket.readyState === 1 && downloadItem.url !== "" && downloadItem.url.indexOf("ftp://") === -1 && downloadItem.url.indexOf("blob:") === -1) &&
if ((downloadItem.url !== "" && downloadItem.url.indexOf("ftp://") === -1 && downloadItem.url.indexOf("blob:") === -1) &&
(toDownloadMime.indexOf(downloadItem.mime) > -1 || audioFound || videoFound))
{
browserVar.downloads.cancel(downloadItem.id);
Expand Down Expand Up @@ -156,3 +162,7 @@ if (!isFirefox)
});
}

window.addEventListener('online', (e) =>
{
socket = new WebSocket("ws://127.0.0.1:49152");
});
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "LinkDownloader Extension",
"version": "1.7.5",
"version": "1.8.0",
"description": "Extension for LinkDownloader!",
"permissions": [
"cookies",
Expand Down

0 comments on commit 8822595

Please sign in to comment.