diff --git a/dist/dsh-watch-0.1.0.tgz b/dist/dsh-watch-0.1.0.tgz index 596f2b9..2a19614 100644 Binary files a/dist/dsh-watch-0.1.0.tgz and b/dist/dsh-watch-0.1.0.tgz differ diff --git a/lib/index.js b/lib/index.js index 6487028..a6cef05 100644 --- a/lib/index.js +++ b/lib/index.js @@ -106,6 +106,48 @@ function apply(ctx, config) { }; } + async function harnessDiscover() { + const out = {}; + if (!api) return { error: 'apiProxy unavailable' }; + for (const domain of Object.keys(api)) { + const d = api[domain]; + const methods = []; + if (d) { + for (const k of Object.keys(d)) { + if (typeof d[k] === 'function') methods.push(k); + } + } + out[domain] = methods.sort(); + } + return { domains: out }; + } + + async function harnessPair(params) { + // 尝试常见命名:取到主电脑的设备配对链接,供手机端自动完成配对 + const candidates = [ + ['remote', 'createPairingLink'], + ['remote', 'createDeviceLink'], + ['remote', 'pair'], + ['device', 'createPairingLink'], + ['device', 'pair'], + ['remote', 'deviceLink'], + ['pairing', 'createLink'] + ]; + const errors = []; + for (const [domain, method] of candidates) { + try { + const d = api && api[domain]; + if (d && typeof d[method] === 'function') { + const res = await d[method](params || {}); + return { domain, method, result: res }; + } + } catch (e) { + errors.push(domain + '.' + method + ': ' + (e && e.message || e)); + } + } + throw new Error('无可用配对接口: ' + (errors.join(' | ') || 'unknown')); + } + async function sessionList() { const status = await computeStatus(); return { @@ -135,6 +177,8 @@ function apply(ctx, config) { if (method === 'harness.balance') return harnessBalance(); if (method === 'session.list') return sessionList(); if (method === 'session.history') return sessionHistory(params); + if (method === 'harness.discover') return harnessDiscover(); + if (method === 'harness.pair') return harnessPair(params); const dot = method.indexOf('.'); if (dot <= 0) throw new Error('unknown method ' + method); const domain = method.slice(0, dot);