Skip to content

Commit

Permalink
refactor: refactor WebSocket options handling in surge and surfboard …
Browse files Browse the repository at this point in the history
…utils
  • Loading branch information
geekdada committed Mar 5, 2024
1 parent a5f59e9 commit 84aff5d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 35 deletions.
32 changes: 12 additions & 20 deletions src/utils/__tests__/surge.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,12 @@ test('getSurgeNodes', async (t) => {
method: 'auto',
network: 'ws',
nodeName: '测试 3',
path: '/',
port: 8080,
tls: false,
host: '',
uuid: '1386f85e-657b-4d6e-9d56-78badb75e1fd',
binPath: '/usr/local/bin/v2ray',
localPort: 61101,
wsOpts: {
path: '/',
},
},
{
type: NodeTypeEnum.Vmess,
Expand All @@ -79,13 +78,12 @@ test('getSurgeNodes', async (t) => {
method: 'auto',
network: 'ws',
nodeName: '测试 4',
path: '/',
port: 8080,
tls: true,
host: '',
uuid: '1386f85e-657b-4d6e-9d56-78badb75e1fd',
binPath: '/usr/local/bin/v2ray',
localPort: 61101,
wsOpts: {
path: '/',
},
},
{
type: NodeTypeEnum.Vmess,
Expand All @@ -94,13 +92,9 @@ test('getSurgeNodes', async (t) => {
method: 'aes-128-gcm',
network: 'tcp',
nodeName: '测试 5',
path: '/',
port: 8080,
tls: false,
host: '',
uuid: '1386f85e-657b-4d6e-9d56-78badb75e1fd',
binPath: '/usr/local/bin/v2ray',
localPort: 61101,
},
{
nodeName: 'Test Node 4',
Expand Down Expand Up @@ -148,17 +142,16 @@ test('getSurgeNodes', async (t) => {
method: 'auto',
network: 'ws',
nodeName: '测试 6',
path: '/',
port: 8080,
tls: true,
tls13: true,
skipCertVerify: true,
host: '',
uuid: '1386f85e-657b-4d6e-9d56-78badb75e1fd',
binPath: '/usr/local/bin/v2ray',
localPort: 61101,
tfo: true,
mptcp: true,
wsOpts: {
path: '/',
},
},
{
type: NodeTypeEnum.Vmess,
Expand All @@ -167,18 +160,17 @@ test('getSurgeNodes', async (t) => {
method: 'auto',
network: 'ws',
nodeName: '测试 7',
path: '/',
port: 8080,
tls: true,
tls13: true,
skipCertVerify: true,
host: '',
uuid: '1386f85e-657b-4d6e-9d56-78badb75e1fd',
binPath: '/usr/local/bin/v2ray',
localPort: 61101,
tfo: true,
mptcp: true,
underlyingProxy: 'another-proxy',
wsOpts: {
path: '/',
},
},
]
const txt1 = surge.getSurgeNodes(nodeList).split('\n')
Expand Down
4 changes: 1 addition & 3 deletions src/utils/surfboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,7 @@ function nodeListMapper(
if (nodeConfig.network === 'ws') {
result.push('ws=true')

if (nodeConfig.wsOpts) {
result.push(`ws-path=${nodeConfig.wsOpts.path}`)
}
result.push(`ws-path=${nodeConfig.wsOpts?.path || '/'}`)

result.push(
'ws-headers=' +
Expand Down
22 changes: 10 additions & 12 deletions src/utils/surge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,18 +318,16 @@ function nodeListMapper(
if (nodeConfig.network === 'ws') {
result.push('ws=true')

if (nodeConfig.wsOpts) {
result.push(`ws-path=${nodeConfig.wsOpts.path}`)
result.push(
'ws-headers=' +
JSON.stringify(
getSurgeExtendHeaders({
'user-agent': OBFS_UA,
...nodeConfig.wsOpts.headers,
}),
),
)
}
result.push(`ws-path=${nodeConfig.wsOpts?.path || '/'}`)
result.push(
'ws-headers=' +
JSON.stringify(
getSurgeExtendHeaders({
'user-agent': OBFS_UA,
...nodeConfig.wsOpts?.headers,
}),
),
)
}

if (nodeConfig.tls) {
Expand Down

0 comments on commit 84aff5d

Please sign in to comment.