test-streamOBS.ts 781 B

1234567891011121314151617181920212223
  1. import { from, map, Observable, of } from "rxjs";
  2. import * as fs from "fs"
  3. import { BaseMessage } from "../dependencies/fisloggingservice/services/logging-service";
  4. export class StreamingService {
  5. private messagesJSON: any = fs.readFileSync("testRequest.json")
  6. private messages = JSON.parse(this.messagesJSON)
  7. public stream(): Observable<BaseMessage> {
  8. return new Observable(observer => {
  9. let messages = this.messages
  10. let count = 0
  11. const intervalId = setInterval(() => {
  12. observer.next(messages[count]);
  13. count++;
  14. if (count >= 4) {
  15. clearInterval(intervalId);
  16. observer.complete();
  17. }
  18. }, 1000)
  19. })
  20. }
  21. }