From 4136b0f3ce4ac56629cc5b9424dfaa0422d90d6d Mon Sep 17 00:00:00 2001 From: haiyangcui Date: Sun, 8 Nov 2020 00:13:08 +0100 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=90=86=E5=8A=9F=E8=83=BD,=E4=BD=9C?= =?UTF-8?q?=E8=80=85:buvta?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 3 +++ src/lib/site/tools.js | 16 +++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 33da801..d367d95 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ "cors": "^2.8.5", "dexie": "^3.0.2", "electron-localshortcut": "^3.2.1", + "electron-proxy-agent": "^1.2.0", "electron-updater": "^4.3.5", "element-ui": "^2.14.0", "express": "^4.17.1", @@ -32,10 +33,12 @@ "iptv-playlist-parser": "^0.5.0", "m3u": "0.0.2", "m3u8-parser": "^4.5.0", + "memcached": "^2.2.2", "modern-normalize": "^1.0.0", "mousetrap": "^1.6.5", "qrcode.vue": "^1.7.0", "randomstring": "^1.1.5", + "session": "^0.1.0", "v-fit-columns": "^0.2.0", "vue": "^2.6.12", "vue-clickaway": "^2.2.2", diff --git a/src/lib/site/tools.js b/src/lib/site/tools.js index eb005bd..56d4ba7 100644 --- a/src/lib/site/tools.js +++ b/src/lib/site/tools.js @@ -4,9 +4,23 @@ import parser from 'fast-xml-parser' import cheerio from 'cheerio' import { Parser as M3u8Parser } from 'm3u8-parser' +// axios使用系统代理 https://evandontje.com/2020/04/02/automatic-system-proxy-configuration-for-electron-applications/ +// xgplayer使用chromium代理设置,浏览器又默认使用系统代理 https://www.chromium.org/developers/design-documents/network-settings +// 要在设置中添加代理设置,可参考https://stackoverflow.com/questions/37393248/how-connect-to-proxy-in-electron-webview +var http = require('http') +var https = require('http') +const { remote } = require('electron') +var win = remote.getCurrentWindow() +var session = win.webContents.session +var ElectronProxyAgent = require('electron-proxy-agent') + +// use ElectronProxyAgent as http and https globalAgents +http.globalAgent = https.globalAgent = new ElectronProxyAgent(session) + +// axios.get('https://api.my-ip.io/ip').then(res => console.log(res)) // 请求超时时限 -axios.defaults.timeout = 5000 +axios.defaults.timeout = 10000 // 可能使用代理,增长超时 // 重试次数,共请求3次 axios.defaults.retry = 2