@@ -39,10 +39,12 @@ export class clsstream {
3939 public stream : ChangeStream ;
4040 public id : string ;
4141 public callback : any ;
42+ aggregates : object [ ] ;
43+ collectionname : string ;
4244}
4345export class WebSocketServerClient {
4446 public jwt : string ;
45- private _socketObject : WebSocket ;
47+ public _socketObject : WebSocket ;
4648 private _receiveQueue : SocketMessage [ ] ;
4749 private _sendQueue : SocketMessage [ ] ;
4850 public messageQueue : IHashTable < QueuedMessage > = { } ;
@@ -165,9 +167,9 @@ export class WebSocketServerClient {
165167 if ( this . queuecount ( ) > 0 ) {
166168 this . CloseConsumers ( span ) ;
167169 }
168- if ( this . streamcount ( ) > 0 ) {
169- this . CloseConsumers ( span ) ;
170- }
170+ // if (this.streamcount() > 0) {
171+ // this.CloseStreams( );
172+ // }
171173 return ;
172174 }
173175 if ( this . _socketObject . readyState === this . _socketObject . CLOSED || this . _socketObject . readyState === this . _socketObject . CLOSING ) {
@@ -228,7 +230,7 @@ export class WebSocketServerClient {
228230 const span : Span = Logger . otel . startSpan ( "WebSocketServerClient.Close" ) ;
229231 try {
230232 await this . CloseConsumers ( span ) ;
231- await this . CloseStreams ( ) ;
233+ // await this.CloseStreams();
232234 if ( this . _socketObject != null ) {
233235 try {
234236 this . _socketObject . removeAllListeners ( ) ;
@@ -579,85 +581,87 @@ export class WebSocketServerClient {
579581 const msg : Message = new Message ( ) ; msg . command = "deleteone" ; msg . data = JSON . stringify ( q ) ;
580582 await this . Send < DeleteOneMessage > ( msg ) ;
581583 }
582- streams : clsstream [ ] = [ ] ;
583- public streamcount ( ) : number {
584- if ( this . streams == null ) return 0 ;
585- return this . streams . length ;
586- }
587- async CloseStreams ( ) : Promise < void > {
588- if ( this . streams != null && this . streams . length > 0 ) {
589- for ( let i = this . streams . length - 1 ; i >= 0 ; i -- ) {
590- try {
591- if ( this . streams [ i ] != null && this . streams [ i ] . stream != null && ! this . streams [ i ] . stream . isClosed ( ) ) {
592- await this . streams [ i ] . stream . close ( ) ;
593- }
594- this . streams . splice ( i , 1 ) ;
595- } catch ( error ) {
596- Logger . instanse . error ( "WebSocketclient::CloseStreams " + error + " " + this . id + "/" + this . clientagent ) ;
597- }
598- }
599- }
600- }
601- async CloseStream ( id : string ) : Promise < void > {
602- if ( this . streams != null && this . streams . length > 0 ) {
603- for ( let i = this . streams . length - 1 ; i >= 0 ; i -- ) {
604- try {
605- if ( this . streams [ i ] != null && this . streams [ i ] . id == id ) {
606- if ( ! this . streams [ i ] . stream . isClosed ( ) ) await this . streams [ i ] . stream . close ( ) ;
607- this . streams . splice ( i , 1 ) ;
608- }
609- } catch ( error ) {
610- Logger . instanse . error ( "WebSocketclient::CloseStream " + error + " " + this . id + "/" + this . clientagent ) ;
611- }
612- }
613- }
614- WebSocketServer . update_mongodb_watch_count ( this ) ;
615- }
584+ // streams: clsstream[] = [];
585+ // public streamcount(): number {
586+ // if (this.streams == null) return 0;
587+ // return this.streams.length;
588+ // }
589+ // async CloseStreams(): Promise<void> {
590+ // if (this.streams != null && this.streams.length > 0) {
591+ // for (let i = this.streams.length - 1; i >= 0; i--) {
592+ // try {
593+ // if (this.streams[i] != null && this.streams[i].stream != null && !this.streams[i].stream.isClosed()) {
594+ // await this.streams[i].stream.close();
595+ // }
596+ // this.streams.splice(i, 1);
597+ // } catch (error) {
598+ // Logger.instanse.error("WebSocketclient::CloseStreams " + error + " " + this.id + "/" + this.clientagent);
599+ // }
600+ // }
601+ // }
602+ // }
603+ // async CloseStream(id: string): Promise<void> {
604+ // if (this.streams != null && this.streams.length > 0) {
605+ // for (let i = this.streams.length - 1; i >= 0; i--) {
606+ // try {
607+ // if (this.streams[i] != null && this.streams[i].id == id) {
608+ // if (!this.streams[i].stream.isClosed()) await this.streams[i].stream.close();
609+ // this.streams.splice(i, 1);
610+ // }
611+ // } catch (error) {
612+ // Logger.instanse.error("WebSocketclient::CloseStream " + error + " " + this.id + "/" + this.clientagent);
613+ // }
614+ // }
615+ // }
616+ // WebSocketServer.update_mongodb_watch_count(this);
617+ // }
616618 async UnWatch ( id : string , jwt : string ) : Promise < void > {
617619 if ( this . watches [ id ] ) {
618- this . CloseStream ( this . watches [ id ] . streamid ) ;
620+ // this.CloseStream(this.watches[id].streamid);
619621 delete this . watches [ id ] ;
620622 }
621623 }
622624 public watches : IHashTable < ClientWatch > = { } ;
623625 async Watch ( aggregates : object [ ] , collectionname : string , jwt : string , id : string = null ) : Promise < string > {
624626 const stream : clsstream = new clsstream ( ) ;
625627 stream . id = NoderedUtil . GetUniqueIdentifier ( ) ;
626- stream . stream = await Config . db . watch ( aggregates , collectionname , jwt ) ;
627- this . streams . push ( stream ) ;
628+ stream . collectionname = collectionname ;
629+ stream . aggregates = aggregates ;
630+ // stream.stream = await Config.db.watch(aggregates, collectionname, jwt);
631+ // this.streams.push(stream);
628632 if ( id == null ) id = NoderedUtil . GetUniqueIdentifier ( ) ;
629633
630- const options = { fullDocument : "updateLookup" } ;
631- const me = this ;
632- try {
633- ( stream . stream as any ) . on ( "error" , err => {
634- console . error ( err ) ;
635- } ) ;
636- ( stream . stream as any ) . on ( "change" , next => {
637- try {
638- Logger . instanse . info ( "Watch: " + JSON . stringify ( next . documentKey ) ) ;
639- const msg : SocketMessage = SocketMessage . fromcommand ( "watchevent" ) ;
640- const q = new WatchEventMessage ( ) ;
641- q . id = id ;
642- q . result = next ;
643- if ( q . result && q . result . fullDocument ) {
644- q . result . fullDocument = Config . db . decryptentity ( q . result . fullDocument ) ;
645- }
646- msg . data = JSON . stringify ( q ) ;
647- me . _socketObject . send ( msg . tojson ( ) ) ;
648- } catch ( error ) {
649- Logger . instanse . error ( "WebSocketclient::Watch::changeListener " + error + " " + this . id + "/" + this . clientagent ) ;
650- }
651- } , options ) ;
634+ // const options = { fullDocument: "updateLookup" };
635+ // const me = this;
636+ // try {
637+ // (stream.stream as any).on("error", err => {
638+ // console.error(err);
639+ // });
640+ // (stream.stream as any).on("change", next => {
641+ // try {
642+ // // Logger.instanse.info("Watch: " + JSON.stringify(next.documentKey));
643+ // // const msg: SocketMessage = SocketMessage.fromcommand("watchevent");
644+ // // const q = new WatchEventMessage();
645+ // // q.id = id;
646+ // // q.result = next;
647+ // // if (q.result && q.result.fullDocument) {
648+ // // q.result.fullDocument = Config.db.decryptentity(q.result.fullDocument);
649+ // / / }
650+ // // msg.data = JSON.stringify(q);
651+ // // me._socketObject.send(msg.tojson());
652+ // } catch (error) {
653+ // Logger.instanse.error("WebSocketclient::Watch::changeListener " + error + " " + this.id + "/" + this.clientagent);
654+ // }
655+ // }, options);
652656 WebSocketServer . update_mongodb_watch_count ( this ) ;
653657 this . watches [ id ] = {
654- aggregates, collectionname, streamid : stream . id
658+ aggregates, collectionname // , streamid: stream.id
655659 } as ClientWatch ;
656660 return id ;
657- } catch ( error ) {
658- Logger . instanse . error ( "WebSocketclient::Watch " + error + " " + this . id + "/" + this . clientagent ) ;
659- throw error ;
660- }
661+ // } catch (error) {
662+ // Logger.instanse.error("WebSocketclient::Watch " + error + " " + this.id + "/" + this.clientagent);
663+ // throw error;
664+ // }
661665 }
662666}
663667export class ClientWatch {
0 commit comments