ws

package
v0.43.0 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2023 License: AGPL-3.0 Imports: 19 Imported by: 2

Documentation

Overview

Package ws implements a k6/ws for k6. It provides basic functionality to communicate over websockets that *blocks* the event loop while the connection is opened.

Index

Constants

This section is empty.

Variables

View Source
var ErrWSInInitContext = common.NewInitContextError("using websockets in the init context is not supported")

ErrWSInInitContext is returned when websockets are using in the init context

Functions

This section is empty.

Types

type HTTPResponse added in v0.41.0

type HTTPResponse struct {
	URL     string            `json:"url"`
	Status  int               `json:"status"`
	Headers map[string]string `json:"headers"`
	Body    string            `json:"body"`
	Error   string            `json:"error"`
}

HTTPResponse is the http response returned by ws.connect.

type RootModule added in v0.36.0

type RootModule struct{}

RootModule is the global module instance that will create module instances for each VU.

func New added in v0.18.0

func New() *RootModule

New returns a pointer to a new RootModule instance.

func (*RootModule) NewModuleInstance added in v0.36.0

func (*RootModule) NewModuleInstance(m modules.VU) modules.Instance

NewModuleInstance implements the modules.Module interface to return a new instance for each VU.

type Socket

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

Socket is the representation of the websocket returned to the js.

func (*Socket) Close

func (s *Socket) Close(args ...goja.Value)

Close closes the webscocket. If providede the first argument will be used as the code for the close message.

func (*Socket) On

func (s *Socket) On(event string, handler goja.Value)

On is used to configure what the websocket should do on each event.

func (*Socket) Ping

func (s *Socket) Ping()

Ping sends a ping message over the websocket.

func (*Socket) Send

func (s *Socket) Send(message string)

Send writes the given string message to the connection.

func (*Socket) SendBinary added in v0.32.0

func (s *Socket) SendBinary(message goja.Value)

SendBinary writes the given ArrayBuffer message to the connection.

func (*Socket) SetInterval

func (s *Socket) SetInterval(fn goja.Callable, intervalMs float64) error

SetInterval executes the provided function inside the socket's event loop each interval time, which is in ms

func (*Socket) SetTimeout

func (s *Socket) SetTimeout(fn goja.Callable, timeoutMs float64) error

SetTimeout executes the provided function inside the socket's event loop after at least the provided timeout, which is in ms, has elapsed

type WS

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

WS represents a module instance of the WebSocket module.

func (*WS) Connect

func (mi *WS) Connect(url string, args ...goja.Value) (*HTTPResponse, error)

Connect establishes a WebSocket connection based on the parameters provided.

func (*WS) Exports added in v0.36.0

func (mi *WS) Exports() modules.Exports

Exports returns the exports of the ws module.

Jump to

Keyboard shortcuts

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