@mygo-plugins/websocket
v0.2.6
Published
A WebSocket whose connections Go makes, for MyGo desktop apps
Maintainers
Readme
@mygo-plugins/websocket
A WebSocket for MyGo apps whose
connections Go makes, with the API of the browser's. Unlike the browser's,
it may send any header with the opening handshake, such as Authorization,
Cookie or Origin, and is not subject to the page's Content Security Policy.
Use the plugin in Go:
import "github.com/egoist/mygo/plugins/websocket"
mygo.Use(websocket.Plugin) // or websocket.New(websocket.Options{...})and connect in the frontend:
import { WebSocket } from "@mygo-plugins/websocket";
const ws = new WebSocket("wss://example.com/live", ["v1"], {
headers: { authorization: `Bearer ${token}` },
});
ws.onopen = () => ws.send("hello");
ws.onmessage = (e) => console.log(e.data);
ws.onclose = (e) => console.log(e.code, e.reason, e.wasClean);Messages are sent in order, bufferedAmount counts the bytes Go has not
written yet, and received messages wait in Go while the page is behind, so a
fast server cannot fill the page's memory. Connections close (1001, going
away) when their page navigates away or its window closes. No extensions
(such as permessage-deflate) are negotiated.
The documentation covers closing, failures and the options of the Go side.
