class sap.ui.core.ws.WebSocket

Control sample: sap.ui.core.ws.WebSocket
Visiblity: public
UX Guidelines:
Implements:
Available since: N/A
Module: sap/ui/core/ws/WebSocket
Application Component: CA-UI5-COR

Basic WebSocket class.


Constructor

Creates a new WebSocket connection.

new sap.ui.core.ws.WebSocket(sUrl, aProtocols?)
Param Type Default Value Description
sUrl string

relative or absolute URL for WebSocket connection.

aProtocols? array

array of protocols as strings, a single protocol as a string


Events Overview

Event Description
close

The close event is fired, when the connection was closed.

error

The error event is fired, when an error occurred.

message

The message event is fired, when a message was received.

open

The open event is fired, when the connection was successfully opened.

close

The close event is fired, when the connection was closed.

Param Type Description
oControlEvent sap.ui.base.Event
getSource sap.ui.base.EventProvider
getParameters object
code string

Close code provided by the server.

reason string

Reason from server for closing the connection.

wasClean string

Indicates whether the connection was cleanly closed or not.

error

The error event is fired, when an error occurred.

Param Type Description
oControlEvent sap.ui.base.Event
getSource sap.ui.base.EventProvider
getParameters object

message

The message event is fired, when a message was received.

Param Type Description
oControlEvent sap.ui.base.Event
getSource sap.ui.base.EventProvider
getParameters object
data string

Received data from the server.

open

The open event is fired, when the connection was successfully opened.

Param Type Description
oControlEvent sap.ui.base.Event
getSource sap.ui.base.EventProvider
getParameters object

Methods Overview

Method Description
attachClose

Attaches event handler fnFunction to the close event of this sap.ui.core.ws.WebSocket.

When called, the context of the event handler (its this) will be bound to oListener if specified, otherwise it will be bound to this sap.ui.core.ws.WebSocket itself.

attachError

Attaches event handler fnFunction to the error event of this sap.ui.core.ws.WebSocket.

When called, the context of the event handler (its this) will be bound to oListener if specified, otherwise it will be bound to this sap.ui.core.ws.WebSocket itself.

attachMessage

Attaches event handler fnFunction to the message event of this sap.ui.core.ws.WebSocket.

When called, the context of the event handler (its this) will be bound to oListener if specified, otherwise it will be bound to this sap.ui.core.ws.WebSocket itself.

attachOpen

Attaches event handler fnFunction to the open event of this sap.ui.core.ws.WebSocket.

When called, the context of the event handler (its this) will be bound to oListener if specified, otherwise it will be bound to this sap.ui.core.ws.WebSocket itself.

close

Closes the connection.

detachClose

Detaches event handler fnFunction from the close event of this sap.ui.core.ws.WebSocket.

The passed function and listener object must match the ones used for event registration.

detachError

Detaches event handler fnFunction from the error event of this sap.ui.core.ws.WebSocket.

The passed function and listener object must match the ones used for event registration.

detachMessage

Detaches event handler fnFunction from the message event of this sap.ui.core.ws.WebSocket.

The passed function and listener object must match the ones used for event registration.

detachOpen

Detaches event handler fnFunction from the open event of this sap.ui.core.ws.WebSocket.

The passed function and listener object must match the ones used for event registration.

sap.ui.core.ws.WebSocket.extend

Creates a new subclass of class sap.ui.core.ws.WebSocket with name sClassName and enriches it with the information contained in oClassInfo.

oClassInfo might contain the same kind of information as described in sap.ui.base.EventProvider.extend.

fireClose

Fires event close to attached listeners.

fireError

Fires event error to attached listeners.

fireMessage

Fires event message to attached listeners.

fireOpen

Fires event open to attached listeners.

getInterface

WebSockets don't have a facade and therefore return themselves as their interface.

References:

  • sap.ui.base.Object#getInterface

sap.ui.core.ws.WebSocket.getMetadata

Returns a metadata object for class sap.ui.core.ws.WebSocket.

getProtocol

Getter for the protocol selected by the server once the connection is open.

getReadyState

Getter for WebSocket readyState.

send

Sends a message.

If the connection is not yet opened, the message will be queued and sent when the connection is established.

attachClose

Attaches event handler fnFunction to the close event of this sap.ui.core.ws.WebSocket.

When called, the context of the event handler (its this) will be bound to oListener if specified, otherwise it will be bound to this sap.ui.core.ws.WebSocket itself.

Param Type DefaultValue Description
oData object

An application-specific payload object that will be passed to the event handler along with the event object when firing the event

fnFunction function

The function to be called, when the event occurs

oListener object

Context object to call the event handler with. Defaults to this WebSocket itself

attachError

Attaches event handler fnFunction to the error event of this sap.ui.core.ws.WebSocket.

When called, the context of the event handler (its this) will be bound to oListener if specified, otherwise it will be bound to this sap.ui.core.ws.WebSocket itself.

Param Type DefaultValue Description
oData object

An application-specific payload object that will be passed to the event handler along with the event object when firing the event

fnFunction function

The function to be called, when the event occurs

oListener object

Context object to call the event handler with. Defaults to this WebSocket itself

attachMessage

Attaches event handler fnFunction to the message event of this sap.ui.core.ws.WebSocket.

When called, the context of the event handler (its this) will be bound to oListener if specified, otherwise it will be bound to this sap.ui.core.ws.WebSocket itself.

Param Type DefaultValue Description
oData object

An application-specific payload object that will be passed to the event handler along with the event object when firing the event

fnFunction function

The function to be called, when the event occurs

oListener object

Context object to call the event handler with. Defaults to this WebSocket itself

attachOpen

Attaches event handler fnFunction to the open event of this sap.ui.core.ws.WebSocket.

When called, the context of the event handler (its this) will be bound to oListener if specified, otherwise it will be bound to this sap.ui.core.ws.WebSocket itself.

Param Type DefaultValue Description
oData object

An application-specific payload object that will be passed to the event handler along with the event object when firing the event

fnFunction function

The function to be called, when the event occurs

oListener object

Context object to call the event handler with. Defaults to this WebSocket itself

close

Closes the connection.

Param Type DefaultValue Description
iCode int 1000

Status code that explains why the connection is closed. Must either be 1000, or between 3000 and 4999

sReason string

Closing reason as a string

detachClose

Detaches event handler fnFunction from the close event of this sap.ui.core.ws.WebSocket.

The passed function and listener object must match the ones used for event registration.

Param Type DefaultValue Description
fnFunction function

The function to call, when the event occurs

oListener object

Context object on which the given function had to be called

detachError

Detaches event handler fnFunction from the error event of this sap.ui.core.ws.WebSocket.

The passed function and listener object must match the ones used for event registration.

Param Type DefaultValue Description
fnFunction function

The function to call, when the event occurs

oListener object

Context object on which the given function had to be called

detachMessage

Detaches event handler fnFunction from the message event of this sap.ui.core.ws.WebSocket.

The passed function and listener object must match the ones used for event registration.

Param Type DefaultValue Description
fnFunction function

The function to call, when the event occurs

oListener object

Context object on which the given function had to be called

detachOpen

Detaches event handler fnFunction from the open event of this sap.ui.core.ws.WebSocket.

The passed function and listener object must match the ones used for event registration.

Param Type DefaultValue Description
fnFunction function

The function to call, when the event occurs

oListener object

Context object on which the given function had to be called

sap.ui.core.ws.WebSocket.extend

Creates a new subclass of class sap.ui.core.ws.WebSocket with name sClassName and enriches it with the information contained in oClassInfo.

oClassInfo might contain the same kind of information as described in sap.ui.base.EventProvider.extend.

Param Type DefaultValue Description
sClassName string

Name of the class being created

oClassInfo object

Object literal with information about the class

FNMetaImpl function

Constructor function for the metadata object; if not given, it defaults to the metadata implementation used by this class

fireClose

Fires event close to attached listeners.

Param Type DefaultValue Description
oParameters object

Parameters to pass along with the event

code string

Close code provided by the server

reason string

Reason from server for closing the connection

wasClean string

Indicates whether the connection was cleanly closed or not

fireError

Fires event error to attached listeners.

Param Type DefaultValue Description
oParameters object

Parameters to pass along with the event

fireMessage

Fires event message to attached listeners.

Param Type DefaultValue Description
oParameters object

Parameters to pass along with the event

data string

Received data from the server

fireOpen

Fires event open to attached listeners.

Param Type DefaultValue Description
oParameters object

Parameters to pass along with the event

getInterface

WebSockets don't have a facade and therefore return themselves as their interface.

References:

sap.ui.core.ws.WebSocket.getMetadata

Returns a metadata object for class sap.ui.core.ws.WebSocket.

getProtocol

Getter for the protocol selected by the server once the connection is open.

getReadyState

Getter for WebSocket readyState.

send

Sends a message.

If the connection is not yet opened, the message will be queued and sent when the connection is established.

Param Type DefaultValue Description
sMessage string

Message to send