@utsp/types 0.4.0 → 0.5.0-nightly.20251204224035.7a07d4b

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.d.ts +221 -102
  2. package/package.json +1 -1
package/dist/index.d.ts CHANGED
@@ -1034,93 +1034,6 @@ type AnyNetworkMessage = InputMessage | UpdateMessage | LoadMessage | JoinMessag
1034
1034
  /** Message type literals */
1035
1035
  type MessageType = AnyNetworkMessage['type'];
1036
1036
 
1037
- /**
1038
- * Application lifecycle interface for games, dashboards, signage, etc.
1039
- * Supports single-user (local) and multi-user (networked) scenarios.
1040
- *
1041
- * @template TCore - Core type (typically Core)
1042
- * @template TUser - User type (typically User)
1043
- * @template TRuntime - Runtime type (optional)
1044
- */
1045
- interface IApplication<TCore = any, TUser = any, TRuntime = unknown> {
1046
- /**
1047
- * Initialize application (called once at startup, before users)
1048
- * Can be async if you need to load resources.
1049
- * @param core - Core instance
1050
- * @param runtime - Runtime instance (optional)
1051
- */
1052
- init(core: TCore, runtime?: TRuntime): void | Promise<void>;
1053
- /**
1054
- * Update global logic (called every frame, runs once)
1055
- * @param core - Core instance
1056
- * @param deltaTime - Time since last update (seconds)
1057
- */
1058
- update(core: TCore, deltaTime: number): void;
1059
- /**
1060
- * Initialize new user (called when user connects/joins)
1061
- * @param core - Core instance
1062
- * @param user - User instance
1063
- * @param metadata - Optional user metadata (username, preferences, etc.)
1064
- */
1065
- initUser(core: TCore, user: TUser, metadata?: UserMetadata): void;
1066
- /**
1067
- * Update user-specific logic (called every frame per user)
1068
- * @param core - Core instance
1069
- * @param user - User instance
1070
- * @param deltaTime - Time since last update (seconds)
1071
- */
1072
- updateUser(core: TCore, user: TUser, deltaTime: number): void;
1073
- /**
1074
- * Cleanup when user disconnects (optional)
1075
- * @param core - Core instance
1076
- * @param user - User instance
1077
- * @param reason - Disconnect reason (optional)
1078
- */
1079
- destroyUser?(core: TCore, user: TUser, reason?: string): void;
1080
- /**
1081
- * Cleanup when application shuts down (optional)
1082
- */
1083
- destroy?(): void;
1084
- /**
1085
- * Commit changes after all updates (optional)
1086
- * Called after update() and all updateUser() to trigger render/broadcast.
1087
- * @param core - Core instance
1088
- * @param deltaTime - Time since last update (seconds)
1089
- */
1090
- onCommit?(core: TCore, deltaTime: number): void;
1091
- /**
1092
- * Handle errors during execution (optional)
1093
- * @param core - Core instance
1094
- * @param error - The error that occurred
1095
- * @param context - Error context (phase, user, timestamp)
1096
- * @returns true to continue, false to stop runtime
1097
- */
1098
- onError?(core: TCore, error: Error, context: {
1099
- phase: 'init' | 'update' | 'initUser' | 'updateUser' | 'destroyUser' | 'destroy';
1100
- user?: TUser;
1101
- timestamp: number;
1102
- }): boolean;
1103
- }
1104
- /**
1105
- * User metadata for initUser
1106
- */
1107
- interface UserMetadata {
1108
- /** Display name */
1109
- username?: string;
1110
- /** Avatar/skin ID */
1111
- avatar?: string | number;
1112
- /** Team/faction */
1113
- team?: string | number;
1114
- /** Color preference */
1115
- color?: number;
1116
- /** Theme preference */
1117
- theme?: string;
1118
- /** Auth token */
1119
- token?: string;
1120
- /** Custom data */
1121
- [key: string]: unknown;
1122
- }
1123
-
1124
1037
  /**
1125
1038
  * Audio types for UTSP
1126
1039
  * @packageDocumentation
@@ -1186,17 +1099,78 @@ interface SoundExternalLoadPacket {
1186
1099
  */
1187
1100
  type AnySoundLoadPacket = SoundLoadPacket | SoundExternalLoadPacket;
1188
1101
  /**
1189
- * Client acknowledgment that an external sound was loaded
1190
- * Sent after successfully downloading and decoding an external sound
1102
+ * Audio ACK types
1103
+ */
1104
+ type AudioAckType = 'sound-loaded' | 'sound-error' | 'playback-started' | 'playback-ended' | 'playback-error';
1105
+ /**
1106
+ * Base interface for all audio acknowledgments
1107
+ */
1108
+ interface AudioAckBase {
1109
+ /** Type of acknowledgment */
1110
+ type: AudioAckType;
1111
+ }
1112
+ /**
1113
+ * ACK: Sound successfully loaded (file or external)
1191
1114
  */
1192
- interface SoundLoadedAck {
1115
+ interface SoundLoadedAck extends AudioAckBase {
1116
+ type: 'sound-loaded';
1193
1117
  /** Sound ID that was loaded */
1194
1118
  soundId: number;
1195
- /** Loading status */
1196
- status: 'loaded' | 'error';
1197
- /** Error message if status is 'error' */
1198
- error?: string;
1119
+ /** Sound name */
1120
+ name: string;
1199
1121
  }
1122
+ /**
1123
+ * ACK: Sound failed to load
1124
+ */
1125
+ interface SoundErrorAck extends AudioAckBase {
1126
+ type: 'sound-error';
1127
+ /** Sound ID that failed */
1128
+ soundId: number;
1129
+ /** Sound name */
1130
+ name: string;
1131
+ /** Error message */
1132
+ error: string;
1133
+ }
1134
+ /**
1135
+ * ACK: Sound playback started
1136
+ */
1137
+ interface PlaybackStartedAck extends AudioAckBase {
1138
+ type: 'playback-started';
1139
+ /** Instance ID of the playing sound */
1140
+ instanceId: SoundInstanceId;
1141
+ /** Sound ID being played */
1142
+ soundId: number;
1143
+ }
1144
+ /**
1145
+ * ACK: Sound playback ended (natural end, not stopped)
1146
+ */
1147
+ interface PlaybackEndedAck extends AudioAckBase {
1148
+ type: 'playback-ended';
1149
+ /** Instance ID that ended */
1150
+ instanceId: SoundInstanceId;
1151
+ /** Sound ID that was playing */
1152
+ soundId: number;
1153
+ }
1154
+ /**
1155
+ * ACK: Sound playback failed
1156
+ */
1157
+ interface PlaybackErrorAck extends AudioAckBase {
1158
+ type: 'playback-error';
1159
+ /** Instance ID that failed (if known) */
1160
+ instanceId?: SoundInstanceId;
1161
+ /** Sound ID or name that was requested */
1162
+ sound: number | string;
1163
+ /** Error message */
1164
+ error: string;
1165
+ }
1166
+ /**
1167
+ * Union of all audio ACK types
1168
+ */
1169
+ type AudioAck = SoundLoadedAck | SoundErrorAck | PlaybackStartedAck | PlaybackEndedAck | PlaybackErrorAck;
1170
+ /**
1171
+ * Callback type for audio ACK events on server
1172
+ */
1173
+ type AudioAckHandler = (userId: string, ack: AudioAck) => void;
1200
1174
  /**
1201
1175
  * Unique identifier for a playing sound instance
1202
1176
  * Allows multiple instances of the same sound to play simultaneously
@@ -1220,13 +1194,16 @@ interface PlaySoundCommand {
1220
1194
  loop?: boolean;
1221
1195
  /** Fade in duration in seconds (0 = no fade, default: 0) */
1222
1196
  fadeIn?: number;
1223
- /** Spatial position (if set, enables 2D positional audio) */
1224
- position?: {
1225
- /** X position (0-65535, 16-bit) */
1226
- x: number;
1227
- /** Y position (0-65535, 16-bit) */
1228
- y: number;
1229
- };
1197
+ /** X position for spatial audio (0-65535, 16-bit). Must be set with y. */
1198
+ x?: number;
1199
+ /** Y position for spatial audio (0-65535, 16-bit). Must be set with x. */
1200
+ y?: number;
1201
+ /** Low-pass filter cutoff frequency in Hz (100-25500, 0 or undefined = disabled) */
1202
+ lowpass?: number;
1203
+ /** High-pass filter cutoff frequency in Hz (100-25500, 0 or undefined = disabled) */
1204
+ highpass?: number;
1205
+ /** Reverb wet/dry mix (0.0-1.0, 0 or undefined = disabled) */
1206
+ reverb?: number;
1230
1207
  }
1231
1208
  /**
1232
1209
  * Command to stop a sound on the client
@@ -1284,6 +1261,21 @@ interface ResumeSoundCommand {
1284
1261
  */
1285
1262
  sound: SoundInstanceId | string | 'all';
1286
1263
  }
1264
+ /**
1265
+ * Command to update audio effects on a playing sound
1266
+ */
1267
+ interface SetSoundEffectsCommand {
1268
+ /** Marker to identify this as a set-effects command */
1269
+ setEffects: true;
1270
+ /** Target instance ID */
1271
+ instanceId: SoundInstanceId;
1272
+ /** Low-pass filter cutoff frequency in Hz (100-25500, 0 = disable) */
1273
+ lowpass?: number;
1274
+ /** High-pass filter cutoff frequency in Hz (100-25500, 0 = disable) */
1275
+ highpass?: number;
1276
+ /** Reverb wet/dry mix (0.0-1.0, 0 = disable) */
1277
+ reverb?: number;
1278
+ }
1287
1279
  /**
1288
1280
  * Command to set the listener position for spatial audio
1289
1281
  */
@@ -1348,6 +1340,12 @@ interface AudioPlayOptions {
1348
1340
  };
1349
1341
  /** Instance ID (provided by server in connected mode, auto-generated otherwise) */
1350
1342
  instanceId?: number;
1343
+ /** Low-pass filter cutoff frequency in Hz (100-25500, 0 = disable) */
1344
+ lowpass?: number;
1345
+ /** High-pass filter cutoff frequency in Hz (100-25500, 0 = disable) */
1346
+ highpass?: number;
1347
+ /** Reverb wet/dry mix (0.0-1.0, 0 = disable) */
1348
+ reverb?: number;
1351
1349
  }
1352
1350
  /**
1353
1351
  * Result of playing a sound
@@ -1445,6 +1443,14 @@ interface IAudioProcessor {
1445
1443
  * @param config - Spatial audio options
1446
1444
  */
1447
1445
  configureSpatial(config: AudioSpatialOptions): void;
1446
+ /**
1447
+ * Set audio effects on a playing sound
1448
+ * @param instanceId - The sound instance ID
1449
+ * @param lowpass - Low-pass filter cutoff Hz (0 = disable)
1450
+ * @param highpass - High-pass filter cutoff Hz (0 = disable)
1451
+ * @param reverb - Reverb mix 0.0-1.0 (0 = disable)
1452
+ */
1453
+ setEffects(instanceId: number, lowpass?: number, highpass?: number, reverb?: number): void;
1448
1454
  }
1449
1455
  /**
1450
1456
  * Interface for loading sounds into the audio system
@@ -1484,5 +1490,118 @@ interface ISoundLoader {
1484
1490
  has(nameOrId: string | number): boolean;
1485
1491
  }
1486
1492
 
1493
+ /**
1494
+ * Application lifecycle interface for games, dashboards, signage, etc.
1495
+ * Supports single-user (local) and multi-user (networked) scenarios.
1496
+ *
1497
+ * @template TCore - Core type (typically Core)
1498
+ * @template TUser - User type (typically User)
1499
+ * @template TRuntime - Runtime type (optional)
1500
+ */
1501
+ interface IApplication<TCore = any, TUser = any, TRuntime = unknown> {
1502
+ /**
1503
+ * Initialize application (called once at startup, before users)
1504
+ * Can be async if you need to load resources.
1505
+ * @param core - Core instance
1506
+ * @param runtime - Runtime instance (optional)
1507
+ */
1508
+ init(core: TCore, runtime?: TRuntime): void | Promise<void>;
1509
+ /**
1510
+ * Update global logic (called every frame, runs once)
1511
+ * @param core - Core instance
1512
+ * @param deltaTime - Time since last update (seconds)
1513
+ */
1514
+ update(core: TCore, deltaTime: number): void;
1515
+ /**
1516
+ * Initialize new user (called when user connects/joins)
1517
+ * @param core - Core instance
1518
+ * @param user - User instance
1519
+ * @param metadata - Optional user metadata (username, preferences, etc.)
1520
+ */
1521
+ initUser(core: TCore, user: TUser, metadata?: UserMetadata): void;
1522
+ /**
1523
+ * Update user-specific logic (called every frame per user)
1524
+ * @param core - Core instance
1525
+ * @param user - User instance
1526
+ * @param deltaTime - Time since last update (seconds)
1527
+ */
1528
+ updateUser(core: TCore, user: TUser, deltaTime: number): void;
1529
+ /**
1530
+ * Cleanup when user disconnects (optional)
1531
+ * @param core - Core instance
1532
+ * @param user - User instance
1533
+ * @param reason - Disconnect reason (optional)
1534
+ */
1535
+ destroyUser?(core: TCore, user: TUser, reason?: string): void;
1536
+ /**
1537
+ * Cleanup when application shuts down (optional)
1538
+ */
1539
+ destroy?(): void;
1540
+ /**
1541
+ * Commit changes after all updates (optional)
1542
+ * Called after update() and all updateUser() to trigger render/broadcast.
1543
+ * @param core - Core instance
1544
+ * @param deltaTime - Time since last update (seconds)
1545
+ */
1546
+ onCommit?(core: TCore, deltaTime: number): void;
1547
+ /**
1548
+ * Handle audio acknowledgments from clients (optional, server mode only)
1549
+ *
1550
+ * Called when a client sends an audio-ack message (sound loaded, playback started/ended, error).
1551
+ * Useful for:
1552
+ * - Waiting for sounds to load before playing them
1553
+ * - Tracking playback state across clients
1554
+ * - Handling audio errors gracefully
1555
+ *
1556
+ * @param core - Core instance
1557
+ * @param user - User who sent the ACK
1558
+ * @param ack - The audio acknowledgment
1559
+ *
1560
+ * @example
1561
+ * ```typescript
1562
+ * onAudioAck(core, user, ack) {
1563
+ * if (ack.type === 'sound-loaded') {
1564
+ * console.log(`User ${user.id} loaded sound ${ack.name}`);
1565
+ * // Now safe to play this sound for this user
1566
+ * } else if (ack.type === 'playback-ended') {
1567
+ * console.log(`Sound instance ${ack.instanceId} finished`);
1568
+ * }
1569
+ * }
1570
+ * ```
1571
+ */
1572
+ onAudioAck?(core: TCore, user: TUser, ack: AudioAck): void;
1573
+ /**
1574
+ * Handle errors during execution (optional)
1575
+ * @param core - Core instance
1576
+ * @param error - The error that occurred
1577
+ * @param context - Error context (phase, user, timestamp)
1578
+ * @returns true to continue, false to stop runtime
1579
+ */
1580
+ onError?(core: TCore, error: Error, context: {
1581
+ phase: 'init' | 'update' | 'initUser' | 'updateUser' | 'destroyUser' | 'destroy';
1582
+ user?: TUser;
1583
+ timestamp: number;
1584
+ }): boolean;
1585
+ }
1586
+ /**
1587
+ * User metadata for initUser
1588
+ */
1589
+ interface UserMetadata {
1590
+ /** Display name */
1591
+ username?: string;
1592
+ /** Avatar/skin ID */
1593
+ avatar?: string | number;
1594
+ /** Team/faction */
1595
+ team?: string | number;
1596
+ /** Color preference */
1597
+ color?: number;
1598
+ /** Theme preference */
1599
+ theme?: string;
1600
+ /** Auth token */
1601
+ token?: string;
1602
+ /** Custom data */
1603
+ [key: string]: unknown;
1604
+ }
1605
+
1487
1606
  export { GamepadInput, InputDeviceType, KeyboardInput, MouseInput, NetworkState, TVRemoteInput, TouchInput, Vector2, Vector3, createInputDescriptor, deserializeInputDescriptor, gamepadAxisIndexToInput, gamepadButtonIndexToInput, getTouchXAxis, getTouchYAxis, inputDescriptorToString, isAxis, isButton, isGamepadAxis, isGamepadButton, isMouseAxis, isMouseButton, isTVRemoteAxis, isTVRemoteButton, isTouchButton, isTouchGesture, isTouchPosition, keyCodeToKeyboardInput, keyboardInputToKeyCode, parseInputDescriptor, serializeInputDescriptor };
1488
- export type { AnyNetworkMessage, AnySoundLoadPacket, AudioConfigCommand, AudioPlayOptions, AudioPlayResult, AudioSpatialOptions, AxisBinding, AxisSource, ButtonBinding, ButtonSource, ChatMessage, ClientInfo, ConfigureSpatialCommand, ConnectionHandler, DisconnectionHandler, ErrorMessage, FadeOutSoundCommand, GamepadInputDescriptor, IApplication, IAudioProcessor, IColorPalette, IInputSystem, INetworkClient, INetworkServer, IRenderer, ISoundLoader, InputBindingLoadPacket, InputDescriptor, InputEnum, InputMessage, JoinMessage, JoinResponseMessage, KeyboardInputDescriptor, LeaveMessage, LoadMessage, MessageType, MouseInputDescriptor, NetworkClientOptions, NetworkEventHandler, NetworkMessage, NetworkServerOptions, PauseSoundCommand, PingMessage, PlaySoundCommand, PongMessage, RGBColor, RenderState, RenderedCell, ResumeSoundCommand, ServerEventHandler, SetListenerPositionCommand, SoundExternalEntry, SoundExternalLoadPacket, SoundFileEntry, SoundFormat, SoundInstanceId, SoundLoadPacket, SoundLoadType, SoundLoadedAck, SpatialAudioConfig, StopSoundCommand, TVRemoteInputDescriptor, TouchInputDescriptor, TypedInputDescriptor, UpdateMessage, UserMetadata, UserRenderState };
1607
+ export type { AnyNetworkMessage, AnySoundLoadPacket, AudioAck, AudioAckBase, AudioAckHandler, AudioAckType, AudioConfigCommand, AudioPlayOptions, AudioPlayResult, AudioSpatialOptions, AxisBinding, AxisSource, ButtonBinding, ButtonSource, ChatMessage, ClientInfo, ConfigureSpatialCommand, ConnectionHandler, DisconnectionHandler, ErrorMessage, FadeOutSoundCommand, GamepadInputDescriptor, IApplication, IAudioProcessor, IColorPalette, IInputSystem, INetworkClient, INetworkServer, IRenderer, ISoundLoader, InputBindingLoadPacket, InputDescriptor, InputEnum, InputMessage, JoinMessage, JoinResponseMessage, KeyboardInputDescriptor, LeaveMessage, LoadMessage, MessageType, MouseInputDescriptor, NetworkClientOptions, NetworkEventHandler, NetworkMessage, NetworkServerOptions, PauseSoundCommand, PingMessage, PlaySoundCommand, PlaybackEndedAck, PlaybackErrorAck, PlaybackStartedAck, PongMessage, RGBColor, RenderState, RenderedCell, ResumeSoundCommand, ServerEventHandler, SetListenerPositionCommand, SetSoundEffectsCommand, SoundErrorAck, SoundExternalEntry, SoundExternalLoadPacket, SoundFileEntry, SoundFormat, SoundInstanceId, SoundLoadPacket, SoundLoadType, SoundLoadedAck, SpatialAudioConfig, StopSoundCommand, TVRemoteInputDescriptor, TouchInputDescriptor, TypedInputDescriptor, UpdateMessage, UserMetadata, UserRenderState };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@utsp/types",
3
- "version": "0.4.0",
3
+ "version": "0.5.0-nightly.20251204224035.7a07d4b",
4
4
  "description": "Type definitions and interfaces for UTSP (Universal Text Stream Protocol)",
5
5
  "author": "THP Software",
6
6
  "license": "MIT",