Skip to content

Commit

Permalink
fix: p2p connection does not work
Browse files Browse the repository at this point in the history
  • Loading branch information
ci010 committed Apr 26, 2024
1 parent 064521e commit e516915
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion xmcl-electron-app/plugins/esbuild.native.plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default function createNativeModulePlugin(nodeModules: string): Plugin {

// Intercept node_modules\node-datachannel\lib\index.js
build.onLoad(
{ filter: /^.+node-datachannel[\\/]lib[\\/]index\.js$/g },
{ filter: /^.+node-datachannel[\\/]lib[\\/]index\.c?js$/g },
async ({ path }) => {
return {
contents: `
Expand Down
3 changes: 2 additions & 1 deletion xmcl-keystone-ui/src/views/Multiplayer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@
<MultiplayerDialogInitiate />
<MultiplayerDialogReceive />
<SimpleDialog
v-model="model"
:title="t('multiplayer.disconnected')"
:persistent="false"
:width="400"
Expand Down Expand Up @@ -478,7 +479,7 @@ import MultiplayerDialogReceive from './MultiplayerDialogReceive.vue'
const { show } = useDialog('peer-initiate')
const { show: showShareInstance } = useDialog('share-instance')
const { show: showReceive } = useDialog('peer-receive')
const { show: showDelete, target: deleting, confirm: doDelete } = useSimpleDialog<string>((v) => {
const { show: showDelete, target: deleting, confirm: doDelete, model } = useSimpleDialog<string>((v) => {
if (!v) return
console.log(`drop connection ${v}`)
drop(v)
Expand Down
1 change: 1 addition & 0 deletions xmcl-runtime/iceServers/pluginIceServers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,5 @@ export const pluginIceServers: LauncherAppPlugin = async (app) => {
logger.error(new Error(`Fail to fetch the rtc credential by xbox ${username}. Status ${response.statusCode}.`))
}
}
update()
}
5 changes: 3 additions & 2 deletions xmcl-runtime/nat/NatService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@ export class NatService extends StatefulService<NatState> implements INatService
const servers = p.getIceServers(false)

// randomly pick one
const stun = servers[Math.floor(Math.random() * servers.length)]
const info = await getNatInfoUDP({ stun: { ip: stun.hostname, port: stun.port } })
const ice = servers[Math.floor(Math.random() * servers.length)]
const stun = { ip: ice.hostname, port: ice.port }
const info = await getNatInfoUDP({ stun })
if (info.type !== 'Blocked') {
this.state.natInfoSet(info.externalIp, info.externalPort)
}
Expand Down
3 changes: 2 additions & 1 deletion xmcl-runtime/peer/NodeDataChannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ const url = `https://github.com/murat-dogan/node-datachannel/releases/download/v
export const NodeDataChannelModule = new NativeModuleLoader('node_datachannel.node', () => [url, url], (_, binding) => {
if (!binding) {
// eslint-disable-next-line @typescript-eslint/no-var-requires
return require('node-datachannel') as NodeDataChannel
const mod = require('node-datachannel') as NodeDataChannel
return mod
}
return binding as NodeDataChannel
})
2 changes: 1 addition & 1 deletion xmcl-runtime/util/NativeModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class NativeModuleLoader<T> {
const nativeModule = getDependencyIfExists(root, this.nodeFileName)
const result = this.loader(root, nativeModule)
this.#signal.resolve(result)
} catch {
} catch (e) {
if (this.#retryCount > 3) {
this.#signal.reject(new AnyError('NativeInitError', 'Failed to load ' + this.nodeFileName))
return
Expand Down

0 comments on commit e516915

Please sign in to comment.