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

js.web.channelmessaging.MessagePort Maven / Gradle / Ivy

package js.web.channelmessaging;

import js.lang.Any;
import js.util.buffers.Transferable;
import js.util.collections.Array;
import js.web.dom.AddEventListenerOptions;
import js.web.dom.EventListener;
import js.web.dom.EventListenerOptions;
import js.web.dom.EventTarget;
import org.teavm.jso.JSBody;
import org.teavm.jso.JSByRef;
import org.teavm.jso.JSProperty;

import javax.annotation.Nullable;

/**
 * This Channel Messaging API interface represents one of the two ports of a MessageChannel, allowing messages to be sent from one port and listening out for them arriving at the other.
 */
public interface MessagePort extends EventTarget, MessageEventSource, Transferable {

    @JSBody(script = "return MessagePort.prototype")
    static MessagePort prototype() {
        throw new UnsupportedOperationException("Available only in JavaScript");
    }

    @JSBody(script = "return new MessagePort()")
    static MessagePort create() {
        throw new UnsupportedOperationException("Available only in JavaScript");
    }

    @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 getOnmessageerror();

    @JSProperty
    void setOnmessageerror(EventListener onmessageerror);

    default void addMessageErrorEventListener(EventListener listener, AddEventListenerOptions options) {
        addEventListener("messageerror", listener, options);
    }

    default void addMessageErrorEventListener(EventListener listener, boolean options) {
        addEventListener("messageerror", listener, options);
    }

    default void addMessageErrorEventListener(EventListener listener) {
        addEventListener("messageerror", listener);
    }

    default void removeMessageErrorEventListener(EventListener listener, EventListenerOptions options) {
        removeEventListener("messageerror", listener, options);
    }

    default void removeMessageErrorEventListener(EventListener listener, boolean options) {
        removeEventListener("messageerror", listener, options);
    }

    default void removeMessageErrorEventListener(EventListener listener) {
        removeEventListener("messageerror", listener);
    }

    /**
     * Disconnects the port, so that it is no longer active.
     */
    void close();

    /**
     * Posts a message through the channel. Objects listed in transfer are transferred, not just cloned, meaning that they are no longer usable on the sending side.
     * 

* Throws a "DataCloneError" DOMException if transfer contains duplicate objects or port, or if message could not be cloned. */ void postMessage(Any message, Transferable... transfer); void postMessage(Any message, Array transfer); void postMessage(Any message, PostMessageOptions options); void postMessage(Any message); /** * Begins dispatching messages received on the port. */ void start(); }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy