public abstract class WebSocket
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
static class |
WebSocket.BinaryType
The types of data the WebSocket can receive.
|
static interface |
WebSocket.Factory
The factory used for creating WebSocket instances.
|
static class |
WebSocket.ReadyState
The states of the WebSocket.
|
| Constructor and Description |
|---|
WebSocket() |
| Modifier and Type | Method and Description |
|---|---|
abstract void |
close()
Close the WebSocket and stop receiving MessageEvents.
|
void |
close(short code)
Close the WebSocket with specified code and stop receiving MessageEvents.
|
abstract void |
close(short code,
java.lang.String reason)
Close the WebSocket with specified code and reason, and stop receiving MessageEvents.
|
abstract void |
connect(java.lang.String url,
java.lang.String... protocols)
Connect the WebSocket to the specified url, passing specified protocols.
|
static boolean |
deregister(WebSocket.Factory factory)
Deregister factory if the specified factory is the registered factory.
|
abstract WebSocket.BinaryType |
getBinaryType()
Return the type of the binary messages that the WebSocket will receive.
|
abstract int |
getBufferedAmount()
Return the amount buffered on underlying WebSocket.
|
abstract java.lang.String |
getExtensions()
Return the extensions that the underlying WebSocket is connected using.
|
WebSocketListener |
getListener()
Return the listener associated with the WebSocket.
|
abstract java.lang.String |
getProtocol()
Return the protocol used by the underlying WebSocket.
|
abstract WebSocket.ReadyState |
getReadyState()
Return the state of the WebSocket.
|
abstract java.lang.String |
getURL()
Return the url that the underlying WebSOcket is connected to.
|
abstract boolean |
isConnected() |
static boolean |
isSupported() |
static WebSocket |
newWebSocketIfSupported()
Create a WebSocket if supported by the platform.
|
protected void |
onClose(boolean wasClean,
int code,
java.lang.String reason)
Fire a Close event.
|
protected void |
onError()
Fire an Error event.
|
protected void |
onMessage(ArrayBuffer data)
Fire a Message event.
|
protected void |
onMessage(java.lang.String data)
Fire a Message event.
|
protected void |
onOpen()
Fire a Connected event.
|
static void |
register(WebSocket.Factory factory)
Register a factory to be used to construct WebSocket instances.
|
abstract void |
send(ArrayBuffer data)
Send some ArrayBuffer data across the WebSocket.
|
abstract void |
send(ArrayBufferView data)
Send some ArrayBufferView data across the WebSocket.
|
abstract void |
send(java.lang.String data)
Send some string data across the WebSocket.
|
abstract void |
setBinaryType(WebSocket.BinaryType binaryType)
Set the type of the binary messages that the WebSocket will receive.
|
void |
setListener(WebSocketListener listener)
Set the listener to receive messages from the WebSocket.
|
public static WebSocket newWebSocketIfSupported()
public static boolean isSupported()
public static void register(@Nonnull
WebSocket.Factory factory)
factory - the factory to register.public static boolean deregister(@Nonnull
WebSocket.Factory factory)
factory - the factory to deregister.public abstract void connect(@Nonnull
java.lang.String url,
@Nonnull
java.lang.String... protocols)
throws java.lang.IllegalStateException
url - the url to open.java.lang.IllegalStateException - if the WebSocket is already open.public abstract void close()
throws java.lang.IllegalStateException
java.lang.IllegalStateException - if the WebSocket is not open.public final void close(short code)
throws java.lang.IllegalStateException
java.lang.IllegalStateException - if the WebSocket is not open.public abstract void close(short code,
@Nullable
java.lang.String reason)
throws java.lang.IllegalStateException
java.lang.IllegalStateException - if the WebSocket is not open.public abstract boolean isConnected()
public abstract void send(@Nonnull
java.lang.String data)
throws java.lang.IllegalStateException
data - the data to send.java.lang.IllegalStateException - if the WebSocket is not open.public abstract void send(@Nonnull
ArrayBuffer data)
throws java.lang.IllegalStateException
data - the data to send.java.lang.IllegalStateException - if the WebSocket is not open.public abstract void send(@Nonnull
ArrayBufferView data)
throws java.lang.IllegalStateException
data - the data to send.java.lang.IllegalStateException - if the WebSocket is not open.public abstract int getBufferedAmount()
throws java.lang.IllegalStateException
java.lang.IllegalStateException - if the WebSocket is not open.public abstract java.lang.String getProtocol()
throws java.lang.IllegalStateException
java.lang.IllegalStateException - if the WebSocket is not open.public abstract java.lang.String getURL()
throws java.lang.IllegalStateException
java.lang.IllegalStateException - if the WebSocket is not open.public abstract java.lang.String getExtensions()
throws java.lang.IllegalStateException
java.lang.IllegalStateException - if the WebSocket is not open.public abstract WebSocket.ReadyState getReadyState()
public abstract void setBinaryType(@Nonnull
WebSocket.BinaryType binaryType)
throws java.lang.IllegalStateException
binaryType - the type of the binary messages that the WebSocket will receive.java.lang.IllegalStateException - if the WebSocket is not open.public abstract WebSocket.BinaryType getBinaryType() throws java.lang.IllegalStateException
java.lang.IllegalStateException - if the WebSocket is not open.@Nonnull public final WebSocketListener getListener()
public final void setListener(@Nullable
WebSocketListener listener)
listener - the listener to receive messages from the WebSocket.protected final void onOpen()
protected final void onClose(boolean wasClean,
int code,
@Nullable
java.lang.String reason)
protected final void onMessage(java.lang.String data)
protected final void onMessage(ArrayBuffer data)
protected final void onError()