@@ -86,9 +86,25 @@ export type TAKOptions = {
8686 socketBatchSize ?: number ;
8787} ;
8888
89+ export type WriteOptions = {
90+ /** Remove any existing flow tags and replace them with a fresh
91+ * `NodeCoT-*` entry before serializing to XML.
92+ * Useful when re-submitting CoTs back to TAK Server over 8089.
93+ * @default false */
94+ stripFlow ?: boolean ;
95+ } ;
96+
8997const DEFAULT_WRITE_QUEUE_SIZE = 10_000 ;
9098const DEFAULT_SOCKET_BATCH_SIZE = 64 ;
9199
100+ function cloneCoT ( cot : CoT ) : CoT {
101+ const cloned = new CoT ( JSON . parse ( JSON . stringify ( cot . raw ) ) ) ;
102+ cloned . metadata = JSON . parse ( JSON . stringify ( cot . metadata ) ) ;
103+ cloned . path = cot . path ;
104+
105+ return cloned ;
106+ }
107+
92108export default class TAK extends EventEmitter {
93109 id : number | string ;
94110 type : string ;
@@ -394,14 +410,17 @@ export default class TAK extends EventEmitter {
394410 *
395411 * @param cots Array of CoT objects to send
396412 */
397- async write ( cots : CoT [ ] ) : Promise < void > {
413+ async write ( cots : CoT [ ] , opts : WriteOptions = { } ) : Promise < void > {
398414 for ( let i = 0 ; i < cots . length ; ) {
399415 if ( this . destroyed ) return ;
400416
401417 // Serialize upfront and push XML strings into the ring buffer
402418 while (
403419 i < cots . length &&
404- this . queue . push ( CoTParser . to_xml ( cots [ i ] ) )
420+ this . queue . push ( CoTParser . to_xml (
421+ opts . stripFlow ? cloneCoT ( cots [ i ] ) : cots [ i ] ,
422+ opts . stripFlow ? { resetFlow : true } : undefined ,
423+ ) )
405424 ) {
406425 i ++ ;
407426 }
0 commit comments