Skip to main content

Websockets

Returns WebsocketService singleton instance as a container of the Websockets implementations it will be used to extract and create the listeners to messages and setup on your way the responses for websockets. Singleton still not created then initialize it a new Singleton instance.

Constructor
WebsocketService(
wsOptional
:Websocket.Server
wssOptional
:Websocket.Server
)

Parameters
NameOptionalTypeDefaultsDescription
wsYesWebsocket.ServerNon Secure Websocket Server Instance.
wssYesWebsocket.ServerSecure Websocket Server Instance.

Properties

privateStatic
instance
:Websocket.Server

This is the initialized Singleton instance and will be undefined if not initialized.

private
ws
:Websocket.Server

Private and readonly property that contains an instance of WebSocket.Server.

private
wss
:Websocket.Server

Private and readonly property that contains an instance of WebSocket.Server over secure protocol.

public
httpServer
:http.Server

Public property that contains an instance for http.Server;

public
httpsServer
:https.Server

Public property that contains an instance for https.Server;

Methods

publicStatic
getInstance(
wsOptional
:Websocket.Server
wssOptional
:Websocket.Server
)
WebsocketService

Returns WebsocketService singleton instance, however, if Singleton still is not already initialize this will create the Singleton instance instead return it and for that ws should passed as minimum requirement to initialize this.

Parameters
NameOptionalTypeDefaultsDescription
wsYesWebsocket.ServerNon Secure Websocket Server Instance.
wssYesWebsocket.ServerSecure Websocket Server Instance.

publicStatic
init(
wsOptional
:Websocket.Server
wssOptional
:Websocket.Server
)
void

Try to initialize WebsocketService singleton instance when is not already initialized this will create the Singleton instance and ws argument should be passed as minimum requirement to initialize this. If already initialized this will be ignored.

Parameters
NameOptionalTypeDefaultsDescription
wsYesWebsocket.ServerNon Secure Websocket Server Instance.
wssYesWebsocket.ServerSecure Websocket Server Instance.

publicStatic
clear()
void

Clear the Singleton instance and ready to be created again.

public
getWebsocket(
httpServer
:http.Server | https.Server
)
Websocket.Server

Returns the mapped Websocket Server attached returns WebSocket.Server

Parameters
NameOptionalTypeDefaultsDescription
httpServerNohttp.Server | https.ServerGet Websocket instance associated with the http or https Server.

public
setHttpServer(
httpServer
:http.Server | https.Server
)
void

This populate the properties httpServer or httpsServer depends on the type of server passed as arguments it will save it on the respective Singleton property.

Parameters
NameOptionalTypeDefaultsDescription
httpServerNohttp.Server | https.ServerGet Websocket instance associated with the http or https Server.

public
setWebsocket(
ws
:Websocket.Server
)
Websocket.Server

This populate the properties httpServer or httpsServer depends on the type of server passed as arguments it will save it on the respective Singleton property.

Parameters
NameOptionalTypeDefaultsDescription
wsNoWebsocket.ServerAssign Websocket Server Instance.

public
setSecureWebsocket(
wss
:Websocket.Server
)
Websocket.Server

This populate the properties httpServer or httpsServer depends on the type of server passed as arguments it will save it on the respective Singleton property.

Parameters
NameOptionalTypeDefaultsDescription
wssNoWebsocket.ServerAssing SECURE Websocket Server Instance.