Documentation
¶
Overview ¶
Package websocketjs provides low-level bindings for the browser's WebSocket API.
These bindings work with typical JavaScript idioms, such as adding event listeners with callbacks.
ws, err := websocketjs.New("ws://localhost/socket") // Does not block. if err != nil { // handle error } onOpen := func(ev *js.Object) { err := ws.Send([]byte("Hello!")) // Send a binary frame. // ... err := ws.Send("Hello!") // Send a text frame. // ... } ws.AddEventListener("open", false, onOpen) ws.AddEventListener("message", false, onMessage) ws.AddEventListener("close", false, onClose) ws.AddEventListener("error", false, onError) err = ws.Close() // ...
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ReadyState ¶
type ReadyState uint16
ReadyState represents the state that a WebSocket is in. For more information about the available states, see http://dev.w3.org/html5/websockets/#dom-websocket-readystate
const ( // Connecting means that the connection has not yet been established. Connecting ReadyState = 0 // Open means that the WebSocket connection is established and communication // is possible. Open ReadyState = 1 // Closing means that the connection is going through the closing handshake, // or the Close() method has been invoked. Closing ReadyState = 2 // Closed means that the connection has been closed or could not be opened. Closed ReadyState = 3 )
func (ReadyState) String ¶
func (rs ReadyState) String() string
type WebSocket ¶
type WebSocket struct { *js.Object URL string `js:"url"` // ready state ReadyState ReadyState `js:"readyState"` BufferedAmount uint32 `js:"bufferedAmount"` // networking Extensions string `js:"extensions"` Protocol string `js:"protocol"` // messaging BinaryType string `js:"binaryType"` }
WebSocket is a low-level convenience wrapper around the browser's WebSocket object. For more information, see http://dev.w3.org/html5/websockets/#the-websocket-interface
func (*WebSocket) AddEventListener ¶
AddEventListener provides the ability to bind callback functions to the following available events: open, error, close, message
func (*WebSocket) Close ¶
Close closes the underlying WebSocket.
See: http://dev.w3.org/html5/websockets/#dom-websocket-close
func (*WebSocket) RemoveEventListener ¶
RemoveEventListener removes a previously bound callback function
Notes ¶
Bugs ¶
When WebSocket.Send is called on a closed WebSocket, the thrown error doesn't seem to be caught by recover.