Options
All
  • Public
  • Public/Protected
  • All
Menu

Class WebSocketController<RequestType, ResponseType, UnderlyingDataType>

Class, that wraps the socket and takes control over authorization, subscription and reconnection.

Type Parameters

  • RequestType

  • ResponseType

  • UnderlyingDataType extends string | ArrayBufferLike | Blob | ArrayBufferView

Hierarchy

  • WebSocketController

Index

Constructors

  • new WebSocketController<RequestType, ResponseType, UnderlyingDataType>(_config: WebSocketControllerConfig<RequestType, ResponseType, UnderlyingDataType>): WebSocketController<RequestType, ResponseType, UnderlyingDataType>

Accessors

  • get authorized$(): Observable<undefined | ResponseType>
  • get closed$(): Observable<CloseEvent>
  • get closedForever$(): Observable<void>
  • Fires when the authorization, subscription or something else gone wrong. Does not replace notAuthorized$, notSubscribed$, error$ observables, they will emit anyway.

    You can use it to navigate user back to login page.

    Returns Observable<void>

  • get closing$(): Observable<void>
  • get error$(): Observable<any>
  • Fires with socket, serialization and any other errors.

    Generally there is no way to handle the errors, other than reopen socket, which is made internally. If you wish, you can log these errors or report them to the server via http.

    Returns Observable<any>

  • get messages$(): Observable<ResponseType>
  • get opened$(): Observable<Event>
  • get pending$(): Observable<void>
  • get subscribed$(): Observable<undefined | ResponseType[]>

Methods

  • close(): Observable<void>
  • Sends the message and waits for the corresponding response message. The response is found by id, so setRequestId(msg) === getResponseId(response). Those functions are configured in WebSocketControllerConfig.

    By default, if the socket is not opened or authorized, the message is saved to the buffer, and being sent later, when the socket comes to an appropriate state. You also can control parameters of the buffer through WebSocketControllerConfig.buffer Note, that there are different buffers for messages, that require the socket to be authorized, and for those, that do not.

    Unlike Angular HttpClient, the request is being sent immediately after the function was called, not after subscription to the inner observable.

    Parameters

    Returns Observable<ResponseType>

  • Sends the message into the underlying socket.

    By default, if the socket is not opened or authorized, the message is saved to the buffer, and being sent later, when the socket comes to an appropriate state. You also can control parameters of the buffer through WebSocketControllerConfig.buffer Note, that there are different buffers for messages, that require the socket to be authorized, or to be subscribed, and for those, that do not.

    Parameters

    Returns void

Generated using TypeDoc