com.gargoylesoftware.htmlunit.javascript.host
Class WebSocket

java.lang.Object
  extended by net.sourceforge.htmlunit.corejs.javascript.ScriptableObject
      extended by com.gargoylesoftware.htmlunit.javascript.SimpleScriptable
          extended by com.gargoylesoftware.htmlunit.javascript.host.WebSocket
All Implemented Interfaces:
Serializable, Cloneable, net.sourceforge.htmlunit.corejs.javascript.ConstProperties, net.sourceforge.htmlunit.corejs.javascript.debug.DebuggableObject, net.sourceforge.htmlunit.corejs.javascript.Scriptable

public class WebSocket
extends SimpleScriptable

A JavaScript object for a WebSocket.

Version:
$Revision: 7429 $
Author:
Ahmed Ashour
See Also:
Mozilla documentation, Serialized Form

Field Summary
static int CLOSED
          The connection has been closed or could not be opened.
static int CLOSING
          The connection is going through the closing handshake.
static int CONNECTING
          The connection has not yet been established.
static int OPEN
          The WebSocket connection is established and communication is possible.
 
Fields inherited from class net.sourceforge.htmlunit.corejs.javascript.ScriptableObject
CONST, DONTENUM, EMPTY, PERMANENT, READONLY, UNINITIALIZED_CONST
 
Fields inherited from interface net.sourceforge.htmlunit.corejs.javascript.Scriptable
NOT_FOUND
 
Constructor Summary
WebSocket()
          Creates a new instance.
 
Method Summary
 void close(Object code, Object reason)
          Closes the WebSocket connection or connection attempt, if any.
 net.sourceforge.htmlunit.corejs.javascript.Function getOnclose()
          Returns the event handler that fires on close.
 net.sourceforge.htmlunit.corejs.javascript.Function getOnerror()
          Returns the event handler that fires on error.
 net.sourceforge.htmlunit.corejs.javascript.Function getOnmessage()
          Returns the event handler that fires on message.
 net.sourceforge.htmlunit.corejs.javascript.Function getOnopen()
          Returns the event handler that fires on open.
 int getReadyState()
          Returns The current state of the connection.
static net.sourceforge.htmlunit.corejs.javascript.Scriptable jsConstructor(net.sourceforge.htmlunit.corejs.javascript.Context cx, Object[] args, net.sourceforge.htmlunit.corejs.javascript.Function ctorObj, boolean inNewExpr)
          JavaScript constructor.
 void send(Object content)
          Transmits data to the server over the WebSocket connection.
 void setOnclose(net.sourceforge.htmlunit.corejs.javascript.Function closeHandler)
          Sets the event handler that fires on close.
 void setOnerror(net.sourceforge.htmlunit.corejs.javascript.Function errorHandler)
          Sets the event handler that fires on error.
 void setOnmessage(net.sourceforge.htmlunit.corejs.javascript.Function messageHandler)
          Sets the event handler that fires on message.
 void setOnopen(net.sourceforge.htmlunit.corejs.javascript.Function openHandler)
          Sets the event handler that fires on open.
 
Methods inherited from class com.gargoylesoftware.htmlunit.javascript.SimpleScriptable
clone, defineFunctionProperties, defineProperty, equivalentValues, get, getBrowserVersion, getClassName, getDefaultValue, getDomNodeOrDie, getDomNodeOrNull, getPrototype, getScriptableFor, getStartingScope, getTransformerScriptableFor, getWindow, getWindow, getWithPreemption, hasInstance, initParentScope, isReadOnlySettable, makeScriptableFor, setCaseSensitive, setDomNode, setDomNode, setHtmlElement
 
Methods inherited from class net.sourceforge.htmlunit.corejs.javascript.ScriptableObject
applyDescriptorToAttributeBitset, associateValue, avoidObjectDetection, buildDataDescriptor, callMethod, callMethod, checkPropertyChange, checkPropertyDefinition, defineClass, defineClass, defineClass, defineConst, defineConstProperty, defineOwnProperties, defineOwnProperty, defineOwnProperty, defineProperty, defineProperty, defineProperty, delete, delete, deleteProperty, deleteProperty, ensureScriptable, ensureScriptableObject, get, get, getAllIds, getArrayPrototype, getAssociatedValue, getAttributes, getAttributes, getAttributes, getAttributes, getClassPrototype, getDefaultValue, getFunctionPrototype, getGetterOrSetter, getIds, getObjectPrototype, getOwnPropertyDescriptor, getParentScope, getProperty, getProperty, getPropertyIds, getPrototype, getSlot, getTopLevelScope, getTopScopeValue, getTypedProperty, getTypedProperty, getTypeOf, has, has, hasProperty, hasProperty, isAccessorDescriptor, isConst, isDataDescriptor, isEmpty, isExtensible, isFalse, isGenericDescriptor, isGetterOrSetter, isSealed, isTrue, preventExtensions, put, put, putConst, putConstProperty, putProperty, putProperty, redefineProperty, sameValue, sealObject, setAttributes, setAttributes, setAttributes, setAttributes, setGetterOrSetter, setParentScope, setPrototype, size
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CONNECTING

public static final int CONNECTING
The connection has not yet been established.

See Also:
Constant Field Values

OPEN

public static final int OPEN
The WebSocket connection is established and communication is possible.

See Also:
Constant Field Values

CLOSING

public static final int CLOSING
The connection is going through the closing handshake.

See Also:
Constant Field Values

CLOSED

public static final int CLOSED
The connection has been closed or could not be opened.

See Also:
Constant Field Values
Constructor Detail

WebSocket

public WebSocket()
Creates a new instance. JavaScript objects must have a default constructor.

Method Detail

jsConstructor

public static net.sourceforge.htmlunit.corejs.javascript.Scriptable jsConstructor(net.sourceforge.htmlunit.corejs.javascript.Context cx,
                                                                                  Object[] args,
                                                                                  net.sourceforge.htmlunit.corejs.javascript.Function ctorObj,
                                                                                  boolean inNewExpr)
JavaScript constructor.

Parameters:
cx - the current context
args - the arguments to the WebSocket constructor
ctorObj - the function object
inNewExpr - Is new or not
Returns:
the java object to allow JavaScript to access

getOnclose

public net.sourceforge.htmlunit.corejs.javascript.Function getOnclose()
Returns the event handler that fires on close.

Returns:
the event handler that fires on close

setOnclose

public void setOnclose(net.sourceforge.htmlunit.corejs.javascript.Function closeHandler)
Sets the event handler that fires on close.

Parameters:
closeHandler - the event handler that fires on close

getOnerror

public net.sourceforge.htmlunit.corejs.javascript.Function getOnerror()
Returns the event handler that fires on error.

Returns:
the event handler that fires on error

setOnerror

public void setOnerror(net.sourceforge.htmlunit.corejs.javascript.Function errorHandler)
Sets the event handler that fires on error.

Parameters:
errorHandler - the event handler that fires on error

getOnmessage

public net.sourceforge.htmlunit.corejs.javascript.Function getOnmessage()
Returns the event handler that fires on message.

Returns:
the event handler that fires on message

setOnmessage

public void setOnmessage(net.sourceforge.htmlunit.corejs.javascript.Function messageHandler)
Sets the event handler that fires on message.

Parameters:
messageHandler - the event handler that fires on message

getOnopen

public net.sourceforge.htmlunit.corejs.javascript.Function getOnopen()
Returns the event handler that fires on open.

Returns:
the event handler that fires on open

setOnopen

public void setOnopen(net.sourceforge.htmlunit.corejs.javascript.Function openHandler)
Sets the event handler that fires on open.

Parameters:
openHandler - the event handler that fires on open

getReadyState

public int getReadyState()
Returns The current state of the connection. The possible values are:

Returns:
the current state of the connection

close

public void close(Object code,
                  Object reason)
Closes the WebSocket connection or connection attempt, if any. If the connection is already CLOSED, this method does nothing.

Parameters:
code - A numeric value indicating the status code explaining why the connection is being closed
reason - A human-readable string explaining why the connection is closing

send

public void send(Object content)
Transmits data to the server over the WebSocket connection.

Parameters:
content - the body of the message being sent with the request


Copyright © 2002-2012 Gargoyle Software Inc.. All Rights Reserved.