java.lang.Object
org.htmlunit.corejs.javascript.SlotMapOwner<org.htmlunit.corejs.javascript.Scriptable>
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.Scriptable>,org.htmlunit.corejs.javascript.debug.DebuggableObject,org.htmlunit.corejs.javascript.PropHolder<org.htmlunit.corejs.javascript.Scriptable>,org.htmlunit.corejs.javascript.Scriptable,org.htmlunit.corejs.javascript.SymbolScriptable
JavaScript host 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.DescriptorInfo, org.htmlunit.corejs.javascript.ScriptableObject.KeyComparator, org.htmlunit.corejs.javascript.ScriptableObject.LambdaGetterFunction, org.htmlunit.corejs.javascript.ScriptableObject.LambdaSetterFunction -
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 class org.htmlunit.corejs.javascript.SlotMapOwner
isSealedFields 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.Returns the binary data type used when receiving binary messages.longReturns the number of bytes of data that have been queued but not yet transmitted.org.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.Returns the sub-protocol in use, or an empty string if no sub-protocol was selected.intReturns the current state of the connection.getUrl()Returns the URL of the WebSocket connection.static org.htmlunit.corejs.javascript.ScriptablejsConstructor(org.htmlunit.corejs.javascript.Context cx, org.htmlunit.corejs.javascript.VarScope scope, Object[] args, org.htmlunit.corejs.javascript.Function ctorObj, boolean inNewExpr) Creates an instance of this object.voidTransmits data to the server over the WebSocket connection.voidsetBinaryType(String type) Sets the binary data type used when receiving binary messages.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 org.htmlunit.javascript.host.event.EventTarget
addEventListener, clearEventListenersContainer, dispatchEvent, executeEventLocally, fireEvent, getEventHandler, getEventListenersContainer, hasEventHandlers, isEventHandlerOnWindow, jsConstructor, removeEventListener, setEventHandlerMethods inherited from class org.htmlunit.javascript.HtmlUnitScriptable
clone, equivalentValues, get, getBrowserVersion, getClassName, getDefaultValue, getDomNodeOrDie, getDomNodeOrNull, getPrototype, getScriptableFor, getWindow, getWindow, getWindowOrWorkerGlobalScope, getWithPreemption, has, hasInstance, makeScriptableFor, put, setClassName, setDomNode, setDomNode, setupPromise, setupRejectedPromiseMethods inherited from class org.htmlunit.corejs.javascript.ScriptableObject
applyDescriptorToAttributeBitset, avoidObjectDetection, buildDataDescriptor, callMethod, callMethod, checkNotSealed, checkPropertyChangeForSlot, checkPropertyChangeForSlot, checkPropertyDefinition, checkPropertyDefinition, checkSlotRemoval, defineBuiltinProperty, defineBuiltinProperty, defineBuiltInProperty, defineBuiltInProperty, defineBuiltInProperty, defineBuiltInProperty, defineClass, defineClass, defineClass, defineConst, defineConstProperty, defineFunctionProperties, defineOwnProperties, defineOwnProperty, defineOwnProperty, defineOwnProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, delete, delete, delete, deleteProperty, deleteProperty, deleteProperty, ensureScriptable, ensureScriptableObject, ensureScriptableObjectButNotSymbol, ensureSymbolScriptable, ensureType, get, get, getAllIds, getAncestor, getArrayPrototype, getClassPrototype, getClassPrototype, getDefaultValue, getExternalArrayData, getExternalArrayLength, getFunctionPrototype, getGeneratorFunctionPrototype, getGetterOrSetter, getGetterOrSetter, getObjectPrototype, getOwnPropertyDescriptor, getParentScope, getProperty, getProperty, getProperty, getProperty, getProperty, getPropertyIds, getPrototype, getSuperProperty, getSuperProperty, getSuperProperty, getThis, getTopLevelScope, getTopScopeValue, getTypedProperty, getTypedProperty, getTypeOf, hasProperty, hasProperty, hasProperty, hasProperty, isAccessorDescriptor, isAccessorDescriptor, isConst, isDataDescriptor, isEmpty, isExtensible, isFalse, isGenericDescriptor, isGenericDescriptor, isGetterOrSetter, isGetterOrSetter, isTrue, preventExtensions, put, put, putConst, putConstProperty, putConstProperty, putOwnProperty, putOwnProperty, putOwnProperty, putProperty, putProperty, putProperty, putProperty, putSuperProperty, putSuperProperty, putSuperProperty, querySlot, redefineProperty, redefineProperty, sameValue, sealObject, setCommonDescriptorProperties, setExternalArrayData, setGetterOrSetter, setParentScope, setPrototype, sizeMethods inherited from class org.htmlunit.corejs.javascript.SlotMapOwner
associateValue, checkNotSealed, copyAssociatedValue, createSlotMap, defineProperty, defineProperty, get, getAssociatedValue, getAttributes, getAttributes, getAttributes, getAttributes, getAttributes, getIds, has, has, isSealed, readMaps, setAttributes, setAttributes, setAttributes, setAttributes, setAttributes, writeMapsMethods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.htmlunit.corejs.javascript.Scriptable
get, getIds, has, hasMethods inherited from interface org.htmlunit.corejs.javascript.SymbolScriptable
get, has
-
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.VarScope scope, Object[] args, org.htmlunit.corejs.javascript.Function ctorObj, boolean inNewExpr) Creates an instance of this object.- Parameters:
cx- the current contextscope- the scopeargs- the constructor argumentsctorObj- the function objectinNewExpr- whether invoked vianew- Returns:
- the new
WebSocketinstance
-
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. Possible values areCONNECTING,OPEN,CLOSING, orCLOSED.- Returns:
- the current ready state
-
getUrl
Returns the URL of the WebSocket connection.- Returns:
- the URL string
-
getProtocol
Returns the sub-protocol in use, or an empty string if no sub-protocol was selected.- Returns:
- the sub-protocol
-
getBufferedAmount
public long getBufferedAmount()Returns the number of bytes of data that have been queued but not yet transmitted.- Returns:
- the buffered amount in bytes
-
getBinaryType
Returns the binary data type used when receiving binary messages.- Returns:
- the binary type (
"blob"or"arraybuffer")
-
setBinaryType
Sets the binary data type used when receiving binary messages.- Parameters:
type- the new binary type; must be"blob"or"arraybuffer"
-
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 data to send
-