0

enter image description hereI have implemented this event source .But, its not working on IE as suggested by many i am using

https://github.com/remy/polyfills/blob/master/EventSource.js this pollyfill for IE.

which was suggested by

Is there a Microsoft equivalent for HTML5 Server-Sent Events?

In my code where i need this EventSource i have done like this:

 require('../../../style/vendors/EventSource.js'); --> In My Import

 ngOnInit() 
  {   
  let es = new   EventSource('http://localhost:8080/api/message');
  }

But, again when running on IE i am getting the error what i was getting earlier :

"ReferenceError: 'EventSource' is undefined
   at MessageComponent.prototype.ngOnInit (http://localhost:8080/js/app.8c7c223048ac731c6001.js:42531:10)

Please suggets me whether am missing anything or the Problem with Pollyfills?

Community
  • 1
  • 1
Rohitesh
  • 1,514
  • 7
  • 28
  • 51
  • Why is `.js` file in directory where parent directory is labelled `style`? – guest271314 Mar 31 '17 at 05:19
  • @guest271314 hmmm...just to check my code i placed the .js file inside style folder. – Rohitesh Mar 31 '17 at 05:34
  • Have not used ie in some time; have not browsed polyfill code. Have you posted an issue at github repo for the polyfill? – guest271314 Mar 31 '17 at 05:36
  • @guest271314 yes i have posted on Github too but there they have not done with angular 2 . So, asked to ask this on stackoverflow. – Rohitesh Mar 31 '17 at 05:37
  • Have not tried angular2 either. Does polyfill define `EventSource` if angular2 is not used? – guest271314 Mar 31 '17 at 05:38
  • @guest271314 i am not sure because i cannot able to find anything related to angular 2. but, from npm we can install the pollyfills https://www.npmjs.com/package/event-source-polyfill . There they have explained it for php. So, i am not geeting any clue whether my code is incorrect or is the problem with pollyfils – Rohitesh Mar 31 '17 at 05:41
  • Is `open` event logged at `console` at ie at https://jsfiddle.net/jv04ddLb/? – guest271314 Mar 31 '17 at 05:45
  • @guest271314 i am sorry i did'nt get your question – Rohitesh Mar 31 '17 at 05:47
  • Check `console` at jsfiddle at previous comment. Is `open` event of `EventSource` logged at ie? – guest271314 Mar 31 '17 at 05:48
  • @guest271314 yes in chrome its Event bubbles : false cancelBubble : false cancelable : false composed : false currentTarget : EventSource defaultPrevented : false eventPhase : 0 isTrusted : true path : Array[0] returnValue : true srcElement : EventSource target : EventSource timeStamp : 1564.2650000000003 type : "open" __proto__ : Event But, in IE i am getting SCRIPT5: Access is denied File: show, Line: 1, Column: 1 – Rohitesh Mar 31 '17 at 05:50
  • Appears to be issue with ie. Though not sure what `Access is denied File` is referencing? – guest271314 Mar 31 '17 at 05:54
  • @guest271314 i am checking with the ACCESS DENIED issue. I'll let you know if i am getting anything on this. – Rohitesh Mar 31 '17 at 05:55
  • @guest271314 the ACCESS DENIED is because of the ; in the very 1st line of the JS file i removed the ; and error gone but looks like the retrun is not correct i have attached the pic in(IE) the question plz check. – Rohitesh Mar 31 '17 at 06:03
  • "but looks like the retrun is not correct" What do you mean? The jsfiddle was to check if `EventSource` is defined outside of the `javascript` which you are currently using at ie. The issue is not with `EventSource` being `undefined`. – guest271314 Mar 31 '17 at 06:06
  • @guest271314 because its returning null and the output is different from chrome console. – Rohitesh Mar 31 '17 at 06:08
  • What is returning null? The issue described at original Question is `EventSource` being `undefined`. If `EventSource` is not `undefined` at linked jsfiddle, where polyfill is defined, the issue appears to be at another portion of `javascript` – guest271314 Mar 31 '17 at 06:09
  • @guest271314 __proto__ do you know how to call this JS file and pass the URL In order to connected to server? i want to call this js file from other .js file or html page – Rohitesh Mar 31 '17 at 06:12
  • Include the polyfill, make certain path to resource at `require()` call is correct – guest271314 Mar 31 '17 at 06:13
  • @guest271314 require is pointing correctly to the path but i guess i cannot able to call the functions inside the EventSource.js const es = require('../../../style/vendors/EventSource.js'); i am getting the following when i am doing the console.log(es) ();Object EventSource : (url) __proto__ : Object – Rohitesh Mar 31 '17 at 06:16
  • What do you mean by "call the functions inside the EventSource.js"? What is server response from `'http://localhost:8080/api/message'`? – guest271314 Mar 31 '17 at 06:18
  • @guest271314 i mean to ask how to use this EventSource.js in order to connected to server – Rohitesh Mar 31 '17 at 06:20
  • Use `message` event attached to `EventSource` instance to get stream from server, see http://stackoverflow.com/questions/42512572/how-to-send-xmlhttprequest-continuously-in-webworker/42513099#42513099 – guest271314 Mar 31 '17 at 06:21
  • @guest271314 Sorry to bother you again i am getting below exception when using es.addEventListner TypeError: es.addEventListener is not a function at NotificationComponent.ngOnInit (http://localhost:8425/js/app.1467cfb67d5944de8cd9.js:42536:13) at Wrapper_NotificationComponent.ngDoCheck (/NotificationModule/NotificationComponent/wrapper.ngfactory.js:16:73) – Rohitesh Mar 31 '17 at 06:28
  • @guest271314 my implemented code: const es = require('../../../style/vendors/EventSource.js'); es.EventSource('URL'); es.addEventListener('open', function (event) { console.log('event source open') }); es.addEventListener('message', function (event) { // do stuff with `event.data` console.log(event.data); }); es.addEventListener('error', function (event) { console.log('event source error', event) }); – Rohitesh Mar 31 '17 at 06:31
  • As mentioned at previous comment, have not tried angular2. – guest271314 Mar 31 '17 at 06:32
  • @guest271314 ohk thanks for your help – Rohitesh Mar 31 '17 at 06:33
  • @guest271314 hi in EventSource.js line no. 19 this.readyState is comming as undefined and also line no. 127 EventSource.prototype is not called. Do you have any idea related to this ? – Rohitesh Mar 31 '17 at 08:50
  • No. Would again suggest filing an issue at polyfill repo with accompanying description and code to reproduce issue – guest271314 Mar 31 '17 at 14:57

0 Answers0