Class WebSocket
java.lang.Object
org.htmlunit.corejs.javascript.ScriptableObject
org.htmlunit.javascript.HtmlUnitScriptable
org.htmlunit.javascript.host.event.EventTarget
org.htmlunit.javascript.host.WebSocket
- All Implemented Interfaces:
Serializable, AutoCloseable, Cloneable, org.htmlunit.corejs.javascript.ConstProperties, org.htmlunit.corejs.javascript.debug.DebuggableObject, org.htmlunit.corejs.javascript.Scriptable, org.htmlunit.corejs.javascript.SymbolScriptable
A JavaScript object for
WebSocket.- Author:
- Ahmed Ashour, Ronald Brill, Madis Pärn
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class org.htmlunit.corejs.javascript.ScriptableObject
org.htmlunit.corejs.javascript.ScriptableObject.KeyComparator -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe connection has been closed or could not be opened.static final intThe connection is going through the closing handshake.static final intThe connection has not yet been established.static final intThe WebSocket connection is established and communication is possible.Fields inherited from class org.htmlunit.corejs.javascript.ScriptableObject
CONST, DONTENUM, EMPTY, PERMANENT, READONLY, UNINITIALIZED_CONSTFields inherited from interface org.htmlunit.corejs.javascript.Scriptable
NOT_FOUND -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()voidCloses the WebSocket connection or connection attempt, if any.longorg.htmlunit.corejs.javascript.FunctionReturns the event handler that fires on close.org.htmlunit.corejs.javascript.FunctionReturns the event handler that fires on error.org.htmlunit.corejs.javascript.FunctionReturns the event handler that fires on message.org.htmlunit.corejs.javascript.FunctionReturns the event handler that fires on open.intReturns The current state of the connection.getUrl()static org.htmlunit.corejs.javascript.ScriptablejsConstructor(org.htmlunit.corejs.javascript.Context cx, org.htmlunit.corejs.javascript.Scriptable scope, Object[] args, org.htmlunit.corejs.javascript.Function ctorObj, boolean inNewExpr) JavaScript constructor.voidTransmits data to the server over the WebSocket connection.voidsetBinaryType(String type) Sets the used binary type.voidsetOnclose(org.htmlunit.corejs.javascript.Function closeHandler) Sets the event handler that fires on close.voidsetOnerror(org.htmlunit.corejs.javascript.Function errorHandler) Sets the event handler that fires on error.voidsetOnmessage(org.htmlunit.corejs.javascript.Function messageHandler) Sets the event handler that fires on message.voidsetOnopen(org.htmlunit.corejs.javascript.Function openHandler) Sets the event handler that fires on open.Methods inherited from class EventTarget
addEventListener, clearEventListenersContainer, dispatchEvent, executeEventLocally, fireEvent, getEventHandler, getEventListenersContainer, hasEventHandlers, isEventHandlerOnWindow, jsConstructor, removeEventListener, setEventHandlerMethods inherited from class HtmlUnitScriptable
clone, equivalentValues, get, getBrowserVersion, getClassName, getDefaultValue, getDomNodeOrDie, getDomNodeOrNull, getPrototype, getScriptableFor, getStartingScope, getWindow, getWindow, getWithPreemption, has, hasInstance, initParentScope, makeScriptableFor, put, setClassName, setDomNode, setDomNode, setParentScope, setupPromise, setupRejectedPromiseMethods inherited from class org.htmlunit.corejs.javascript.ScriptableObject
applyDescriptorToAttributeBitset, associateValue, avoidObjectDetection, buildDataDescriptor, callMethod, callMethod, checkPropertyChange, checkPropertyDefinition, defineClass, defineClass, defineClass, defineConst, defineConstProperty, defineFunctionProperties, defineOwnProperties, defineOwnProperty, defineOwnProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, delete, delete, delete, deleteProperty, deleteProperty, deleteProperty, ensureScriptable, ensureScriptableObject, ensureSymbolScriptable, get, get, get, getAllIds, getArrayPrototype, getAssociatedValue, getAttributes, getAttributes, getAttributes, getAttributes, getAttributes, getClassPrototype, getDefaultValue, getExternalArrayData, getExternalArrayLength, getFunctionPrototype, getGeneratorFunctionPrototype, getGetterOrSetter, getGetterOrSetter, getIds, getObjectPrototype, getOwnPropertyDescriptor, getParentScope, getProperty, getProperty, getProperty, getPropertyIds, getPrototype, getTopLevelScope, getTopScopeValue, getTypedProperty, getTypedProperty, getTypeOf, has, has, hasProperty, hasProperty, hasProperty, isAccessorDescriptor, isConst, isDataDescriptor, isEmpty, isExtensible, isFalse, isGenericDescriptor, isGetterOrSetter, isSealed, isTrue, preventExtensions, put, put, putConst, putConstProperty, putProperty, putProperty, putProperty, querySlot, redefineProperty, sameValue, sealObject, setAttributes, setAttributes, setAttributes, setAttributes, setAttributes, setCommonDescriptorProperties, setExternalArrayData, setGetterOrSetter, setPrototype, size
-
Field Details
-
CONNECTING
public static final int CONNECTINGThe connection has not yet been established.- See Also:
-
OPEN
public static final int OPENThe WebSocket connection is established and communication is possible.- See Also:
-
CLOSING
public static final int CLOSINGThe connection is going through the closing handshake.- See Also:
-
CLOSED
public static final int CLOSEDThe connection has been closed or could not be opened.- See Also:
-
-
Constructor Details
-
WebSocket
public WebSocket()Creates a new instance.
-
-
Method Details
-
jsConstructor
public static org.htmlunit.corejs.javascript.Scriptable jsConstructor(org.htmlunit.corejs.javascript.Context cx, org.htmlunit.corejs.javascript.Scriptable scope, Object[] args, org.htmlunit.corejs.javascript.Function ctorObj, boolean inNewExpr) JavaScript constructor.- Parameters:
cx- the current contextscope- the scopeargs- the arguments to the WebSocket constructorctorObj- the function objectinNewExpr- Is new or not- Returns:
- the java object to allow JavaScript to access
-
getOnclose
public org.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(org.htmlunit.corejs.javascript.Function closeHandler) Sets the event handler that fires on close.- Parameters:
closeHandler- the event handler that fires on close
-
getOnerror
public org.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(org.htmlunit.corejs.javascript.Function errorHandler) Sets the event handler that fires on error.- Parameters:
errorHandler- the event handler that fires on error
-
getOnmessage
public org.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(org.htmlunit.corejs.javascript.Function messageHandler) Sets the event handler that fires on message.- Parameters:
messageHandler- the event handler that fires on message
-
getOnopen
public org.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(org.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:CONNECTING,OPEN,CLOSINGorCLOSED.- Returns:
- the current state of the connection
-
getUrl
- Returns:
- the url
-
getProtocol
- Returns:
- the sub protocol used
-
getBufferedAmount
public long getBufferedAmount()- Returns:
- the sub protocol used
-
getBinaryType
- Returns:
- the used binary type
-
setBinaryType
-
close
- Specified by:
closein interfaceAutoCloseable- Throws:
IOException
-
close
Closes the WebSocket connection or connection attempt, if any. If the connection is alreadyCLOSED, this method does nothing.- Parameters:
code- A numeric value indicating the status code explaining why the connection is being closedreason- A human-readable string explaining why the connection is closing
-
send
Transmits data to the server over the WebSocket connection.- Parameters:
content- the body of the message being sent with the request
-