Use structured piano status packets instead of message text matching
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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>;
|
||||
|
||||
Reference in New Issue
Block a user