@@ -55,7 +55,7 @@ class OSCLeashConfig {
5555 if ( this . Logging ) {
5656 debug . info ( ' Logging is enabled' ) ;
5757 }
58- debug . info ( ` Using integrated OSC service (no separate ports) ` ) ;
58+ debug . info ( ` Using OSC-Query for receiving, legacy OSC for sending ` ) ;
5959 debug . info ( ` Leash name(s): ${ this . Leashes . join ( ', ' ) } ` ) ;
6060 debug . info ( ` Strength Multiplier: ${ this . StrengthMultiplier } ` ) ;
6161 debug . info ( ` Delays: ${ this . ActiveDelay } ms & ${ this . InactiveDelay } ms` ) ;
@@ -124,11 +124,12 @@ class Leash {
124124 * OSC Package Controller - Handles OSC message routing
125125 */
126126class OSCPackageController {
127- constructor ( leashCollection , oscService , addonInstance = null ) {
127+ constructor ( leashCollection , oscQuery , oscService , addonInstance = null ) {
128128 if ( ! leashCollection || leashCollection . length === 0 ) {
129129 throw new Error ( "Leash collection empty within Package manager." ) ;
130130 }
131131 this . leashes = leashCollection ;
132+ this . oscQuery = oscQuery ;
132133 this . oscService = oscService ;
133134 this . addonInstance = addonInstance ;
134135 this . listeners = new Map ( ) ;
@@ -182,9 +183,15 @@ class OSCPackageController {
182183 } ) ;
183184 }
184185 registerListener ( address , callback ) {
185- if ( this . oscService && this . oscService . registerOSCLeashListener ) {
186- this . oscService . registerOSCLeashListener ( address , callback ) ;
187- this . listeners . set ( address , callback ) ;
186+ if ( this . oscQuery ) {
187+ // Create a wrapper callback that filters OSC-Query messages by address
188+ const wrappedCallback = ( oscData ) => {
189+ if ( oscData . address === address ) {
190+ callback ( oscData . value ) ;
191+ }
192+ } ;
193+ this . oscQuery . on ( 'osc-message' , wrappedCallback ) ;
194+ this . listeners . set ( address , wrappedCallback ) ;
188195 }
189196 }
190197 updateGrabbed ( currLeash , value ) {
@@ -221,9 +228,9 @@ class OSCPackageController {
221228 }
222229 }
223230 removeAllListeners ( ) {
224- if ( this . oscService && this . oscService . unregisterOSCLeashListener ) {
231+ if ( this . oscQuery ) {
225232 for ( const [ address , callback ] of this . listeners ) {
226- this . oscService . unregisterOSCLeashListener ( address , callback ) ;
233+ this . oscQuery . off ( 'osc-message' , callback ) ;
227234 }
228235 }
229236 this . listeners . clear ( ) ;
@@ -233,7 +240,8 @@ class OSCPackageController {
233240 * OSC Leash Program - Main processing logic
234241 */
235242class OSCLeashProgram {
236- constructor ( oscService , addonInstance = null ) {
243+ constructor ( oscQuery , oscService , addonInstance = null ) {
244+ this . oscQuery = oscQuery ;
237245 this . oscService = oscService ;
238246 this . addonInstance = addonInstance ;
239247 this . running = false ;
@@ -274,8 +282,14 @@ class OSCLeashProgram {
274282 clearInterval ( intervalId ) ;
275283 this . activeIntervals . delete ( leash . Name ) ;
276284 // debug.info(`Stopped monitoring thread for ${leash.Name}`);
277- // Send stop signals
278- this . leashOutput ( 0.0 , 0.0 , 0 , leash . settings ) ;
285+ // Send stop signals (only if OSC is available)
286+ try {
287+ if ( this . oscService && this . oscService . isListening ) {
288+ this . leashOutput ( 0.0 , 0.0 , 0 , leash . settings ) ;
289+ }
290+ } catch ( error ) {
291+ debug . warn ( `OSCLeash: Could not send stop signals: ${ error . message } ` ) ;
292+ }
279293 // Reset leash state
280294 leash . Active = false ;
281295 leash . resetMovement ( ) ;
@@ -288,6 +302,12 @@ class OSCLeashProgram {
288302 this . stopLeashMonitoring ( leash ) ;
289303 return ;
290304 }
305+ // Check if OSC service is still available and listening
306+ if ( ! this . oscService || ! this . oscService . isListening ) {
307+ debug . info ( `Stopping movement processing - OSC service not available` ) ;
308+ this . stopLeashMonitoring ( leash ) ;
309+ return ;
310+ }
291311 // Double-check that we should actually be processing
292312 if ( ! leash . Grabbed ) {
293313 debug . warn ( `Process called but leash ${ leash . Name } is not grabbed! Stopping monitoring.` ) ;
@@ -370,10 +390,19 @@ class OSCLeashProgram {
370390 debug . warn ( 'OSCLeash: OSC service not available' ) ;
371391 return ;
372392 }
393+ // Check if OSC service is actually running before sending
394+ if ( ! this . oscService . isListening ) {
395+ debug . warn ( 'OSCLeash: OSC service not listening - skipping output' ) ;
396+ return ;
397+ }
373398 // Send OSC messages to VRChat
374- this . oscService . sendMessage ( '/input/Vertical' , vert , 'f' ) ;
375- this . oscService . sendMessage ( '/input/Horizontal' , hori , 'f' ) ;
376- this . oscService . sendMessage ( '/input/Run' , runType , 'i' ) ;
399+ try {
400+ this . oscService . sendMessage ( '/input/Vertical' , vert , 'f' ) ;
401+ this . oscService . sendMessage ( '/input/Horizontal' , hori , 'f' ) ;
402+ this . oscService . sendMessage ( '/input/Run' , runType , 'i' ) ;
403+ } catch ( error ) {
404+ debug . error ( `OSCLeash: Error sending OSC messages: ${ error . message } ` ) ;
405+ }
377406 }
378407 clamp ( n ) {
379408 return Math . max ( - 1.0 , Math . min ( n , 1.0 ) ) ;
@@ -388,6 +417,7 @@ class OSCLeashProgram {
388417class OSCLeashAddon {
389418 constructor ( ) {
390419 this . enabled = false ;
420+ this . oscQuery = null ;
391421 this . oscService = null ;
392422 this . config = this . loadConfig ( ) ;
393423 this . settings = new OSCLeashConfig ( this . config ) ;
@@ -452,9 +482,13 @@ class OSCLeashAddon {
452482 return this . enabled ;
453483 }
454484
455- start ( oscService = null ) {
485+ start ( oscQuery = null , oscService = null ) {
486+ if ( ! oscQuery ) {
487+ debug . logError ( 'Cannot start OSCLeash: No OSC-Query service provided' ) ;
488+ return false ;
489+ }
456490 if ( ! oscService ) {
457- debug . logError ( 'Cannot start OSCLeash: No OSC service provided' ) ;
491+ debug . logError ( 'Cannot start OSCLeash: No OSC service provided for sending ' ) ;
458492 return false ;
459493 }
460494
@@ -463,6 +497,7 @@ class OSCLeashAddon {
463497 return true ;
464498 }
465499
500+ this . oscQuery = oscQuery ;
466501 this . oscService = oscService ;
467502 this . enabled = true ;
468503
@@ -479,10 +514,10 @@ class OSCLeashAddon {
479514 }
480515
481516 // Create program
482- this . program = new OSCLeashProgram ( this . oscService , this ) ;
517+ this . program = new OSCLeashProgram ( this . oscQuery , this . oscService , this ) ;
483518
484519 // Create package controller
485- this . packageController = new OSCPackageController ( this . leashes , this . oscService , this ) ;
520+ this . packageController = new OSCPackageController ( this . leashes , this . oscQuery , this . oscService , this ) ;
486521 this . packageController . onLeashActivate = ( leash ) => {
487522 this . program . leashRun ( leash ) ;
488523 } ;
@@ -494,7 +529,7 @@ class OSCLeashAddon {
494529 // Do NOT automatically set leash as active - wait for OSC grab detection
495530 // this.leashes[0].Active = true; // REMOVED - leashes should only be active when grabbed
496531
497- debug . info ( 'OSCLeash initialized - all leashes in idle state, waiting for grab detection...' ) ;
532+ debug . info ( 'OSCLeash initialized - all leashes in idle state, waiting for grab detection via OSC-Query ...' ) ;
498533 this . settings . printInfo ( ) ;
499534 debug . info ( 'OSCLeash addon started, awaiting input...' ) ;
500535 this . notifyStatusChange ( ) ; // Notify UI of status change
@@ -526,9 +561,13 @@ class OSCLeashAddon {
526561 leash . resetMovement ( ) ;
527562 }
528563
529- // Send stop signals
530- if ( this . program && this . oscService ) {
531- this . program . leashOutput ( 0.0 , 0.0 , 0 , this . settings ) ;
564+ // Send stop signals only if OSC is available
565+ try {
566+ if ( this . program && this . oscService && this . oscService . isListening ) {
567+ this . program . leashOutput ( 0.0 , 0.0 , 0 , this . settings ) ;
568+ }
569+ } catch ( error ) {
570+ debug . warn ( `OSCLeash: Could not send stop signals during shutdown: ${ error . message } ` ) ;
532571 }
533572
534573 // Remove listeners
@@ -560,8 +599,8 @@ class OSCLeashAddon {
560599 this . saveConfig ( ) ;
561600
562601 // Restart if it was enabled
563- if ( wasEnabled && this . oscService ) {
564- this . start ( this . oscService ) ;
602+ if ( wasEnabled && this . oscQuery && this . oscService ) {
603+ this . start ( this . oscQuery , this . oscService ) ;
565604 }
566605
567606 debug . info ( 'OSCLeash config updated' ) ;
0 commit comments