All Downloads are FREE. Search and download functionalities are using the official Maven repository.

js.web.serversideevents.EventSource Maven / Gradle / Ivy

package js.web.serversideevents;


import js.extras.JsEnum;
import js.web.channelmessaging.MessageEvent;
import js.web.dom.*;
import org.teavm.jso.JSBody;
import org.teavm.jso.JSProperty;

import javax.annotation.Nullable;


public interface EventSource extends EventTarget {
    @JSBody(script = "return EventSource.prototype")
    static EventSource prototype() {
        throw new UnsupportedOperationException("Available only in JavaScript");
    }

    @JSBody(params = {"url", "eventSourceInitDict"}, script = "return new EventSource(url, eventSourceInitDict)")
    static EventSource create(String url, EventSourceInit eventSourceInitDict) {
        throw new UnsupportedOperationException("Available only in JavaScript");
    }

    @JSBody(params = "url", script = "return new EventSource(url)")
    static EventSource create(String url) {
        throw new UnsupportedOperationException("Available only in JavaScript");
    }

    @JSProperty
    @Nullable
    EventListener getOnerror();

    @JSProperty
    void setOnerror(EventListener onerror);

    default void addErrorEventListener(EventListener listener, AddEventListenerOptions options) {
        addEventListener("error", listener, options);
    }

    default void addErrorEventListener(EventListener listener, boolean options) {
        addEventListener("error", listener, options);
    }

    default void addErrorEventListener(EventListener listener) {
        addEventListener("error", listener);
    }

    default void removeErrorEventListener(EventListener listener, EventListenerOptions options) {
        removeEventListener("error", listener, options);
    }

    default void removeErrorEventListener(EventListener listener, boolean options) {
        removeEventListener("error", listener, options);
    }

    default void removeErrorEventListener(EventListener listener) {
        removeEventListener("error", listener);
    }

    @JSProperty
    @Nullable
    EventListener getOnmessage();

    @JSProperty
    void setOnmessage(EventListener onmessage);

    default void addMessageEventListener(EventListener listener, AddEventListenerOptions options) {
        addEventListener("message", listener, options);
    }

    default void addMessageEventListener(EventListener listener, boolean options) {
        addEventListener("message", listener, options);
    }

    default void addMessageEventListener(EventListener listener) {
        addEventListener("message", listener);
    }

    default void removeMessageEventListener(EventListener listener, EventListenerOptions options) {
        removeEventListener("message", listener, options);
    }

    default void removeMessageEventListener(EventListener listener, boolean options) {
        removeEventListener("message", listener, options);
    }

    default void removeMessageEventListener(EventListener listener) {
        removeEventListener("message", listener);
    }

    @JSProperty
    @Nullable
    EventListener getOnopen();

    @JSProperty
    void setOnopen(EventListener onopen);

    default void addOpenEventListener(EventListener listener, AddEventListenerOptions options) {
        addEventListener("open", listener, options);
    }

    default void addOpenEventListener(EventListener listener, boolean options) {
        addEventListener("open", listener, options);
    }

    default void addOpenEventListener(EventListener listener) {
        addEventListener("open", listener);
    }

    default void removeOpenEventListener(EventListener listener, EventListenerOptions options) {
        removeEventListener("open", listener, options);
    }

    default void removeOpenEventListener(EventListener listener, boolean options) {
        removeEventListener("open", listener, options);
    }

    default void removeOpenEventListener(EventListener listener) {
        removeEventListener("open", listener);
    }

    /**
     * Returns the state of this EventSource object's connection. It can have the values described below.
     */
    @JSProperty
    ReadyState getReadyState();

    /**
     * Returns the URL providing the event stream.
     */
    @JSProperty
    String getUrl();

    /**
     * Returns true if the credentials mode for connection requests to the URL providing the event stream is set to "include", and false otherwise.
     */
    @JSProperty
    boolean isWithCredentials();

    /**
     * Aborts any instances of the fetch algorithm started for this EventSource object, and sets the readyState attribute to CLOSED.
     */
    void close();

    abstract class ReadyState extends JsEnum {


        public static final ReadyState CLOSED = JsEnum.from("EventSource.CLOSED");

        public static final ReadyState CONNECTING = JsEnum.from("EventSource.CONNECTING");

        public static final ReadyState OPEN = JsEnum.from("EventSource.OPEN");
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy