From 368becd078dc51deda191b3c0036505f9d46e0f8 Mon Sep 17 00:00:00 2001 From: H3CoF6 <1707889225@qq.com> Date: Wed, 30 Sep 2026 13:55:47 +0800 Subject: [PATCH] fix(protocol): don't send bytesGeneralFlags on private voice (#495) Private-chat voice bubbles arrived without a waveform: the NapCat-derived 14-byte c2c bytesGeneralFlags blob suppresses it. A/B testing that single field (everything else byte-identical) shows the receiver drops the shipped waveform while it is present and draws the bars as soon as it is gone, so c2c now sends no flags at all. Group voice keeps its 10-byte blob unchanged. --- packages/core/tests/highway/ptt-upload.test.ts | 16 ++++++++++------ packages/protocol/src/highway/ptt-upload.ts | 18 +++++++++++++----- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/packages/core/tests/highway/ptt-upload.test.ts b/packages/core/tests/highway/ptt-upload.test.ts index 3b53864f..d902b6f9 100644 --- a/packages/core/tests/highway/ptt-upload.test.ts +++ b/packages/core/tests/highway/ptt-upload.test.ts @@ -2,8 +2,8 @@ // regular load path goes through ffmpeg's silk encoder + the OS temp // directory, which we don't want to exercise in a unit test. The // fingerprint path covers most of what makes ptt-upload distinct -// (group/c2c requestId difference, command id mapping, NapCat-style -// bytesGeneralFlags, voiceFormat honouring). +// (group/c2c requestId difference, command id mapping, the group-only +// bytesGeneralFlags blob, voiceFormat honouring). import { describe, it, expect, vi, beforeEach } from 'vitest'; @@ -45,7 +45,7 @@ describe('ptt-upload', () => { ); }); - it('c2c: 0x126D_100 + PRIVATE_PTT_CMD_ID + requestId=4 + c2c-flavored flags', async () => { + it('c2c: 0x126D_100 + PRIVATE_PTT_CMD_ID + requestId=4 + no generalFlags', async () => { await uploadPttMsgInfo({} as any, false, 'recipient-uid', FINGERPRINT); const args = vi.mocked(pipeline.runNtv2Upload).mock.calls[0]![0]; expect(args.oidbCmd).toBe(0x126D); @@ -53,10 +53,14 @@ describe('ptt-upload', () => { expect(args.requestId).toBe(4); expect(args.uploads[0]!.cmdId).toBe(PRIVATE_PTT_CMD_ID); - const c2cFlags = (args.extBizInfo as any).ptt.bytesGeneralFlags; - expect(c2cFlags.length).toBe(14); - expect(c2cFlags[0]).toBe(0x9a); + // Private voice must not carry a generalFlags blob: with the NapCat c2c + // one present the receiver drops the progress bar even though the waveform + // is in the payload. Group keeps its 10-byte blob (covered above). + expect((args.extBizInfo as any).ptt.bytesGeneralFlags).toBeUndefined(); expect((args.extBizInfo as any).ptt.waveform).toBeUndefined(); + + // Reserve stays the bare legacy 4 bytes, same as group voice. + expect([...(args.extBizInfo as any).ptt.bytesReserve]).toEqual([0x08, 0x00, 0x38, 0x00]); }); it('fingerprint path does not invent a waveform', async () => { diff --git a/packages/protocol/src/highway/ptt-upload.ts b/packages/protocol/src/highway/ptt-upload.ts index a92f6a75..187ea396 100644 --- a/packages/protocol/src/highway/ptt-upload.ts +++ b/packages/protocol/src/highway/ptt-upload.ts @@ -219,11 +219,19 @@ export async function uploadPttMsgInfo( ptt: { bytesReserve: new Uint8Array([0x08, 0x00, 0x38, 0x00]), bytesPbReserve: new Uint8Array(0), - // `bytesGeneralFlags` differs between group / c2c voice. Lifted - // verbatim from NapCat (UploadGroupPtt.ts / UploadPrivatePtt.ts). - bytesGeneralFlags: isGroup - ? new Uint8Array([0x9a, 0x01, 0x07, 0xaa, 0x03, 0x04, 0x08, 0x08, 0x12, 0x00]) - : new Uint8Array([0x9a, 0x01, 0x0b, 0xaa, 0x03, 0x08, 0x08, 0x04, 0x12, 0x04, 0x00, 0x00, 0x00, 0x00]), + // `bytesGeneralFlags` is the group blob lifted verbatim from NapCat + // (UploadGroupPtt.ts). Private chat must send **none**: with the + // NapCat c2c blob (UploadPrivatePtt.ts) present the receiving client + // draws the voice bubble without its progress bar, and the waveform + // we ship is silently dropped. Confirmed by A/B-ing this single field + // against an otherwise identical send (present → flat, absent → drawn). + ...(isGroup + ? { + bytesGeneralFlags: new Uint8Array([ + 0x9a, 0x01, 0x07, 0xaa, 0x03, 0x04, 0x08, 0x08, 0x12, 0x00, + ]), + } + : {}), ...(ptt.waveform ? { waveform: ptt.waveform } : {}), }, },