index.ts 796 B

123456789101112131415161718192021222324
  1. import { Subject, from } from 'rxjs';
  2. import * as fs from 'fs'
  3. export * from './services/server-client.service';
  4. const messagesJSON: any = fs.readFileSync('payload.json')
  5. let parsedMessages = JSON.parse(messagesJSON)
  6. function generateFakeStreamResponse(request: any): Subject<any> {
  7. let res: Subject<any> = new Subject()
  8. from(parsedMessages.slice(0, 10)).subscribe({
  9. next: element => {
  10. let message = {
  11. id: request.id,
  12. message: element
  13. }
  14. res.next(message)
  15. },
  16. error: error => console.error(error),
  17. complete: () => console.log(`Stream response for ${request.id} has been prepared.`)
  18. })
  19. return res
  20. }
  21. generateFakeStreamResponse({ id: '123', message: 'DOnt lie to me boy' }).subscribe((e => console.log(e)))