Skip to content
This repository has been archived by the owner on Mar 20, 2019. It is now read-only.

realityforge/gwt-eventsource

Repository files navigation

Deprecated

This project has been deprecated in favour of the EventSource support provided by Elemental2. Elemental2 is closer to the browser, future compatible and easier to maintain.


gwt-eventsource

Build Status

A simple library to provide eventsource support to GWT.

Quick Start

The simplest way to use the library is to add the following dependency into the build system. i.e.

<dependency>
   <groupId>org.realityforge.gwt.eventsource</groupId>
   <artifactId>gwt-eventsource</artifactId>
   <version>1.0</version>
   <scope>provided</scope>
</dependency>

Then you add the following snippet into the .gwt.xml file.

<module rename-to='myapp'>
  ...

  <!-- Enable the eventsource library -->
  <inherits name="org.realityforge.gwt.eventsource.EventSource"/>
</module>

Then you can interact with the EventSource from within the browser.

final EventSource eventSource = EventSource.newEventSourceIfSupported();
if ( null != eventSource )
{
  eventSource.setListener( new EventSourceListenerAdapter() {
    @Override
    public void onOpen( @Nonnull final EventSource eventSource )
    {
      // Connected!
    }

    @Override
    public void onMessage( @Nonnull final EventSource eventSource,
                           @Nullable final String lastEventId,
                           @Nonnull final String type,
                           @Nonnull final String data )
    {
      //Handle message
    }
  });
  eventSource.connect( "http://example.com/someurl.ext" );
  ...
  // Optionally listen to messages on message type other than "message"
  eventSource.subscribeTo( "someMessageType" );
}

This should be sufficient to put together a simple EventSource application.

A very simple example of this code is available in the gwt-eventsource-example project.

Appendix

About

GWT EventSource Library

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published