nhooyr

package
v0.0.0-...-f682b98 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 5, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package which contains a WebsocketConnectionAdapterInterface implementation for nhooyr/websocket library (https://github.com/nhooyr/websocket).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type NhooyrWebsocketConnectionAdapter

type NhooyrWebsocketConnectionAdapter struct {
	// contains filtered or unexported fields
}

Adapter for nhooyr/websocket library

func NewNhooyrWebsocketConnectionAdapter

func NewNhooyrWebsocketConnectionAdapter(opts *websocket.DialOptions) *NhooyrWebsocketConnectionAdapter

Description

Factory which creates a new NhooyrWebsocketConnectionAdapter.

Inputs

  • opts: Optional dial options to use when calling Dial method. Can be nil.

Returns

New NhooyrWebsocketConnectionAdapter

func (*NhooyrWebsocketConnectionAdapter) Close

Description

Send a close message with the provided status code and an optional close reason and drop the websocket connection.

Inputs

  • ctx: Context used for tracing purpose
  • code: Status code to use in close message
  • reason: Optional reason joined in clsoe message. Can be empty.

Returns

  • nil in case of success
  • error: server unreachable, connection already closed, ...

func (*NhooyrWebsocketConnectionAdapter) Dial

func (adapter *NhooyrWebsocketConnectionAdapter) Dial(ctx context.Context, target url.URL) (*http.Response, error)

Description

Dial opens a connection to the websocket server and performs a WebSocket handshake.

Inputs

  • ctx: Context used for tracing/timeout purpose
  • target: Target server URL

Returns

The server response to websocket handshake or an error if any.

func (*NhooyrWebsocketConnectionAdapter) GetUnderlyingWebsocketConnection

func (adapter *NhooyrWebsocketConnectionAdapter) GetUnderlyingWebsocketConnection() any

Description

Return the underlying websocket connection if any. Returned value has to be type asserted.

Returns

The underlying websocket connection if any. Returned value has to be type asserted.

func (*NhooyrWebsocketConnectionAdapter) Ping

Description

Send a Ping message to the websocket server and blocks until a Pong response is received, a timeout occurs or until connection is closed.

A concrrent gorotine must call Read method so that contorl frames, pong inclded, are processed and ping does not hang.

Inputs

  • ctx: context used for tracing/timeout purpose.

Returns

- nil in case of success: if a Ping message is sent to the server and if a Pong is received. - error: connection is closed, context timeout/cancellation, ...

func (*NhooyrWebsocketConnectionAdapter) Read

Description

Read a single message from the websocket server. Read blocks until a message is received from the server or until connection closes

Inputs

  • ctx: Context used for tracing purpose

Returns

  • MessageType: received message type (Binary | Text)
  • []bytes: Message content
  • error: in case of connection closure, context timeout/cancellation or failure.

func (*NhooyrWebsocketConnectionAdapter) Write

func (adapter *NhooyrWebsocketConnectionAdapter) Write(ctx context.Context, msgType wsadapters.MessageType, msg []byte) error

Description

Write a single message to the websocket server. Write blocks until message is sent to the server or until an error occurs: context timeout, cancellation, connection closed, ....

Inputs

  • ctx: Context used for tracing/timeout purpose
  • MessageType: received message type (Binary | Text)
  • []bytes: Message content

Returns

  • error: in case of connection closure, context timeout/cancellation or failure.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL