feat(ui-flow): voice/display trace bytes and request-stage-speak IPC
Aggregate voice-capture bytes and display-capture frame counts at trace when PEARCORD_LOG_VOICE_CAPTURE_TRACE=1, and surface request-stage-speak capacity errors to the UI like join-stage. Co-authored-by: Cursor <[email protected]>
This commit is contained in:
@@ -7,6 +7,8 @@ const { USER_STATUS } = require('pearcord-platform')
|
||||
const flowLog = createLogger('ui-flow')
|
||||
|
||||
let voiceCaptureChunkCount = 0
|
||||
let voiceCaptureBytes = 0
|
||||
let displayCaptureFrameCount = 0
|
||||
|
||||
function fromBase64 (str) {
|
||||
if (typeof Buffer !== 'undefined') return Buffer.from(str || '', 'base64')
|
||||
@@ -423,16 +425,32 @@ async function dispatchUiMessage (platform, msg, hooks = {}) {
|
||||
}
|
||||
if (t === 'voice-capture-chunk') {
|
||||
voiceCaptureChunkCount++
|
||||
const chunk = msg.data
|
||||
if (chunk) {
|
||||
if (typeof chunk === 'string') voiceCaptureBytes += chunk.length
|
||||
else if (chunk.byteLength != null) voiceCaptureBytes += chunk.byteLength
|
||||
else if (chunk.length != null) voiceCaptureBytes += chunk.length
|
||||
}
|
||||
if (
|
||||
process.env.PEARCORD_LOG_VOICE_CAPTURE_TRACE === '1' &&
|
||||
voiceCaptureChunkCount % 200 === 0
|
||||
) {
|
||||
log.trace('voice-capture chunks', { count: voiceCaptureChunkCount })
|
||||
log.trace('voice-capture chunks', {
|
||||
count: voiceCaptureChunkCount,
|
||||
bytes: voiceCaptureBytes
|
||||
})
|
||||
}
|
||||
platform.ingestVoiceCapture(msg.data)
|
||||
return true
|
||||
}
|
||||
if (t === 'display-capture-frame') {
|
||||
displayCaptureFrameCount++
|
||||
if (
|
||||
process.env.PEARCORD_LOG_VOICE_CAPTURE_TRACE === '1' &&
|
||||
displayCaptureFrameCount % 200 === 0
|
||||
) {
|
||||
log.trace('display-capture frames', { count: displayCaptureFrameCount })
|
||||
}
|
||||
platform.ingestDisplayCapture({
|
||||
data: msg.data,
|
||||
mimeType: msg.mimeType,
|
||||
@@ -481,6 +499,19 @@ async function dispatchUiMessage (platform, msg, hooks = {}) {
|
||||
}
|
||||
return true
|
||||
}
|
||||
if (t === 'request-stage-speak') {
|
||||
try {
|
||||
await platform.requestStageSpeak()
|
||||
pushState()
|
||||
} catch (err) {
|
||||
if (/voice channel is full/i.test(err?.message || '')) {
|
||||
send({ type: 'error', message: err.message })
|
||||
return true
|
||||
}
|
||||
throw err
|
||||
}
|
||||
return true
|
||||
}
|
||||
if (t === 'select-channel') {
|
||||
await platform.selectChannel(msg.channelId)
|
||||
pushState()
|
||||
|
||||
Reference in New Issue
Block a user