File tree Expand file tree Collapse file tree 1 file changed +25
-6
lines changed Expand file tree Collapse file tree 1 file changed +25
-6
lines changed Original file line number Diff line number Diff line change @@ -343,24 +343,43 @@ class WebBluetooth extends EventTarget {
343343 }
344344 }
345345
346- async send ( data ) {
346+ async send ( data , cb ) {
347347 if ( ! this . writeCharacteristic ) {
348+ if ( cb ) {
349+ cb ( {
350+ error : "No write characteristic available" ,
351+ bytesSent : 0 ,
352+ } ) ;
353+ }
354+ console . error ( `${ this . logHead } No write characteristic available` ) ;
348355 return ;
349356 }
350357
351358 // There is no writable stream in the bluetooth API
352- this . bytesSent += data . byteLength ;
353-
354359 const dataBuffer = new Uint8Array ( data ) ;
355360
356361 try {
357362 if ( this . lastWrite ) {
358363 await this . lastWrite ;
359364 }
360- } catch ( error ) {
361- console . error ( error ) ;
365+ this . lastWrite = this . writeCharacteristic . writeValue ( dataBuffer ) ;
366+ this . bytesSent += data . byteLength ;
367+
368+ if ( cb ) {
369+ cb ( {
370+ error : null ,
371+ bytesSent : this . bytesSent ,
372+ } ) ;
373+ }
374+ } catch ( e ) {
375+ console . error ( `${ this . logHead } Failed to send data:` , e ) ;
376+ if ( cb ) {
377+ cb ( {
378+ error : e ,
379+ bytesSent : 0 ,
380+ } ) ;
381+ }
362382 }
363- this . lastWrite = this . writeCharacteristic . writeValue ( dataBuffer ) ;
364383
365384 return {
366385 bytesSent : data . byteLength ,
You can’t perform that action at this time.
0 commit comments