cometd / cometd

The CometD project, a scalable comet (server push) implementation for web messaging.
https://cometd.org
Apache License 2.0
566 stars 207 forks source link

angularjs 2 can use cometd ? #657

Closed clp334264003 closed 5 years ago

clp334264003 commented 8 years ago

angularjs 2 can use cometd ?

sbordet commented 8 years ago

Have not tried that yet. CometD 3.1 is integrated with AngularJS 1.

idinf2004 commented 7 years ago

I actually have the same question, I wonder if you have some tips about how to use cometd with AngularJS 2

sbordet commented 7 years ago

I have not tried yet. I would appreciate if someone can give it a try and report back.

w0jcik commented 5 years ago

We use it with Angular7. If you use typescript you will want to also install @types/cometd (but it is currently missing some transport types). Since cometd is commonJS module, you will need to set this in tsconfig.json: "esModuleInterop": true,

sbordet commented 5 years ago

@w0jcik thanks for reporting this. Closing as apparently CometD is working with Angular > 1 without any further need.

mkorkar commented 5 years ago

Hi sbordet, i have tried to use with angular 8 but useless so if you can provide example for this

sbordet commented 5 years ago

@mkorkar what's the problem? AFAIK, Angular > 1 does not require any specific integration so you can just use CometD as you like.

mkorkar commented 5 years ago

hi sbordet, glade to hear from you finally i am able to make the project compile successfully but i used cometd-jquery code as found in the Demo [the primer->the maven way] i use microservice architecture [i mean frontend not packaged with backend as in the demo ] and i am able to deploy the spring boot backend code [cometd server side] on jetty [9.4] successfully but i hit in an exception that front can not establish handshake due to CORS exception i tried alot but useless so, is it mandatory to wire them (frontend & backend) together ? thanks in advance

sbordet commented 5 years ago

@mkorkar it's not mandatory to make front-end and back-end on the same host. See https://docs.cometd.org/current4/reference/#_javascript_transports_cross_origin.

mkorkar commented 5 years ago

from the primer Demo i noticed that you used a [CrossOriginFilter] and since my backend is spring boot deployed in standalone jetty and based on your spring boot demo this is my class :

@SpringBootApplication @EnableWebMvc public class SpringBootWebSocketDemoApplication extends SpringBootServletInitializer implements ServletContextInitializer {

@Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { return application.sources(SpringBootWebSocketDemoApplication.class); } public static void main(String[] args) { SpringApplication.run(SpringBootWebSocketDemoApplication.class, args); }

@Override public void onStartup(ServletContext servletContext) throws ServletException {

ServletRegistration.Dynamic cometdServlet = servletContext.addServlet("cometd", AnnotationCometDServlet.class);
cometdServlet.addMapping("/cometd/*");
cometdServlet.setAsyncSupported(true);
cometdServlet.setLoadOnStartup(1);
cometdServlet.setInitParameter("services", HelloService.class.getName());
cometdServlet.setInitParameter("ws.cometdURLMapping", "/cometd/*");

FilterRegistration.Dynamic cometdFilter = servletContext.addFilter("cross-origin", CrossOriginFilter.class); 
cometdFilter.addMappingForUrlPatterns(null, false, "/cometd/*");
cometdFilter.setInitParameter(ALLOWED_METHODS_PARAM, "GET,PUT,POST,OPTIONS,DELETE");
cometdFilter.setInitParameter(ALLOWED_ORIGINS_PARAM, "*");
cometdFilter.setInitParameter(ALLOWED_HEADERS_PARAM, "X-Requested-With,Content-Type,Accept,Origin,authorization");
cometdFilter.setInitParameter(ALLOW_CREDENTIALS_PARAM, "true");
cometdFilter.setInitParameter(EXPOSED_HEADERS_PARAM, "Content-Type,Authorization,X-Requested-With,Content-Length,Accept,Origin,Location,Accept-Content-Encoding");

} }

based on the above this filter not work and still the same issue [CORS] so is there any correct way to define the filter as i don't use XML Configuration

sbordet commented 5 years ago

Once you are adding the CORS filter, it should work. If it does not, then please: A) open a new issue as this one is not relevant anymore and B) must give details of "filter not work" (like: what happens exactly? client DEBUG logs? server DEBUG logs?).