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

Websocket

Extends:

@osjs/event-emitter~EventEmitter → Websocket

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(uri: String, options: Object)

Create a new Websocket

Member Summary

Public Members
public

connection: WebSocket

The Websocket

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(uri: String, options: Object) source

Create a new Websocket

Params:

NameTypeAttributeDescription
uri String

Connection URI

options Object

Websocket options

Public Members

public connection: WebSocket source

The Websocket

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() source

Destroys the current connection