migration from angular 5 to angular 7

287 Views Asked by At

Yesterday i have migrated my application from Angular 5 to angular 7. In that process i have changed EventSource to EventSourcePolyfill as suggested while running the application. But since then i am facing a strange issue. This is what i am getting the issue in console as follows:

ERROR TypeError: Cannot read property 'heartbeatTimeout' of undefined
    at new EventSourcePolyfill (eventsource.js:155)
    at AppFooterComponent.push../src/app/layout/footer/footer.component.ts.AppFooterComponent.connect (footer.component.ts:133)
    at SafeSubscriber._next (footer.component.ts:52)
    at SafeSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.SafeSubscriber.__tryOrUnsub (Subscriber.js:196)
    at SafeSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.SafeSubscriber.next (Subscriber.js:134)
    at Subscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber._next (Subscriber.js:77)
    at Subscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.next (Subscriber.js:54)
    at AsyncAction.dispatch (timer.js:31)
    at AsyncAction.push../node_modules/rxjs/_esm5/internal/scheduler/AsyncAction.js.AsyncAction._execute (AsyncAction.js:63)
    at AsyncAction.push../node_modules/rxjs/_esm5/internal/scheduler/AsyncAction.js.AsyncAction.execute (AsyncAction.js:51)

This is what i did in my code:

import { EventSourcePolyfill } from 'ng-event-source';

let source = new EventSourcePolyfill('/api/v1/events/register');

Can any one suggest me how to get rid of this issue.

Thanks.

1

There are 1 best solutions below

0
On

You have to pass additional parameters, as

eventSource = new EventSourcePolyfill(url,
    { heartbeatTimeout: 5000, connectionTimeout: 5000, headers: { 'Authorization': 'Basic foo' }});