Documentation
¶
Overview ¶
Package websocket is the WebSocket plugin of MyGo: pages open WebSocket connections from Go with the WebSocket class of its JavaScript package, @mygo-plugins/websocket, which has the API of the browser's. Unlike the browser's, it may send any header with the opening handshake, such as Authorization or Cookie, and is not subject to the page's Content Security Policy.
mygo.Use(websocket.Plugin)
and in the frontend:
import { WebSocket } from "@mygo-plugins/websocket";
const ws = new WebSocket("wss://example.com/live", [], {
headers: { authorization: `Bearer ${token}` },
});
ws.onmessage = (e) => console.log(e.data);
Connections close when their page navigates away or its window closes.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Plugin = New(Options{})
Plugin is the plugin with the default options.
Functions ¶
Types ¶
type Options ¶
type Options struct {
// Client makes the opening handshakes; nil means a client of
// netproxy.Transport(), which follows the system's proxy settings.
// Its Timeout and CheckRedirect are ignored: connections last, and
// redirects fail them, as in browsers.
Client *http.Client
// Allow, when not nil, decides whether pages may open a connection
// with the handshake request; a connection it refuses fails.
Allow func(r *http.Request) bool
// MaxMessageSize is the most bytes a received message may have, 64 MiB
// when zero. A bigger message fails the connection.
MaxMessageSize int64
// CloseTimeout is how long a connection that sends a close frame waits
// for the server to read it and, when the page closed first, to finish
// the closing handshake, 5 seconds when zero.
CloseTimeout time.Duration
}
Options configure the plugin.