Class WebSocket

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.AutoCloseable, java.lang.Cloneable, org.htmlunit.corejs.javascript.ConstProperties, org.htmlunit.corejs.javascript.debug.DebuggableObject, org.htmlunit.corejs.javascript.Scriptable, org.htmlunit.corejs.javascript.SymbolScriptable

    public class WebSocket
    extends EventTarget
    implements java.lang.AutoCloseable
    A JavaScript object for WebSocket.
    See Also:
    Mozilla documentation, Serialized Form
    • Nested Class Summary

      • Nested classes/interfaces inherited from class org.htmlunit.corejs.javascript.ScriptableObject

        org.htmlunit.corejs.javascript.ScriptableObject.KeyComparator
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.lang.String binaryType_  
      static int CLOSED
      The connection has been closed or could not be opened.
      private org.htmlunit.corejs.javascript.Function closeHandler_  
      static int CLOSING
      The connection is going through the closing handshake.
      static int CONNECTING
      The connection has not yet been established.
      private HtmlPage containingPage_  
      private org.htmlunit.corejs.javascript.Function errorHandler_  
      private static org.apache.commons.logging.Log LOG  
      private org.htmlunit.corejs.javascript.Function messageHandler_  
      static int OPEN
      The WebSocket connection is established and communication is possible.
      private org.htmlunit.corejs.javascript.Function openHandler_  
      private boolean originSet_  
      private int readyState_  
      private java.net.URI url_  
      private WebSocketAdapter webSocketImpl_  
      • Fields inherited from class org.htmlunit.corejs.javascript.ScriptableObject

        CONST, DONTENUM, EMPTY, PERMANENT, READONLY, UNINITIALIZED_CONST
      • Fields inherited from interface org.htmlunit.corejs.javascript.Scriptable

        NOT_FOUND
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
        WebSocket()
      Creates a new instance.
      private WebSocket​(java.lang.String url, Window window)
      Creates a new instance.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      (package private) void callFunction​(org.htmlunit.corejs.javascript.Function function, java.lang.Object[] args)  
      void close()
      void close​(java.lang.Object code, java.lang.Object reason)
      Closes the WebSocket connection or connection attempt, if any.
      (package private) void fire​(Event evt)  
      java.lang.String getBinaryType()  
      long getBufferedAmount()  
      org.htmlunit.corejs.javascript.Function getOnclose()
      Returns the event handler that fires on close.
      org.htmlunit.corejs.javascript.Function getOnerror()
      Returns the event handler that fires on error.
      org.htmlunit.corejs.javascript.Function getOnmessage()
      Returns the event handler that fires on message.
      org.htmlunit.corejs.javascript.Function getOnopen()
      Returns the event handler that fires on open.
      java.lang.String getProtocol()  
      int getReadyState()
      Returns The current state of the connection.
      java.lang.String getUrl()  
      static org.htmlunit.corejs.javascript.Scriptable jsConstructor​(org.htmlunit.corejs.javascript.Context cx, org.htmlunit.corejs.javascript.Scriptable scope, java.lang.Object[] args, org.htmlunit.corejs.javascript.Function ctorObj, boolean inNewExpr)
      JavaScript constructor.
      void send​(java.lang.Object content)
      Transmits data to the server over the WebSocket connection.
      void setBinaryType​(java.lang.String type)
      Sets the used binary type.
      void setOnclose​(org.htmlunit.corejs.javascript.Function closeHandler)
      Sets the event handler that fires on close.
      void setOnerror​(org.htmlunit.corejs.javascript.Function errorHandler)
      Sets the event handler that fires on error.
      void setOnmessage​(org.htmlunit.corejs.javascript.Function messageHandler)
      Sets the event handler that fires on message.
      void setOnopen​(org.htmlunit.corejs.javascript.Function openHandler)
      Sets the event handler that fires on open.
      (package private) void setReadyState​(int readyState)  
      • Methods 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
      • Methods inherited from class java.lang.Object

        equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • LOG

        private static final org.apache.commons.logging.Log LOG
      • 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
      • closeHandler_

        private org.htmlunit.corejs.javascript.Function closeHandler_
      • errorHandler_

        private org.htmlunit.corejs.javascript.Function errorHandler_
      • messageHandler_

        private org.htmlunit.corejs.javascript.Function messageHandler_
      • openHandler_

        private org.htmlunit.corejs.javascript.Function openHandler_
      • url_

        private java.net.URI url_
      • readyState_

        private int readyState_
      • binaryType_

        private java.lang.String binaryType_
      • containingPage_

        private HtmlPage containingPage_
      • originSet_

        private boolean originSet_
    • Constructor Detail

      • WebSocket

        public WebSocket()
        Creates a new instance.
      • WebSocket

        private WebSocket​(java.lang.String url,
                          Window window)
        Creates a new instance.
        Parameters:
        url - the URL to which to connect
        window - the top level window
    • Method Detail

      • jsConstructor

        public static org.htmlunit.corejs.javascript.Scriptable jsConstructor​(org.htmlunit.corejs.javascript.Context cx,
                                                                              org.htmlunit.corejs.javascript.Scriptable scope,
                                                                              java.lang.Object[] args,
                                                                              org.htmlunit.corejs.javascript.Function ctorObj,
                                                                              boolean inNewExpr)
        JavaScript constructor.
        Parameters:
        cx - the current context
        scope - the scope
        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 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, CLOSING or CLOSED.
        Returns:
        the current state of the connection
      • setReadyState

        void setReadyState​(int readyState)
      • getUrl

        public java.lang.String getUrl()
        Returns:
        the url
      • getProtocol

        public java.lang.String getProtocol()
        Returns:
        the sub protocol used
      • getBufferedAmount

        public long getBufferedAmount()
        Returns:
        the sub protocol used
      • getBinaryType

        public java.lang.String getBinaryType()
        Returns:
        the used binary type
      • setBinaryType

        public void setBinaryType​(java.lang.String type)
        Sets the used binary type.
        Parameters:
        type - the type
      • close

        public void close()
                   throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Throws:
        java.io.IOException
      • close

        public void close​(java.lang.Object code,
                          java.lang.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​(java.lang.Object content)
        Transmits data to the server over the WebSocket connection.
        Parameters:
        content - the body of the message being sent with the request
      • fire

        void fire​(Event evt)
      • callFunction

        void callFunction​(org.htmlunit.corejs.javascript.Function function,
                          java.lang.Object[] args)