websockets

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Rendered for js/wasm

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event struct {
	Data   []byte    `json:"data"`
	Origin string    `json:"origin"`
	Type   EventType `json:"type"`
	Value  *js.Value `json:"value"`
}

func ToEvent

func ToEvent(value js.Value) *Event

func (*Event) PreventDefault

func (event *Event) PreventDefault()

func (*Event) StopImmediatePropagation

func (event *Event) StopImmediatePropagation()

func (*Event) StopPropagation

func (event *Event) StopPropagation()

type EventListener

type EventListener struct {
	Id       uint                  `json:"id"`
	Callback EventListenerCallback `json:"callback"`
	Function *js.Func              `json:"function"`
}

func ToEventListener

func ToEventListener(callback EventListenerCallback) *EventListener

type EventListenerCallback

type EventListenerCallback func(*Event)

type EventType

type EventType string
const (
	EventTypeClose   EventType = "close"
	EventTypeError   EventType = "error"
	EventTypeMessage EventType = "message"
	EventTypeOpen    EventType = "open"
)

type ReadyState

type ReadyState int
const (
	ReadyStateConnecting ReadyState = 0
	ReadyStateOpen       ReadyState = 1
	ReadyStateClosing    ReadyState = 2
	ReadyStateClosed     ReadyState = 3
)

type Status

type Status int
const (
	StatusNormalClosure   Status = 1000
	StatusGoingAway       Status = 1001
	StatusProtocolError   Status = 1002
	StatusUnsupportedData Status = 1003

	StatusNoStatusReceived        Status = 1005 // Reserved; must not be sent.
	StatusAbnormalClosure         Status = 1006 // Reserved; must not be sent.
	StatusInvalidFramePayloadData Status = 1007
	StatusPolicyViolation         Status = 1008
	StatusMessageTooBig           Status = 1009
	StatusMandatoryExtension      Status = 1010 // Client only.
	StatusInternalServerError     Status = 1011

	StatusServiceRestart    Status = 1012
	StatusTryAgainLater     Status = 1013
	StatusBadGateway        Status = 1014
	StatusTLSHandshakeError Status = 1015 // Reserved; must not be sent.

)

type WebSocket

type WebSocket struct {
	URL            string     `json:"url"`
	BinaryType     string     `json:"binaryType"`
	BufferedAmount uint       `json:"bufferedAmount"`
	Extensions     []string   `json:"extensions"`
	Protocol       string     `json:"protocol"`
	ReadyState     ReadyState `json:"readyState"`
	Value          *js.Value  `json:"value"`
	// contains filtered or unexported fields
}

func NewWebSocket

func NewWebSocket(url string) *WebSocket

Returns new WebSocket instance.

func (*WebSocket) AddEventListener

func (websocket *WebSocket) AddEventListener(typ EventType, listener *EventListener) bool

Adds an EventListener to the WebSocket.

func (*WebSocket) Close

func (websocket *WebSocket) Close(status Status, reason string) error

func (*WebSocket) RemoveEventListener

func (websocket *WebSocket) RemoveEventListener(typ EventType, listener *EventListener) bool

func (*WebSocket) Send

func (websocket *WebSocket) Send(data []byte) error

Jump to

Keyboard shortcuts

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