Use structured piano status packets instead of message text matching

This commit is contained in:
Jage9
2026-02-24 19:56:44 -05:00
parent 7488ac9f67
commit fe07fa3e8f
13 changed files with 155 additions and 61 deletions

View File

@@ -49,6 +49,7 @@ type MessageHandlerDeps = {
playRemoteSpatialStepOrTeleport: (url: string, peerX: number, peerY: number) => void;
handleItemActionResultStatus: (message: Extract<IncomingMessage, { type: 'item_action_result' }>) => boolean;
handleRemotePianoNote: (message: Extract<IncomingMessage, { type: 'item_piano_note' }>) => void;
handlePianoStatus: (message: Extract<IncomingMessage, { type: 'item_piano_status' }>) => void;
stopAllRemoteNotesForSender: (senderId: string) => void;
TELEPORT_SOUND_URL: string;
TELEPORT_START_SOUND_URL: string;
@@ -272,6 +273,11 @@ export function createOnMessageHandler(deps: MessageHandlerDeps): (message: Inco
deps.handleRemotePianoNote(message);
break;
}
case 'item_piano_status': {
deps.handlePianoStatus(message);
break;
}
}
};
}

View File

@@ -180,6 +180,21 @@ export const itemPianoNoteSchema = z.object({
emitRange: z.number().int().min(1),
});
export const itemPianoStatusSchema = z.object({
type: z.literal('item_piano_status'),
itemId: z.string(),
event: z.enum([
'use_mode_entered',
'record_started',
'record_paused',
'record_resumed',
'record_stopped',
'playback_started',
'playback_stopped',
]),
recordingState: z.enum(['idle', 'recording', 'paused', 'playback']).optional(),
});
export const incomingMessageSchema = z.discriminatedUnion('type', [
welcomeMessageSchema,
signalMessageSchema,
@@ -194,6 +209,7 @@ export const incomingMessageSchema = z.discriminatedUnion('type', [
itemActionResultSchema,
itemUseSoundSchema,
itemPianoNoteSchema,
itemPianoStatusSchema,
]);
export type IncomingMessage = z.infer<typeof incomingMessageSchema>;