simpleObsTest.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import { BehaviorSubject, Observable, Subject, interval } from "rxjs";
  2. import { BufferService } from "../services/buffer.service";
  3. import { ConnectionState } from "../interfaces/general.interface";
  4. // let obs1 = new Subject<any>
  5. let obs1 = new Subject<any>;
  6. interval(1000).subscribe(
  7. {
  8. next:(msg)=>{
  9. obs1.next(msg)
  10. }
  11. }
  12. );
  13. let initialReport = { status: 'DIRECT_PUBLISH' }
  14. let reportSubject: BehaviorSubject<any> = new BehaviorSubject(initialReport)
  15. let retransmission = new BufferService(obs1, reportSubject, 'mongo')
  16. let result: Observable<any> = retransmission.getMessages()
  17. result.subscribe(e => console.log(e))
  18. let publishBUFFER: ConnectionState = {
  19. status: `BUFFER`
  20. }
  21. let publishDIRECT_PUBLISH: ConnectionState = {
  22. status: `DIRECT_PUBLISH`
  23. }
  24. setTimeout(()=>{
  25. reportSubject.next(publishBUFFER);
  26. },5000)
  27. setTimeout(()=>{
  28. reportSubject.next(publishDIRECT_PUBLISH);
  29. },10000)
  30. // let initialReport = { status: 'BUFFER' }
  31. // let reportSubject: BehaviorSubject<any> = new BehaviorSubject(initialReport)
  32. // let retransmission = new BufferService(obs1, reportSubject, 'mongo', 5)
  33. // retransmission.getMessages().subscribe(e => console.log(e))