package wsjs
import "github.com/coder/websocket/internal/wsjs"
Package wsjs implements typed access to the browser javascript WebSocket API.
https://developer.mozilla.org/en-US/docs/Web/API/WebSocket
Index ¶
- type CloseEvent
- type MessageEvent
- type WebSocket
- func New(url string, protocols []string) (c WebSocket, err error)
- func (c WebSocket) Close(code int, reason string) (err error)
- func (c WebSocket) OnClose(fn func(CloseEvent)) (remove func())
- func (c WebSocket) OnError(fn func(e js.Value)) (remove func())
- func (c WebSocket) OnMessage(fn func(m MessageEvent)) (remove func())
- func (c WebSocket) OnOpen(fn func(e js.Value)) (remove func())
- func (c WebSocket) SendBytes(v []byte) (err error)
- func (c WebSocket) SendText(v string) (err error)
- func (c WebSocket) Subprotocol() string
Types ¶
type CloseEvent ¶
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 ¶
New is a wrapper around the javascript WebSocket constructor.
func (WebSocket) Close ¶
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 ¶
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 ¶
OnOpen registers a function to be called when the WebSocket is opened.
func (WebSocket) SendBytes ¶
SendBytes sends the given message as a binary message on the WebSocket.
func (WebSocket) SendText ¶
SendText sends the given string as a text message on the WebSocket.
func (WebSocket) Subprotocol ¶
Subprotocol returns the WebSocket subprotocol in use.
Source Files ¶
- Version
- v1.8.13 (latest)
- Published
- Mar 14, 2025
- Platform
- js/wasm
- Imports
- 1 packages
- Last checked
- 1 month ago –
Tools for package owners.