Home Reference Source
import Websocket from '@osjs/client/src/websocket.js'
public class | source

Websocket

Extends:

@osjs/event-emitter~EventEmitter → Websocket

Application Socket

This is just an abstraction above the standard browser provided WebSocket class. Since this class implements the EventHandler, use the .on('event') pattern instead of .onevent.

Constructor Summary

Public Constructor
public

constructor(name: string, uri: string, options: WebsocketOptions)

Create a new Websocket

Member Summary

Public Members
public

If socket is closed

public

If socket is connected

public

If socket failed to connect

public

If socket is connecting

public

connection: WebSocket

The Websocket

public

Options

public

If socket is reconnecting

public

Socket URI

Method Summary

Public Methods
public

close(args: ...*): *

Wrapper for closing

public

open(reconnect: boolean)

Opens the connection

public

send(args: ...*): *

Wrapper for sending data

Private Methods
private

Attaches internal events

private

Destroys the current connection

Public Constructors

public constructor(name: string, uri: string, options: WebsocketOptions) source

Create a new Websocket

Params:

NameTypeAttributeDescription
name string

Instance name

uri string

Connection URI

options WebsocketOptions
  • optional
  • default: {}

Websocket options

Public Members

public closed: boolean source

If socket is closed

public connected: boolean source

If socket is connected

public connectfailed: boolean source

If socket failed to connect

public connecting: boolean source

If socket is connecting

public connection: WebSocket source

The Websocket

public options: WebsocketOptions source

Options

public reconnecting: boolean source

If socket is reconnecting

public uri: string source

Socket URI

Public Methods

public close(args: ...*): * source

Wrapper for closing

Params:

NameTypeAttributeDescription
args ...*

Return:

*

public open(reconnect: boolean) source

Opens the connection

Params:

NameTypeAttributeDescription
reconnect boolean
  • optional
  • default: false

Force reconnection

public send(args: ...*): * source

Wrapper for sending data

Params:

NameTypeAttributeDescription
args ...*

Return:

*

Private Methods

private _attachEvents() source

Attaches internal events

private _destroyConnection(): void source

Destroys the current connection

Return:

void