mirror of
https://github.com/cuiocean/ZY-Player.git
synced 2026-02-09 05:33:34 +08:00
增加代理功能,默认使用系统代理设置
This commit is contained in:
@@ -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",
|
||||
@@ -31,10 +32,12 @@
|
||||
"html2canvas": "^1.0.0-rc.7",
|
||||
"iptv-playlist-parser": "^0.5.0",
|
||||
"m3u": "0.0.2",
|
||||
"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",
|
||||
|
||||
@@ -3,8 +3,23 @@ import axios from 'axios'
|
||||
import parser from 'fast-xml-parser'
|
||||
import cheerio from 'cheerio'
|
||||
|
||||
// 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
|
||||
@@ -12,16 +27,6 @@ axios.defaults.retry = 2
|
||||
// 请求的间隙
|
||||
axios.defaults.retryDelay = 1000
|
||||
|
||||
// 添加请求拦截器(配置发送请求的信息)
|
||||
axios.interceptors.request.use(function (config) {
|
||||
// 处理请求之前的配置
|
||||
// 引入代理,播放器代理怎么搞?
|
||||
return config
|
||||
}, function (error) {
|
||||
// 请求失败的处理
|
||||
return Promise.reject(error)
|
||||
})
|
||||
|
||||
// 添加响应拦截器
|
||||
axios.interceptors.response.use(function (response) {
|
||||
// 对响应数据做些事
|
||||
|
||||
Reference in New Issue
Block a user