mirror of
https://github.com/NoCrypt/migu.git
synced 2026-04-21 08:31:58 +00:00
feat: capacitor NAT traversal
This commit is contained in:
parent
665861b92c
commit
009e26974d
6 changed files with 32 additions and 5 deletions
|
|
@ -44,6 +44,7 @@
|
||||||
"@capacitor/status-bar": "^5.0.6",
|
"@capacitor/status-bar": "^5.0.6",
|
||||||
"@superfrogbe/cordova-plugin-chrome-apps-sockets-udp": "github:superfrogbe/cordova-plugin-chrome-apps-sockets-udp",
|
"@superfrogbe/cordova-plugin-chrome-apps-sockets-udp": "github:superfrogbe/cordova-plugin-chrome-apps-sockets-udp",
|
||||||
"capacitor-dns": "github:funniray/capacitor-dns",
|
"capacitor-dns": "github:funniray/capacitor-dns",
|
||||||
|
"capacitor-os-interfaces-hack": "github:funniray/capacitor-os-interfaces-hack",
|
||||||
"capacitor-plugin-safe-area": "^2.0.5",
|
"capacitor-plugin-safe-area": "^2.0.5",
|
||||||
"common": "workspace:*",
|
"common": "workspace:*",
|
||||||
"cordova-plugin-chrome-apps-common": "^1.0.7",
|
"cordova-plugin-chrome-apps-common": "^1.0.7",
|
||||||
|
|
|
||||||
|
|
@ -93,7 +93,7 @@ class Socket extends EventEmitter {
|
||||||
constructor (options, listener) {
|
constructor (options, listener) {
|
||||||
super()
|
super()
|
||||||
if (typeof options === 'string') options = { type: options }
|
if (typeof options === 'string') options = { type: options }
|
||||||
if (options.type !== 'udp4') throw new Error('Bad socket type specified. Valid types are: udp4')
|
if (options.type !== 'udp4' && options.type !== 'udp6') throw new Error('Bad socket type specified. Valid types are: udp4')
|
||||||
|
|
||||||
if (typeof listener === 'function') this.on('message', listener)
|
if (typeof listener === 'function') this.on('message', listener)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,8 @@ async function portRequest (data) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
await globalThis.controller
|
await globalThis.controller
|
||||||
|
await globalThis.prefetchNetworkInterfaces
|
||||||
|
await new Promise(resolve => setTimeout(() => resolve(), 50))
|
||||||
ipcRendererUI.emit('port', { ports: [port2] })
|
ipcRendererUI.emit('port', { ports: [port2] })
|
||||||
ipcRendererWebTorrent.emit('port', { ports: [port1] })
|
ipcRendererWebTorrent.emit('port', { ports: [port1] })
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import TorrentClient from 'common/modules/webtorrent.js'
|
import TorrentClient from 'common/modules/webtorrent.js'
|
||||||
import { ipcRendererWebTorrent } from './ipc.js'
|
import { ipcRendererWebTorrent } from './ipc.js'
|
||||||
|
import { prefetchNetworkInterfaces } from 'os'
|
||||||
|
|
||||||
globalThis.chrome.runtime = { lastError: false, id: 'something' }
|
globalThis.chrome.runtime = { lastError: false, id: 'something' }
|
||||||
|
|
||||||
|
|
@ -18,6 +19,7 @@ const controller = (async () => {
|
||||||
if (!checkState(worker)) worker.addEventListener('statechange', ({ target }) => checkState(target))
|
if (!checkState(worker)) worker.addEventListener('statechange', ({ target }) => checkState(target))
|
||||||
})
|
})
|
||||||
})()
|
})()
|
||||||
|
globalThis.prefetchNetworkInterfaces = await prefetchNetworkInterfaces()
|
||||||
globalThis.controller = controller
|
globalThis.controller = controller
|
||||||
|
|
||||||
async function storageQuota () {
|
async function storageQuota () {
|
||||||
|
|
@ -25,4 +27,6 @@ async function storageQuota () {
|
||||||
return quota - usage
|
return quota - usage
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await prefetchNetworkInterfaces
|
||||||
|
|
||||||
globalThis.client = new TorrentClient(ipcRendererWebTorrent, storageQuota, 'browser', controller, { torrentPort: Math.floor(Math.random() * 65535 + 1) })
|
globalThis.client = new TorrentClient(ipcRendererWebTorrent, storageQuota, 'browser', controller, { torrentPort: Math.floor(Math.random() * 65535 + 1) })
|
||||||
|
|
|
||||||
|
|
@ -31,10 +31,8 @@ const capacitorConfig = {
|
||||||
}
|
}
|
||||||
const alias = {
|
const alias = {
|
||||||
fs: false,
|
fs: false,
|
||||||
os: false,
|
|
||||||
ws: false,
|
ws: false,
|
||||||
dns: 'capacitor-dns',
|
'default-gateway': false,
|
||||||
'@silentbot1/nat-api': false,
|
|
||||||
'load-ip-set': false,
|
'load-ip-set': false,
|
||||||
'node-fetch': false,
|
'node-fetch': false,
|
||||||
'webtorrent/lib/utp.cjs': false,
|
'webtorrent/lib/utp.cjs': false,
|
||||||
|
|
@ -42,8 +40,12 @@ const alias = {
|
||||||
'@/modules/support.js': join(__dirname, 'src', 'support.js'),
|
'@/modules/support.js': join(__dirname, 'src', 'support.js'),
|
||||||
net: join(__dirname, 'src', 'chrome-net.js'),
|
net: join(__dirname, 'src', 'chrome-net.js'),
|
||||||
dgram: join(__dirname, 'src', 'chrome-dgram.js'),
|
dgram: join(__dirname, 'src', 'chrome-dgram.js'),
|
||||||
|
os: 'capacitor-os-interfaces-hack',
|
||||||
|
dns: 'capacitor-dns',
|
||||||
http: 'stream-http',
|
http: 'stream-http',
|
||||||
https: 'stream-http',
|
https: 'stream-http',
|
||||||
|
'utp-native': false,
|
||||||
|
socks: false,
|
||||||
assert: 'assert',
|
assert: 'assert',
|
||||||
ut_pex: 'ut_pex',
|
ut_pex: 'ut_pex',
|
||||||
path: 'path-esm',
|
path: 'path-esm',
|
||||||
|
|
@ -52,10 +54,14 @@ const alias = {
|
||||||
timers: 'timers-browserify',
|
timers: 'timers-browserify',
|
||||||
crypto: 'crypto-browserify',
|
crypto: 'crypto-browserify',
|
||||||
buffer: 'buffer',
|
buffer: 'buffer',
|
||||||
|
'@silentbot1/nat-api': '@silentbot1/nat-api',
|
||||||
'bittorrent-tracker': 'bittorrent-tracker',
|
'bittorrent-tracker': 'bittorrent-tracker',
|
||||||
querystring: 'querystring',
|
querystring: 'querystring',
|
||||||
zlib: 'webtorrent/polyfills/inflate-sync-web.js',
|
zlib: 'webtorrent/polyfills/inflate-sync-web.js',
|
||||||
|
'bittorrent-tracker/server.js': false,
|
||||||
|
'cross-fetch-ponyfill': resolve('../node_modules/cross-fetch-ponyfill/browser.js'),
|
||||||
|
'abort-controller': false,
|
||||||
'bittorrent-tracker/lib/client/http-tracker.js': resolve('../node_modules/bittorrent-tracker/lib/client/http-tracker.js')
|
'bittorrent-tracker/lib/client/http-tracker.js': resolve('../node_modules/bittorrent-tracker/lib/client/http-tracker.js')
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = merge(commonConfig(__dirname, alias, 'chromeapp', 'index'), capacitorConfig)
|
module.exports = merge(commonConfig(__dirname, alias, 'node', 'index'), capacitorConfig)
|
||||||
|
|
|
||||||
|
|
@ -83,6 +83,9 @@ importers:
|
||||||
capacitor-dns:
|
capacitor-dns:
|
||||||
specifier: github:funniray/capacitor-dns
|
specifier: github:funniray/capacitor-dns
|
||||||
version: github.com/funniray/capacitor-dns/6362cd1ad0a6b9b5bdbdc9fee3fba4c8dae91e16(@capacitor/core@5.5.1)
|
version: github.com/funniray/capacitor-dns/6362cd1ad0a6b9b5bdbdc9fee3fba4c8dae91e16(@capacitor/core@5.5.1)
|
||||||
|
capacitor-os-interfaces-hack:
|
||||||
|
specifier: github:funniray/capacitor-os-interfaces-hack
|
||||||
|
version: github.com/funniray/capacitor-os-interfaces-hack/95a51afe9dee88b3ae8df4b1b96fd106c1655954(@capacitor/core@5.5.1)
|
||||||
capacitor-plugin-safe-area:
|
capacitor-plugin-safe-area:
|
||||||
specifier: ^2.0.5
|
specifier: ^2.0.5
|
||||||
version: 2.0.5(@capacitor/core@5.5.1)
|
version: 2.0.5(@capacitor/core@5.5.1)
|
||||||
|
|
@ -8310,6 +8313,17 @@ packages:
|
||||||
'@capacitor/core': 5.5.1
|
'@capacitor/core': 5.5.1
|
||||||
dev: false
|
dev: false
|
||||||
|
|
||||||
|
github.com/funniray/capacitor-os-interfaces-hack/95a51afe9dee88b3ae8df4b1b96fd106c1655954(@capacitor/core@5.5.1):
|
||||||
|
resolution: {tarball: https://codeload.github.com/funniray/capacitor-os-interfaces-hack/tar.gz/95a51afe9dee88b3ae8df4b1b96fd106c1655954}
|
||||||
|
id: github.com/funniray/capacitor-os-interfaces-hack/95a51afe9dee88b3ae8df4b1b96fd106c1655954
|
||||||
|
name: capacitor-os-interfaces-hack
|
||||||
|
version: 0.0.1
|
||||||
|
peerDependencies:
|
||||||
|
'@capacitor/core': ^5.0.0
|
||||||
|
dependencies:
|
||||||
|
'@capacitor/core': 5.5.1
|
||||||
|
dev: false
|
||||||
|
|
||||||
github.com/superfrogbe/cordova-plugin-chrome-apps-sockets-udp/4b740017299c81cfc7d5b49c7d6122a6650b57d4:
|
github.com/superfrogbe/cordova-plugin-chrome-apps-sockets-udp/4b740017299c81cfc7d5b49c7d6122a6650b57d4:
|
||||||
resolution: {tarball: https://codeload.github.com/superfrogbe/cordova-plugin-chrome-apps-sockets-udp/tar.gz/4b740017299c81cfc7d5b49c7d6122a6650b57d4}
|
resolution: {tarball: https://codeload.github.com/superfrogbe/cordova-plugin-chrome-apps-sockets-udp/tar.gz/4b740017299c81cfc7d5b49c7d6122a6650b57d4}
|
||||||
name: '@superfrogbe/cordova-plugin-chrome-apps-sockets-udp'
|
name: '@superfrogbe/cordova-plugin-chrome-apps-sockets-udp'
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue