sguiheux / EventSource

EventSource "polyfill" with custom headers
20 stars 10 forks source link

ERROR TypeError: Cannot read property 'heartbeatTimeout' of undefined #8

Closed TitaneBoy closed 6 years ago

TitaneBoy commented 6 years ago

Hello there..I was trying to use your package in my angular project but I got the error described in the title...

Here is the code of my SSE service

import { Injectable, NgZone } from '@angular/core';
import { Observable } from 'rxjs';

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

@Injectable()
export class SSEServices {

  constructor(private zone: NgZone) {
  }

  getSSEService(name: string) {
    switch (name) {
      case 'Resume':
        return Observable.create((observer) => {
          const eventSource = new EventSourcePolyfill('https://localhost/webclientapi/livessereadings');
          eventSource.onmessage = (event) => {
            const data = JSON.parse(event.data);
            this.zone.run(() => {
              observer.next(data);
            });
          };
          eventSource.onerror = (error) => {
            observer.error(JSON.stringify(error));
          };
          return () => eventSource.close();
        });
      default:
        break;
    }
  }

}

Did I miss something ?

Thank you in advance for your help :-)

TitaneBoy commented 6 years ago

Here is the issue I have in the Chrome console:

image

sguiheux commented 6 years ago

Hello,

The constructor has 2 parameters, : url and option. If you have nothing to pass in option parameter, just send {} => const eventSource = new EventSourcePolyfill(' https://localhost/webclientapi/livessereadings', {});

Steven

Le mar. 17 juil. 2018 à 16:40, TitaneBoy notifications@github.com a écrit :

Here is the issue I have in the Chrome console:

[image: image] https://user-images.githubusercontent.com/15614466/42824451-d9da33d8-89ad-11e8-9ced-5390b2c85ece.png

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/sguiheux/EventSource/issues/8#issuecomment-405606314, or mute the thread https://github.com/notifications/unsubscribe-auth/ABaNibBgWDVZJM-6WF08PMoCyPTkRuPdks5uHfdsgaJpZM4VS91u .

TitaneBoy commented 6 years ago

@sguiheux Hello...Thank you very much for your answer...It looks to work now..:-)

I didn't use a second parameter because I thought it was optional, as you can see here:

image