@@ -13,7 +13,6 @@ import { ITransport } from './transport/ITransport.js';
1313import { base64ToByteArray , byteArrayToBase64 } from './base64.js' ;
1414
1515export class APIClient {
16- private connectionAttempts = 0 ;
1716 private lastId = 0 ;
1817 private lastPausePointId = 0 ;
1918 private closed = false ;
@@ -30,7 +29,6 @@ export class APIClient {
3029
3130 onConnected ?: ( helloMessage : APIHello ) => void ;
3231 onError ?: ( error : APIError ) => void ;
33- onEvent ?: ( event : APIEvent ) => void ;
3432
3533 constructor (
3634 private readonly transport : ITransport ,
@@ -106,22 +104,6 @@ export class APIClient {
106104 } ) ;
107105 }
108106
109- async serialMonitorWritable ( ) {
110- // Dynamic import for Node.js-only API
111- const { Writable } = await import ( 'stream' ) ;
112- const { Buffer } = await import ( 'buffer' ) ;
113- return new Writable ( {
114- write : ( chunk : any , encoding : BufferEncoding , callback : ( error ?: Error | null ) => void ) => {
115- if ( typeof chunk === 'string' ) {
116- chunk = Buffer . from ( chunk , encoding ) ;
117- }
118- this . serialMonitorWrite ( chunk ) . then ( ( ) => {
119- callback ( null ) ;
120- } , callback ) ;
121- } ,
122- } ) ;
123- }
124-
125107 async framebufferRead ( partId : string ) {
126108 return await this . sendCommand < { png : string } > ( 'framebuffer:read' , {
127109 id : partId ,
@@ -249,7 +231,6 @@ export class APIClient {
249231 }
250232 }
251233 this . _lastNanos = message . nanos ;
252- this . onEvent ?.( message ) ;
253234 this . apiEvents . dispatchEvent ( new CustomEvent < APIEvent > ( message . event , { detail : message } ) ) ;
254235 }
255236
@@ -292,14 +273,10 @@ export class APIClient {
292273 if ( this . closed ) return ;
293274 const target = ( this as any ) . server ?? 'transport' ;
294275 const msg = `Connection to ${ target } closed unexpectedly: code ${ code } ${ reason ? ` (${ reason } )` : '' } ` ;
295- const errorObj : APIError = { type : 'error' , message : msg } ;
296- this . onError ?.( errorObj ) ;
297- console . error ( msg ) ;
276+ this . onError ?.( { type : 'error' , message : msg } ) ;
298277 }
299278
300279 private handleTransportError ( error : Error ) {
301- const errorObj : APIError = { type : 'error' , message : error . message } ;
302- this . onError ?.( errorObj ) ;
303- console . error ( 'Transport error:' , error . message ) ;
280+ this . onError ?.( { type : 'error' , message : error . message } ) ;
304281 }
305282}
0 commit comments