wsjs

package
v0.0.0-...-0e15ea6 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2021 License: MIT Imports: 1 Imported by: 0

Documentation

Rendered for js/wasm

Overview

Package wsjs implements typed access to the browser javascript WebSocket API.

https://developer.mozilla.org/en-US/docs/Web/API/WebSocket

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CloseEvent

type CloseEvent struct {
	Code     uint16
	Reason   string
	WasClean bool
}

CloseEvent is the type passed to a WebSocket close handler.

type MessageEvent

type MessageEvent struct {
	// string or []byte.
	Data interface{}
}

MessageEvent is the type passed to a message handler.

type WebSocket

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

WebSocket is a wrapper around a javascript WebSocket object.

func New

func New(url string, protocols []string) (c WebSocket, err error)

New is a wrapper around the javascript WebSocket constructor.

func (WebSocket) Close

func (c WebSocket) Close(code int, reason string) (err error)

Close closes the WebSocket with the given code and reason.

func (WebSocket) OnClose

func (c WebSocket) OnClose(fn func(CloseEvent)) (remove func())

OnClose registers a function to be called when the WebSocket is closed.

func (WebSocket) OnError

func (c WebSocket) OnError(fn func(e js.Value)) (remove func())

OnError registers a function to be called when there is an error with the WebSocket.

func (WebSocket) OnMessage

func (c WebSocket) OnMessage(fn func(m MessageEvent)) (remove func())

OnMessage registers a function to be called when the WebSocket receives a message.

func (WebSocket) OnOpen

func (c WebSocket) OnOpen(fn func(e js.Value)) (remove func())

OnOpen registers a function to be called when the WebSocket is opened.

func (WebSocket) SendBytes

func (c WebSocket) SendBytes(v []byte) (err error)

SendBytes sends the given message as a binary message on the WebSocket.

func (WebSocket) SendText

func (c WebSocket) SendText(v string) (err error)

SendText sends the given string as a text message on the WebSocket.

func (WebSocket) Subprotocol

func (c WebSocket) Subprotocol() string

Subprotocol returns the WebSocket subprotocol in use.

Jump to

Keyboard shortcuts

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