diff --git a/api/100J/HBY100-J.js b/api/100J/HBY100-J.js index f470974..a99706e 100644 --- a/api/100J/HBY100-J.js +++ b/api/100J/HBY100-J.js @@ -1121,37 +1121,47 @@ function execWithBleFirst(bleExec, httpExec, logName, onWaiting, opts = {}) { } catch (e) {} }; + // 协议层认为已连:仍可能被系统蓝牙关闭/底层已断而滞后,先校验适配器,避免先发蓝牙卡超时再回退 if (protocolInstance.isBleConnected && protocolInstance.bleDeviceId) { - console.log('[100J] 语音上传:协议层已连接,执行蓝牙传文件'); - return doBle().catch(onBleSendFail); + return getBleAdapterAvailable().then((adapterOk) => { + if (!adapterOk) { + protocolInstance.setBleConnectionStatus(false, ''); + return go4GOrReject('系统蓝牙已关闭,走4G'); + } + console.log('[100J]', logName || '指令', '协议层已连接,走蓝牙'); + return doBle().catch(onBleSendFail); + }); } - console.log('[100J] 语音上传:协议层未就绪,将等待重连或走 4G', { isBleConnected: protocolInstance.isBleConnected, hasBleDeviceId: !!protocolInstance.bleDeviceId }); - // 无 bleDeviceId:系统蓝牙关闭则立即 4G;开启则短时等页面扫描连上(不再白等 12s) + console.log('[100J]', logName || '指令', '协议层未就绪', { isBleConnected: protocolInstance.isBleConnected, hasBleDeviceId: !!protocolInstance.bleDeviceId }); + // 无 bleDeviceId:本地仅蓝牙场景仍弹「请稍候」并等扫描;可走 4G 时不弹 loading、不白等 5s,直接 4G if (!protocolInstance.bleDeviceId) { return getBleAdapterAvailable().then((adapterOk) => { if (!adapterOk) { + protocolInstance.setBleConnectionStatus(false, ''); return go4GOrReject('系统蓝牙未开启,走4G'); } - if (typeof onWaiting === 'function') onWaiting(); - else showWaitUi('请稍候…'); - return waitForBleConnection() - .then((connected) => { - return connected ? doBle().catch(onBleSendFail) : go4GOrReject('蓝牙未连接'); - }) - .finally(hideWaitUi); + if (no4G) { + if (typeof onWaiting === 'function') onWaiting(); + else showWaitUi('请稍候…'); + return waitForBleConnection() + .then((connected) => { + return connected ? doBle().catch(onBleSendFail) : go4GOrReject('蓝牙未连接'); + }) + .finally(hideWaitUi); + } + return waitForBleConnection(0, BLE_POLL_INTERVAL_MS).then((connected) => + connected ? doBle().catch(onBleSendFail) : go4GOrReject('无蓝牙连接,走4G') + ); }); } - // 有 bleDeviceId 但未连:系统蓝牙关则直接 4G,否则短时重连 + // 有 bleDeviceId 但未连:用户刚关蓝牙/超出范围时,不再弹「请稍候」等重连 ~2s,双通道在线时直接 4G return getBleAdapterAvailable().then((adapterOk) => { if (!adapterOk) { + protocolInstance.setBleConnectionStatus(false, ''); return go4GOrReject('系统蓝牙未开启,走4G'); } - if (typeof onWaiting !== 'function') showWaitUi('请稍候…'); - return tryReconnectBle() - .then((reconnected) => { - return reconnected ? doBle().catch(onBleSendFail) : go4GOrReject('蓝牙未连接'); - }) - .finally(hideWaitUi); + console.log('[100J]', logName || '指令', '蓝牙已断开,直接走4G(不阻塞重连)'); + return go4GOrReject(null); }); }