websocket

package
v1.0.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CloseEvent

type CloseEvent struct {
	*js.Event
}

CloseEvent represents javascript close event. https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent.

func CloseEventOf

func CloseEventOf(x js.Value) *CloseEvent

CloseEventOf returns a close event.

func (*CloseEvent) Code

func (e *CloseEvent) Code() uint16

Code returns close code from server.

func (*CloseEvent) Reason

func (e *CloseEvent) Reason() string

Reason returns eht reason the server closed the connection.

func (*CloseEvent) WasClean

func (e *CloseEvent) WasClean() bool

WasClean returns a boolean that indicates whether or not the connection was cleanly closed.

type State

type State uint16

State represents websocket ready state.

const (
	Connecting State = 0
	Open       State = 1
	Closing    State = 2
	Closed     State = 3
)

websocket ready state valeus.

func (State) String

func (s State) String() string

type WebSocket

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

WebSocket represents javascript web socket component.

func Connect

func Connect(url string) *WebSocket

Connect connects to server.

func (*WebSocket) Close

func (ws *WebSocket) Close()

Close closes the connection.

func (*WebSocket) Closed

func (ws *WebSocket) Closed() bool

Closed returns boolean that indicates whether or not the connection was closed.

func (*WebSocket) OnClose

func (ws *WebSocket) OnClose(cb func(*CloseEvent)) *WebSocket

OnClose add callback function when closed.

func (*WebSocket) OnError

func (ws *WebSocket) OnError(cb func(*js.Event)) *WebSocket

OnError add callback function when error happening.

func (*WebSocket) OnMessage

func (ws *WebSocket) OnMessage(cb func([]byte)) *WebSocket

OnMessage add callback function when receiving message.

func (*WebSocket) OnOpen

func (ws *WebSocket) OnOpen(cb func(*js.Event)) *WebSocket

OnOpen add callback function when opening.

func (*WebSocket) ReadyState

func (ws *WebSocket) ReadyState() State

ReadyState returns current ready state.

func (*WebSocket) Release

func (ws *WebSocket) Release()

Release closes connection and frees up resources.

func (*WebSocket) SendBinary

func (ws *WebSocket) SendBinary(data interface{}) *WebSocket

SendBinary sends binary data to server. Parameter data must be []int8, []int16, []int32, []uint8, []uint16, []uint32, []float32 and []float64.

func (*WebSocket) SendText

func (ws *WebSocket) SendText(data string) *WebSocket

SendText sends text message to server.

func (*WebSocket) URL

func (ws *WebSocket) URL() string

URL returns current connecting url.

Jump to

Keyboard shortcuts

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