@@ -20,10 +20,18 @@ type Mode = 'ws' | 'http';
2020const HOST = location . hostname || 'localhost' ;
2121const ENDPOINTS : Record < Mode , string > = {
2222 ws : `ws://${ HOST } :9000/capability` ,
23- // HTTP base URL — the SDK derives the WS sibling automatically for
24- // subscribe (see web/client.js _resolveUrls).
23+ // HTTP base for call/publish.
2524 http : `http://${ HOST } :9001` ,
2625} ;
26+ // Pass Form C ({http, ws}) when the user picks HTTP so subscribe still
27+ // reaches the WS runtime on :9000. The SDK's auto-derived sibling would
28+ // land on :9001 instead and fail — this dev layout splits the two
29+ // transports across separate ports.
30+ function connectArg ( mode : Mode ) : string | { http : string ; ws : string } {
31+ return mode === 'http'
32+ ? { http : ENDPOINTS . http , ws : ENDPOINTS . ws }
33+ : ENDPOINTS . ws ;
34+ }
2735
2836function $ < T extends HTMLElement > ( id : string ) : T {
2937 const el = document . getElementById ( id ) ;
@@ -40,7 +48,7 @@ function setStatus(text: string, cls: 'ok' | 'err' | '' = ''): void {
4048function setEndpoint ( mode : Mode ) : void {
4149 $ ( 'endpoint' ) . textContent =
4250 mode === 'http'
43- ? `${ ENDPOINTS . http } (subscribe lazily uses ws:// ${ HOST } :9000/capability )`
51+ ? `${ ENDPOINTS . http } (subscribe routed to ${ ENDPOINTS . ws } )`
4452 : ENDPOINTS . ws ;
4553}
4654
@@ -83,15 +91,15 @@ async function main(): Promise<void> {
8391 setEndpoint ( mode ) ;
8492 setStatus ( `connecting (${ mode } )…` ) ;
8593 try {
86- ros = await connect ( ENDPOINTS [ mode ] ) ;
94+ ros = await connect ( connectArg ( mode ) ) ;
8795 setStatus ( `connected (${ mode } )` , 'ok' ) ;
8896 } catch ( e ) {
8997 setStatus ( `failed: ${ String ( e ) } ` , 'err' ) ;
9098 return ;
9199 }
92100
93- // Always-on chatter subscription; over HTTP this lazily opens
94- // the WS sibling endpoint (subscribe always uses WS) .
101+ // Always-on chatter subscription; subscribe always uses WS — the
102+ // explicit { ws } in connectArg() makes this work in HTTP mode too .
95103 try {
96104 await ros . subscribe < 'std_msgs/msg/String' > ( '/web_demo_chatter' , ( msg ) =>
97105 log ( 'chatLog' , `<- ${ msg . data } ` )
0 commit comments